Hacker News new | past | comments | ask | show | jobs | submit login

Mostly the compiler just needs to slap your hand harder, and tell you no when you do something stupid or depend on undefined behavior. Also better static analysis would be nice.

I completely agree with you on all points. Languages exist to make our lives easier.




Well, there's a little more than that, as we actually have told compiler devs we don't want that.

When developers demand that compilers compete with each other on fractions of a percent of runtime performance, we set ourselves up for things like UB acting in unintuitive ways. When people give us the choice between safer but slower systems, and fast but unsafe ones, until recently people have overwhelmingly chosen fast and unsafe and pretended they're superhuman enough to not write bad code.


This is probably too much to ask for. I recently fixed an issue caused by UB in openresty of the form "nginx uses a NULL pointer and a length of 0 to signify a null string" + "nginx sometimes searches for strings in other strings using a function that takes start and end pointers for the haystack". This function works fine on lots of 0-length haystack strings (probably returning no match), but as you probably know, NULL + 0 is allowed to evaluate to anything. This seems pretty hard to detect statically short of banning programs that do arithmetic on any pointer without first NULL checking it.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: