Hacker News new | past | comments | ask | show | jobs | submit login

>Hold it right there. I've never seen anyone argue that static type systems prevent bugs.

Really? I see this every single time the subject is brought up. And, to be fair, they do catch some bugs, it's just that they do so at a cost.

>What the hell is customer? What is payment methods? What fields are available on these objects? What methods can you call on them? no freaking idea.

And, if they are all strings, how much more of an idea do you have?

Static typing does not necessarily help solve this problem - a combination of reduced scope(i.e. looser coupling), more specific variable naming and higher cohesion (e.g. having a customer object) do.

Moreover, there's a super easy way to figure out what all of those things are and figure out how you want to change it - run a behavioral test and launch a REPL when it hits that function.

At that point you can inspect customer, use autocomplete on it and even experimentally run code.

>If anything, static type checking helps experimentation because you can change your mind quickly and the compiler will help you catch all the stupid mistakes that can occur from mismatching types or mistyping variable names. This removes a huge cognitive tax and makes programming more enjoyable.

Behavioral tests perform this function equally well, if you have them.




> IMHO behavioral tests perform this function equally well.

I think a common pitfall in these discussions is to compare the worst case examples rather than reasonable quality codebases. I'd be far more interested in, say, time/cost to correct result metrics for a well-maintained Python codebase which has reasonable use of tests & linting (e.g. flake8) to an equivalently-proficient team using a statically typed language.


If we're discussing well-maintained code, then I would expect that the public interface is documented, at least in docstrings. Then I also know what the parameters are.


Agreed — I'm just wondering about how to quantify the impact of various changes. A dynamic language project with no tests, etc. is going to look like a selling point for static typing but I suspect the real-world bug counts for, say, a Python project using mypy (or even flake8 + tests + coverage) is going to be a lot closer than you might think from how heated these discussions get.


There was a study that did a line by line translation of 4 python projects to haskell and caught some bugs (between 0 and 4 per project): http://evanfarrer.blogspot.co.uk/2012/06/unit-testing-isnt-e...

I got the impression that the bugs found were either not at all serious (e.g. throwing a typeerror on malformed input instead of some other nicer kind of error) or were in areas of the code not covered by tests.

Unfortunately the author does not rate them by severity.


Thanks - that's a lot like what I had in mind!

My gut feeling is that dynamic typing + tests & static analysis is faster than very heavyweight languages (e.g. Java) but probably near or less than languages with more advanced typing systems like Haskell or Rust, but I'd really like to see something more comprehensive than a subjective opinion.


What is behavioral test? Like, I don't understand all these weird paradigms that people come up with to deal with the deficiencies of dynamic typing.

If declaring structs is seen as costly overhead that complicates coding, tests are when more cumbersome.


>What is behavioral test?

A behavioral test is a test that tests the behavior of a piece of software, as opposed to a test that checks types or implementation details or something else that isn't behavior.

It is perhaps not necessary to write tests like these in languages that produce code that does not have bugs. I have yet to encounter such a language.

>If declaring structs is seen as costly overhead that complicates coding, tests are when more cumbersome.

You do not write tests then?


No I do not. I specially don't write unit tests.




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

Search: