News for hackers. Stuff that matters.
Re:Writing Python like it's Rust by drekipus on Sunday May 21, 2023 @06:37AM (#36019587)
* * *
Re:Writing Python like it's Rust by Yoric on Sunday May 21, 2023 @06:56AM (#36019665)
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.

Re:Writing Python like it's Rust by rami3l on Sunday May 21, 2023 @07:37AM (#36019906)
Indeed, that has been a real problem, so now you can probably write `private Dictionary<RoadPlate, List<RoadPlate>> road = new();`.
Re:Writing Python like it's Rust by drekipus on Sunday May 21, 2023 @09:14PM (#36026302)
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.