691
In case you forgot. (lemmy.world)
you are viewing a single comment's thread
view the rest of the comments
[-] wols@lemm.ee 12 points 1 year ago

Extra steps that guarantee you don't accidentally treat an integer as if it were a string or an array and get a runtime exception.
With generics, the compiler can prove that the thing you're passing to that function is actually something the function can use.

Really what you're doing if you're honest, is doing the compiler's work: hmm inside this function I access this field on this parameter. Can I pass an argument of such and such type here? Lemme check if it has that field. Forgot to check? Or were mistaken? Runtime error! If you're lucky, you caught it before production.

Not to mention that types communicate intent. It's no fun trying to figure out how to use a library that has bad/missing documentation. But it's a hell of a lot easier if you don't need to guess what type of arguments its functions can handle.

this post was submitted on 26 Sep 2023
691 points (91.9% liked)

Programmer Humor

32400 readers
253 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS