this post was submitted on 01 Apr 2025
174 points (89.2% liked)

Programmer Humor

36648 readers
320 users here now

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

Rules:

founded 5 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 6 points 2 months ago (5 children)

This is just preferring runtime validation instead of compile time validation.

[–] [email protected] 8 points 2 months ago (4 children)

And relying on runtime validation is a horrific way to write production code

[–] [email protected] 3 points 2 months ago (3 children)

Why though? I've genuinely never had a problem with it. If something is wrong, it was always going to be wrong. Why is it preferable to have to write a bunch of bolierplate than just deal with the stacktrace when you do encounter a type error?

[–] [email protected] 1 points 2 months ago

I’ve genuinely never had a problem with it. If something is wrong, it was always going to be wrong.

Have you worked on a production code base with more than a few thousands of lines of code? A bug is always going to be a bug, but 99% of the time it's far harder to answer "how is this bug triggered" than it is to actually fix the bug. How the bug is triggered is extremely important.

Why is it preferable to have to write a bunch of bolierplate than just deal with the stacktrace when you do encounter a type error?

If you don't validate types you can easily run into a situation where you write a value to a variable with the wrong type, and then some later event retrieves that value and tries to act on it and throws an exception. Now you have a stack trace for the event handler, but the actual bug is in the code that set the variable and thus is not in your stack trace. Maybe the stack trace is enough that you can figure out which variable caused the problem, and maybe it's obvious where that variable was set, but that can become very difficult very fast in a moderately complex application. Obviously you should write tests, but tests will never catch every weird thing a program might do especially when a human is involved. When you're working on a moderately large and complex project that needs to have any degree of reliability, catching errors as early as possible is always better.

load more comments (2 replies)
load more comments (2 replies)
load more comments (2 replies)