News for hackers. Stuff that matters.
Re:Nginx C function by Something1234 on Sunday October 14, 2018 @12:45AM (#18211420)
It just takes discipline. The discipline to not haphazardly throw macros all over the place, and keep them pure(no side effects).
Re:Nginx C function by abstractbeliefs on Sunday October 14, 2018 @01:40AM (#18211548)
Sadly, the reason that discipline is such a vaunted virtue is because it's hard. Even the most well meaning and diligent C developers still make mistakes.

Tools should be ergonomic, they should reduce the need for diligence, care, discipline, and intelligence.

I'm not saying that the above aren't all important to programming, or that we should abandon anything that's not easy, but we're humans and make human mistakes and tools that are unforgiving when we do are ripe to be replaced by those that nudge us back on track.

Re:Nginx C function by Something1234 on Sunday October 14, 2018 @01:56AM (#18211572)
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.

Re:Nginx C function by abstractbeliefs on Sunday October 14, 2018 @02:05AM (#18211592)
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.

Re:Nginx C function by anonymoushn on Sunday October 14, 2018 @02:54AM (#18211717)
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.
Re:Nginx C function by sureaboutthis on Sunday October 14, 2018 @09:31AM (#18212792)
That's why we choose to use C and do the other things, not because it is easy, but because it is hard, because that goal will serve to organize and measure the best of our energies and skills.