5 ms·
My problem with Python, especially when reading someone else's code, or my own old bad code, is that I find that Python doesn't fit [my] brain. The lack of typ
by elabajaba 4y ago
My problem with Python, especially when reading someone else's code, or my own old bad code, is that I find that Python doesn't fit [my] brain.
The lack of typing (in my experience you always end up with a bunch of libraries that don't have type hints) means I spend most of my time just figuring out what I'm supposed to pass to a function (I hate the django docs. Give me something like docs.rs where I can quickly scan what functions something implements, and see what they accept and what they return instead of forcing me to read an 800 page novel that STILL doesn't give you that basic info), and writing tests and trying to guard against passing the wrong thing around.
- stevesimmons 4y agoIn my own code, I always use typehints and write good docstrings (nearly) everywhere. Visual Studio Code's type checker saves so much time and has improved my code quality to no end. It is especially powerful on polymorphic inputs, making sure the different code paths operate on the input type you expect.
- shanebellone 4y agoPyCharm is good for this too. I've recently started using Type Hints by default. At the very least, it makes your code more readable. Nothing bad comes from that.
- type-r 4y agoI started enforcing type hinting in my personal projects. 99% of the time it's easy and useful to add. When I can't figure out how to make a mypy error go away within 30 seconds, I just disable it for that line. I feel this makes for very good 80-20 value/effort tradeoff. I will say that more than one bug has been found after I disabled the single line hint though! Always surprising to me how powerful types can be.
- mharig 4y agoI do not see the benefit of type hints. Good docstrings (and naming of the function and arguments) are superior, at least for the human. Type hints are too much clutter.
- baq 4y agoThere’s a certain program size from which they start to make sense and further still the benefits are obvious - you have a computer to help solve puzzles for you, so why not use it if the puzzle is ‘will this peg fit into that hole?’ when you have thousands of pegs and holes.
- mharig 4y agoAnd so you end up writing climb_the_wooden_ladder(l: WoodenLadder) plus climb_the_aluminium_ladder(l: AluminiumLadder) or press all into an OO hierarchy instead of climb(thing): '''Climb a thing with steps''' # prevent run time crash: if not hasattr(thing, 'getSteps'): hitDeveloper()
- baq 4y agoNo, you define a Ladder (or Climbable if you’re feeling fancy today) Protocol and all remains good in the world.
- cfu28 4y agoNo need for OO hierarchy, just use a protocol
- mharig 4y agoOh, I missed the Protocol class of the typing module. Have to further investigate the usage of this. Thanks to you and baq!
- kbelder 4y agoI have a fear that Python will be improved to the point it offers no more advantage over other languages.
- dehrmann 4y ago> The lack of typing It's gotten a lot better with type hints and typeshed, but I agree, not knowing what type an arg should be and hoping duck typing works out isn't great.