4 ms·
> Hype: "Static Typing reduces bugs." It’s only hype because it’s imprecisely stated. Static type systems make entire classes of bugs impossible at runtime. Th
by aranchelk 4y ago
> Hype: "Static Typing reduces bugs."
It’s only hype because it’s imprecisely stated. Static type systems make entire classes of bugs impossible at runtime. The stronger (read less permissive) the type system, the more classes of bugs cannot occur.
- moffkalast 4y agoOn the other hand it increases development time and makes modifications and new features much harder to implement. If you took it to the extreme, you could also mathematically prove your code is correct for every input variable. Everything's a trade-off, the question is which approach is best for your application. Your average website doesn't warrant as much rigor as a Mars rover.
- forrestthewoods 4y agoHard disagree. Dynamic typing only increases development speed for the first few thousands lines of a solo programmer project. After that it is, in my personal experience, a significant drag on development speed. Furthermore, dynamic typing makes modifications and new features significantly harder to write. Turning compile-time bugs into runtime bugs is a catastrophic decrease in development speed. That’s my personal experience at least. YMMV.
- moffkalast 4y agotaps temple That's why you keep code encapsulated as much as possible in separate files/classes up to like a thousand lines. Any more will be unreadable anyway. > dynamic typing makes modifications and new features significantly harder to write Depends on what you're doing I suppose. Adding a parameter to an object? With dynamic typing you just add it to the object in literally any location, no issues. With static typing you might just need to refactor half your codebase if you have lots of interfaces. Have fun resolving merge conflicts with your team. Not only that, but (in Java as an example) serialization codes for objects will change unless you planned for that previously (you didn't), making old objects impossible to load. A completely new bug that's created solely by static types. And it's not the only one.
- forrestthewoods 4y agoMy personal hell is having some nested objects/dictionaries and wanting to either add or remove a layer. Good luck and God speed in your attempt to simply find every single line of code that needs to be updated.
- ReactiveJelly 4y ago"serialization code"? Maybe it's an issue with Java. In Rust if I add a new field, I just wrap it in an Option. When de-serialized, old objects have a None, new objects with the field have a Some. When serializing it's just `Some (5)` instead of `5`, if it's an int. No runtime crashes from nulls, either.
- moffkalast 4y agoYeah I haven't really ever used Rust, maybe it handles these sort of things better.
- aranchelk 4y agoAre you sure all statically typed languages are slower to develop in than comparable dynamic ones? I used to be thoroughly convinced this was true, but 3 things are now making me doubt it: 1) Statically typed languages with inference don’t require time spent writing signatures. 2) I know I’ve spent time chasing down bugs in dynamically typed software that would have been caught by a type checker. 3) I also know I’ve spent time writing tests for conditions in dynamically typed code that wouldn’t pass a type checker.
- greymalik 4y ago> 1) Statically typed languages with inference What are some strong examples of this? Haskell does an amazing job with it. Java technically supports some amount of inference, but it doesn’t reduce verbosity by all that much. Apart from those I haven’t run into it.
- sanedigital 4y agoSwift and Kotlin both do a fantastic job here. You think in types but don’t have to spend much time typing them.
- aranchelk 4y agoHaskell and PureScript are the ones I’ve used.
- albntomat0 4y agoOff the top of my head, Rust and OCaml do as well. Ive had to occasionally specify a type, but it works well in practice.
- moffkalast 4y ago> bugs that would have been caught by a type checker Type checking also introduces its own set of additional bugs by the virtue of object incompatibility, that do not exist at all in dynamically typed languages (or are handled correctly every time by the compiler/interpreter automatically). Take as an example exchanging objects over sockets, rest, files, etc. Whenever the object definition changes in another piece of the software stack the statically typed parts will crash upon receiving the updated objects, even if it's just one new param added that would've been fine otherwise if dynamically typed (or say change from a float to a double which can be irrelevant). A nightmare in systems with lots of moving parts. One might say that's working as intended, and it of course is, but it also forces you to fix and recompile all of that for no real net gain. Hence the longer dev time I mentioned. I've spent years working with statically typed languages, and I honestly don't think I'll ever go back to them in any professional capacity.
- Tyr42 4y agoOkay please debug my py2 -> py3 migration bytes vs strings code with no type annotations. Aaaahg it burns. I basically am going through and first annotating, then upgrading.
- moffkalast 4y agoAhaha I've had the exact same issue recently, fortunately it was only in a few spots. Fair enough. Interestingly enough, py2 was smart enough to automatically load things in the correct format. Loading a binary file? Get bytes. Loading a text file? Get a string. Py3 has worse functionality now, all for the sake of consistency.
- sh4rks 4y agoHype: using dynamically typed languages increases development time
- PartiallyTyped 4y ago> On the other hand it increases development time and makes modifications and new features much harder to implement I am not sure that that is correct. Type inference significantly decreases development time imho, and access to compiler errors means significantly less testing time because a certain class of errors is avoided. Personally, I find that my productivity w/ Haskell was significantly higher than with python exactly because of the type system even though I have 3x the experience in years w/ Python. I have inherited (hah) a project at work and had to introduce all sorts sanity checks (mypy, pylint, etc) as pre-commit hooks to make my life easier wrt bug hunting.
- tgv 4y agoThe articles from the review (as far as I've scanned them) seem to take a common view of static typing, but the studies themselves are obviously weak. There's almost no way to test such statements, because how are you going to generalize that? Some studies use restricted tasks, which would provides some indication of the usefulness of static typing for e.g. beginners, but then the reviewer starts mixing up all kinds of problems and concepts. E.g., who cares that there's more variation between programmers than between languages? To use that review as an authoritative statement is ingenuous, to say the least.