Re:I like strong typing and compilation errors
by nostrademons on Thursday May 06, 2010 @02:06AM
(#1323701)
I don't really have a strong preference either way. The bulk of my professional work is in JavaScript with a fair amount of Python and C++ thrown in. I dislike the C++, but that's probably because the type system is brain dead rather than because the type system is static. I do most of my hobby hacking in Haskell, which has about the strongest type system imaginable. I'm hacking on a programming language of my own design, which will have static typing, but not to catch errors. I want static type inferencing because it lets the compiler generate usable, machine-checked, cross-referenced, auto-updating documentation from my source code, without having to update this myself.
I've found that I rarely have type errors in dynamically typed languages, as long as I program as if they were statically typed. For example, if my JS function only takes strings or objects with certain fields, I just document those and I almost never make mistakes with them. However, if I start defining functions that return string|int|bool, then I start getting confused. Do this often enough and it becomes essentially impossible to reason about my program.
Ironically, I've found that a good portion of my bugs in statically typed languages are type errors, in the form of null pointer exceptions. Haskell's Maybe type is the way to go here; yeah, it makes looking things up in a dict inconvenient, but I can't count the number of bugs I've avoided by being forced to deal with nulls up-front and not having them pollute the rest of the program.
I've found that I rarely have type errors in dynamically typed languages, as long as I program as if they were statically typed. For example, if my JS function only takes strings or objects with certain fields, I just document those and I almost never make mistakes with them. However, if I start defining functions that return string|int|bool, then I start getting confused. Do this often enough and it becomes essentially impossible to reason about my program.
Ironically, I've found that a good portion of my bugs in statically typed languages are type errors, in the form of null pointer exceptions. Haskell's Maybe type is the way to go here; yeah, it makes looking things up in a dict inconvenient, but I can't count the number of bugs I've avoided by being forced to deal with nulls up-front and not having them pollute the rest of the program.