3 ms·
Ask HN: Why are dynamic type systems important?
Is there really a necessary use case? If a type is eventually expected to meet the parameter requirements of a procedure, what is the benefit? You could argue that in a language where all types are compatible with all operators this isn't true. But you can't always write code that's compatible with all trivial types.
Working with Python, a lot of times I find myself having to figure out the type anyway.
Is it just to make higher level languages more friendly to beginners, until they learn enough to realize data types do exist?
- cratermoon 5y agoSimpler syntax, avoiding all the declaration code Don't need to be compiled Easier to keep changes small and local to the code changing Unit tests need less boilerplate/mocking/stubs Simpler metaprogramming Easier generic programming
- mastrsushi 5y ago>Easier to keep changes small and local to the code changing >Unit tests need less boilerplate/mocking/stubs What do you mean by these?
- cratermoon 5y ago>Easier to keep changes small and local to the code changing When refactoring code in a statically-typed language, the programmer must do extra work to satisfy the compiler, perhaps even changing code elsewhere in the program. >Unit tests need less boilerplate/mocking/stubs In a dynamically-typed language, if the code under test calls a method on another class, that's the only method that needs to be mocked. If the language were statically-typed, the entire class would have to be mocked or at least provided with stub implementations of the methods not called. You can see examples of the kind of extra work a statically-typed language requires in Kent Beck's book on Test Driven Development, where a class has to be changed from abstract to concrete just to satisfy the compiler. Also, I'm glossing over some of the additional dimensions of typing, like strong vs weak and manifest vs inferred types. Different languages have different requirements.