687
In case you forgot. (lemmy.world)
submitted 9 months ago by [email protected] to c/[email protected]
you are viewing a single comment's thread
view the rest of the comments
[-] [email protected] 12 points 9 months 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
687 points (92.0% liked)

Programmer Humor

31326 readers
20 users here now

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

Rules:

founded 4 years ago
MODERATORS