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

I remember a lot of praise for duck "typing" as if it was an innovation, and claims you should just write unit tests to catch type errors.

People kept glossing over the fact that writing typed code would be so much easier than writing untyped code with sufficient manual tests to catch type errors, because no one did the last bit. Things just broke runtime instead.



Agreed. I caught a bug in Python code I wrote yesterday by adding a typehint to a variable in a branch that has never been executed. MyPy immediately flagged it, and I fixed it. Never had to watch it fail.

I put typehints on everything in Python, even when it looks ridiculous. I treat MyPy errors as show-stoppers that must be fixed, not ignored. This works well for me.


Yes, this always struck me as completely bananas. Types are a vastly superior form of test for certain conditions.

Duck typing with type inference would be nice but seems to be completely esoteric. You could have both the flexibility of being able to write "func(arg)" without having to specify the type, and the constraint that if you call arg.foo() in your function the compiler should enforce that you actually have a foo method on arg.

(special side-eye to the people materializing methods and properties all over the place at runtime. This seems to have been a rails/python thing that is gradually going out of fashion.)


> I remember a lot of praise for duck "typing" as if it was an innovation, and claims you should just write unit tests to catch type errors.

> People kept glossing over the fact that writing typed code would be so much easier than writing untyped code with sufficient manual tests to catch type errors, because no one did the last bit. Things just broke runtime instead.

That was the dumbest thing ever. Exchanging automation for lots of manual work was supposed to be innovation?

So many tradeoffs so sometimes someone could write a clever, unmaintainable bit of brainfuck in the production app.


I love ruby for relatively small scripts, but I wouldn’t want to attempt anything very large with it. I find that once my scripts start to get too long I find the need to start adding manual type checking to keep from tripping over myself.




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

Search: