Hacker News new | ask | show | jobs
by hyperman1 2230 days ago
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.
1 comments

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!".