💾 Archived View for station.martinrue.com › staticvoid › 2830fd35585c46ab954cd8d0953aaccf captured on 2023-03-20 at 19:31:49. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-01-29)

➡️ Next capture (2023-04-20)

🚧 View Differences

-=-=-=-=-=-=-

👽 staticvoid

Drew made a language without generics... But why?

10 months ago

Actions

👋 Join Station

6 Replies

👽 staticvoid

@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. · 10 months ago

👽 krixano

@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. · 10 months ago

👽 staticvoid

@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 `<`? · 10 months ago

👽 staticvoid

@eph https://harelang.org/ · 10 months ago

👽 krixano

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. · 10 months ago

👽 eph

What do you mean? What does a language without generics look like? · 10 months ago