5 ms·
I used languages with static types for half of my professional life, the last one was Java, and languages with dynamic types in the other half. I never felt lik
by pmontra 10y ago
I used languages with static types for half of my professional life, the last one was Java, and languages with dynamic types in the other half. I never felt like I have more bugs in dynamic typed languages. What I felt is that I don't have to waste time writing stuff like ArrayList<Whatever> when just something = {} works perfectly well in practice.
I understand that many people say that with static typing if it compiles it works, but I remember using debuggers quite a lot.
I'd say that if one wants types there are plenty of languages to choose from. There is Crystal if one likes Ruby.
Contracts are interesting. I remember Eiffel and other languages. Those could be useful regardless of the kind of typing the language use.
BTW, invariants are another useful tool when designing some algorithms and were neglected recently.
- bjz_ 10y ago> I never felt like I have more bugs in dynamic typed languages. What I felt is that I don't have to waste time writing stuff like ArrayList<Whatever> when just something = {} works perfectly well in practice. Java is a pretty terrible language when it comes to static types. If you have a language that allows you to work with types in a succinct and expressive way, you end up with a powerful modelling tool that can help you reason about and design programs. The side-effect of this is to have far less runtime crashes (you know what cases to check for, like nullable data), great documentation for your future self and your fellow devs, and a greater liberty to do large scale refactors without worrying about breaking things.
- gregschlom 10y agoAgreed. Kotlin is an excellent example of such a language, and I'd highly encourage anyone, especially devs with a strong Java background, to try it out.
- gregschlom 10y agoAgreed. Kotlin is an excellent example of such a language, and I'd highly encourage anyone, especially devs with a strong Java background, to try it out.
- twblalock 10y agoThe self-documenting nature of statically typed programs is something that critics often miss. Making a contribution to an existing codebase is far easier when it is statically typed. You can very easily understand what you ought to do, because the constraints of the type system help you figure out exactly what things are, what arguments you can pass to a method, how the other programmers used the types, etc. In contrast, contributing to an existing codebase in PHP or Rails is much harder. Nothing will stop you from sending the wrong arguments to a method, or adding members to classes that should not be modified, or even simply refactoring and forgetting to change all of the usages of the types and methods you modified.
- Retra 10y agoWell, the converse argument is that most dynamically typed languages allow you to explore the codebase in a REPL by playing with it. And there's a reasonable amount of noise that is added by static types, since often the types don't tell you how to use them, so you have to read the docs anyhow. Which really means there's a big difference between static types that everyone knows and uses, and those that someone invented for particular use. That difference seems more significant than the static/dynamic divide.
- twblalock 10y agoThere are statically-typed languages with REPLs, e.g. Scala, C#, F#, and the upcoming Java 9, so REPLs are not an advantage of dynamic languages. There are even REPLs for C++. Many people's impressions of static languages are based on Java from 10 years ago. It's really quite different now.
- bjz_ 10y agoI find the Haskell, SML, and OCaml repls very nice to use as a exploratory tools. It's made all the nicer due to the types, because you can quickly iterate on gluing things together in different ways. It's something I miss with Rust, although there is progress being made to implement one.
- chowes 10y agoIt's probably unfair to compare bugs to bugs, since with a typed language, your compiler and editor caught many "bugs" before they even hit your application.
- mikekchar 10y agoI have similar experience. For the most part I agree with you, but types often make reading code a lot easier. I've found that many people tend to encode their types into the variable names in languages without type checking. A lot of refactoring tools work more easily with types as well. If you have a method like "write", it's nice to be able to rename it and know 100% for sure that you didn't break something. I'm with you on the excess typing thing, but I still think types are useful just for tool integration. One day I hope that a popular language will emerge that presents an AST so that we can have non-type based refactoring browsers like Smalltalk's.
- pjmlp 10y agoWhile I enjoy using dynamic languages in small projects, I dislike to use them in the typical enterprise projects. Most of my time is spent playing the game "which type is this?". Yeah, one can write unit tests to play the role of the compiler's type checker, but in the enterprise unit tests are pretty low in the deliverables list, usually the bullet following documentation.