5 ms·
Hmm, rarely have I thought types were a burden, rather than help, maybe I’m weird. Maybe I spend effort in making sure my types are useful and easy to work wit
by seer 2y ago
Hmm, rarely have I thought types were a burden, rather than help, maybe I’m weird.
Maybe I spend effort in making sure my types are useful and easy to work with, but one previous TypeScript I got to a state where _all_ of my database queries were automatically typed, and all of my requests and responses too, so both input output were guaranteed to be correct bg the compiler, so any bugs or errors that were left were business logic.
It was incredibly liberating - like pairing with someone who was junior but very pedantic. I ended up writing almost no unit test and only having integration level tests, cause the job of those test was mostly covered by types.
And writing the code itself was such a pleasure - you get immediate feedback if your program is correct _as you type it_. The most bizarre consequence of all this to me was writing a program for almost 2 hours, hundreds of lines of code, and then executing it and having it do exactly what you wanted on the first compile. That was both scary but exciting!
One can get over-constrained with types for sure, where you’re sending more time “fighting the types” rather than writing your code. But this is all just learning, once you understand how the typesystem works it all becomes easy to work with.
It was the same story with tests - once I started testing everything- it wasn’t easy to adopt my code to be testable, took effort, but then I learned how to make code pure, move state to the edges, manage dependencies etc, and all of those are useful practices in their own right, regardless if you write the tests or not.
Same with types - schema design and invariants, state machines, edge cases in type conversion and how to lock and manage external dependencies. Sets, unions etc - it became the way I reason about code with of without types and my code is better for it.
I also assume that types would make AI generated code much better _and more reliable_ because of the additional information and structure that it provides, so I recon they are here ti stay.
- fendy3002 2y agohave you worked with java or C#? both are where types sometimes become a burden. No, you cannot just do something like this: ``` return { data, message: "OK" }; ``` you need to declare a class or struct that match the definition. There's mapper and builder everywhere. Adding / deleting 1 column from a datatype can force you to make changes in 5 places due to mapper / builder.
- qball 2y agoYes you can. C# has had anonymous types since language version 3.0, released nearly 20 years ago; everyone who has used .Select() at the end of a LINQ query has used this.
- seer 2y agoAs a matter of fact - no I haven’t. My experience with types is TypeScript, Elixir and a bit of Scala. I always try to have “clojure style” types where I don’t try to be too prescriptive - don’t lock things down if you don’t need to, just the minimum possible types to make sure the code I’m writing is correct, and nothing more - Rich Hicky’s talks on Clojure’s Spec was an eye opener. I have been told by some java devs though that it is a matter of style - while unconditional it is possible to write java code with much less boilerplate if one uses newer language features and actually tries to hold the cruft at bay. Is that true?
- fendy3002 2y agoidk, haven't use newer java or C# after 2014-ish, though I think I've read C# has support some dynamic typing, never explore that. Never touch Elixir and Scala too so cannot comment on that. TS though, the type declaration is amazing with it's union, optional and intersection type!
- behnamoh 2y ago> My experience with types is TypeScript, Elixir and a bit of Scala. Dude, Elixir only recently introduced some sort of a type system...
- ianleeclark 2y agoElixir has had dialyzer + type hints for years
- seer 2y agoWhile not part of the compiler, the dialyzer’s types are quite nice, even if sometimes it is a bit clunky - I’ve noticed that most of the time when I thought it was “wrong” it actually wasn’t and had picked up on some bug / misunderstanding in my code, though error messages could have been better
- AdieuToLogic 2y agoRegarding programming with a mature static type system: > It was incredibly liberating - like pairing with someone who was junior but very pedantic. This is exactly what is happening. To achieve the same level of semantic confidence across a code-base in a dynamically typed language (such as JavaScript, Perl, Python, Ruby, etc.) would take the effort of a diligent junior programmer. Which, in a way, is what a strongly-typed language compiler does IMHO.