Drew made a language without generics... But why?
2 years ago
@krixano there is a big difference between forcing, for example, explicit instantiating of a template (that would make bloating explicit), and completely taking away ability to write general functions.
You would manually write new functions that does the same thing
Just imagine yourself doing that. I can't - because I would throw my computer out of the window after rewriting sorting function for 10th time. I would simply never use such language. 路 2 years ago
@staticvoid You would manually write new functions that does the same (or similar) thing, but takes all the types that would be used. Or, in languages that have macros, you can use a macro. Also, polymorphism can also be used, if the languages has that.
But the intention behind not having generics is that it's supposed to force people to not make general functions, and so instead of just copying a function and changing the types, you would actually optimize that function for the types that it takes.
I personally do think that while I agree with the above, generics are also sometimes useful, and so would rather have a language that has some form of generics. 路 2 years ago
@krixano what happens if there is no alternative to generics? E.g. how do I write a sorting function that works with any type that provides `<`? 路 2 years ago
@eph https://harelang.org/ 路 2 years ago
Generics are one of the things that compilers spend a lot of time processing, because the compiler basically just copies and pastes the function for each type (or combinations of types) that is used with that function. It would also have to do the type-checking in a way that works with generics.
One of the reasons why some languages (including Golang prior to their latest updates where they added in generics) chose not to do generics is for the reason above. The other reason is that it incentivizes programmers to use generics over other methods and to overgeneralize their functions when a different method might be more optimal. 路 2 years ago
What do you mean? What does a language without generics look like? 路 2 years ago