Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I love python, and I understand the importance of typing, but is there a way to have less physical keyboard typing?

Consider the two examples:

`private Dictionary<RoadPlate, List<RoadPlate>> road = new Dictionary<RoadPlate, List<RoadPlate>>();`

`road : dict[RoadPlate, List[RoadPlate] = {}`

Or even just `road = {}`

I prefer python simply due to needing less writing and less reading. I can think more about the program when there's less stuff to read



Many years ago, I used to code in OCaml. I used to think exactly like you (OCaml has extreme levels of type-inference, so you write as little code as Python and you get type safety). However, as I worked on larger codebases, I realized that most of these type hints on which I was saving a few keystrokes were actually part of the documentation. When I returned to older code, it looked smart, too smart, but I had no clue about my invariants.

And in your particular example, if you write `road = {}`, chances are that it will end up being typed as a `Dict[str, Any]`, which is basically worthless, both to avoid TypeError, but also as a suggestion of what you should and shouldn't put in the dictionary.

These days, I write my types aggressively.


Indeed, that has been a real problem, so now you can probably write `private Dictionary<RoadPlate, List<RoadPlate>> road = new();`.


This was my main complaint, as I nlk no one the dict part needs typing, but surely `new` could infer what I want.

If so, I'm very glad.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: