Hacker News new | ask | show | jobs
by jahaja 2230 days ago
> I'm not working with an ecosystem where my human time is less important than the language philosophy. I want to express a repetitive pattern in the language, and then never think about dumb bureaucratics again.

Writing code is not where time is spent. Repeating oneself, duplicating code, is fast and easy. Debugging someones code that felt like "expressing" themselves through it however, takes time, and a lot of it.

I really have no idea why some people so often need to use generics, and similar, beyond the built-in map and slice/array, when I seemingly do not, even though I write Go as my full-time job. Sure there a lot of difference between apps/domains, but the bulk of the code is usually not that different.

3 comments

Partially I agree,and I'm not happy to see this downvoted.

But more code written equals more code to read. Adding a field to a struct means modifying all the boilerplate too. It is all to common to forget just one place. Boilerplate plus maintenance attracts bugs.

Generics are easily overused and abused, but a well placed generic can save a ton of time.

As an example, and the pnly generic I wrote in a week, today I had to generate a ton of test data programatically in java. So I wrote roughly a 3 line method

  T select(int index, T... values)
and used it on each of the fields with different types like this:

  struct.anInt=select(i,0,1,INT_MAX);
This allowed me to quickly iterate trough all combinations of common and edge cases. If I had to specify all cases individually, there was no chance I'd exhaustively test every combinations.
I agree of course that there will always be situations where generics/expressiveness will be convenient. But my argument is about proportionality. I'd like to optimize for the 98% of the time spent, not the last 2%. It's like when people insists on buying an ultraportable laptop for work even though they'll never move it from their desk. - "But imagine how nice it will be that time I'll be on the train!".
Have you ever worked with sequences/iterators/generators or their abstractions? They make incredibly composable, portable, sound, and readable code. And most useful programs are built on patterns that can be optimally represented using them.

They're also impossible to implement and extend without generics.

If your mental model of writing a program is giving instructions to an abstract machine, generics may seem pointless. However if you're interested in representing a problem and its solution, and allowing the language tooling to translate that into an optimal list of instructions for an abstract machine - generics are pretty critical.

Kinda sad that this is getting downvoted, regardless of whether you agree it is certainly a cogent argument.
Whatever argument it's trying to make would have been better received without the blatant insults.