HACKER Q&A
📣 jlalfonso21

Dynamic vs. Static Typed Languages


What can do better static-typed languages that dynamic ones cant?


  👤 Comevius Accepted Answer ✓
1. Find type-related bugs at compile time.

2. More readable code.

3. More maintainable code.

4. More efficient generated code.


👤 UglyToad
I'd say it's about what static languages don't let you do that dynamic ones do. For example I just found a bug in some scheduling code I wrote where a date value could be null but I was treating it as non null. I change the type to nullable and the compiler tells me everywhere I currently use it in an invalid way.

Types help make (some) invalid states unrepresentable, though the type systems could always be better and some data can only be checked at runtime.

But you can focus your test effort on checking those logic conditions. In addition it makes teamwork far easier.

I'd compare it to the benefits of rust over plain C. Yes you can write safe code in C with a lot of discipline and being 100% focused all the time, or you can leverage tools to let you catch your mistakes and free mental cycles for the actual problem at hand.


👤 yhavr
- Painless refactoring. I change field "foo.bar" into "foo.quux" and the same field changes everywhere else in the (huge) codebase. Or I change the field name in the type declaration and immediately see what's broken.

- Integrated documentation. I see "foo", I see it's type, I see what can I do with it (if it's OO-like).


👤 runawaybottle
I’ll take the downvotes.

It can fulfill certain compulsive needs of certain personality types that like to be comprehensive (think compulsive note takers, list makers).

No harm done, everyone has their quirks.


👤 girishso
Detect typos, can be a huge time saver at times.

👤 preordained
Accretion...