Hacker News new | ask | show | jobs
by jitl 1739 days ago
I don’t need to spend any more time with static typed languages that avoid generics. I wrote Go for several years, tried to love the simplicity, then tried to love code generation. Then I gave up. I don’t need to repeat that experience.
3 comments

I agree. It's not for everyone but there are many different kinds of developers.

If you are and can hire smart people who can use generics without introducing extra tech debt and complexity, I definitely recommend the ones with generics like Rust and Haskell. But the problem is that I'm not smart enough.

I'm in the same boat. I still enjoy writing Go, it's my primary language but adding generics is something I have been looking forward to for a long time. there is so much code that could be made simpler or deduplicated with generics.
As JS developer it took me sometimes realizing the importance of generics, as by default in JS problems it solves doesn't exist. Funny how typed language advocates want automatic casting in the end after all.
Generics are the polar opposites of automatic casting. They exist so you don't have to shoehorn one argument type into another.

JS isn't exactly the best environment to understand this. Ideally, use a compiler language that can show you the generated assembly (`gcc -S ...` with C++ for instance). Then you can see first-hand how type-specific implementations of a generic function look like.

Since when are generics automatic casting?
it's not but it's essentially the same practically speaking -- you get type A|B|C you write code to interact with it in just one way. Either by casting, or generics. weakly typed language do that for you, but they are looked down on.
I think you're missing the key point of statically typed languages, that the compiler catches errors for you. Generics are valuable because it allows users to write "generic" reusable functions that are still checked by the compiler. Of course dynamically-typed languages can do this easily, but that's not the point.
Blub 101