Earlier quoted context omitted.
And instead of adding a check and crashing visibly here you wait even longer until your program misbehaves due to the error? The longer the program runs after something went wrong, the harder it is to debug, and the more likely it becomes that you get an exploitable bug.
Performance is a feature and that null check has a cost. The code is correct. The null check is unnecessary. The bug is passing null in.
Linus Torvalds' good taste argument for linked lists, explained
291–300 of 339 posts
Re: Linus Torvalds' good taste argument for linked lists, explained
#292Earlier quoted context omitted.
That's a pretty big freakin thing to leave out, though. Code that depends on its context is, some would say, bad.
Simply put, safety slows code down. It's a matter of whether you know what's happening underneath or not. The more you try to make C completely safe, the more you slow it down and therefore remove the need to have written it in C in the first place. Whether that's a good thing or not is an exercise for the implementer.
Re: Linus Torvalds' good taste argument for linked lists, explained
#293Earlier quoted context omitted.
Are you arguing that we should leave known crash bugs in the code?
What you are espousing is known as “defensive programming” which is very much a bad thing (tm).
Re: Linus Torvalds' good taste argument for linked lists, explained
#294Earlier quoted context omitted.
That code is not a general purpose library function; it assumes the element exists. If you call that method and the element doesn't exist, presumably something has gone wrong already. Adding a NULL pointer check is not going to fix it. You just silently ignore the error. You'll prevent the crash, but there's no mechanism for handling the error.
And instead of adding a check and crashing visibly here you wait even longer until your program misbehaves due to the error? The longer the program runs after something went wrong, the harder it is to debug, and the more likely it becomes that you get an exploitable bug.
Re: Linus Torvalds' good taste argument for linked lists, explained
#295Earlier quoted context omitted.
The same argument was made recently about the reduce function: it's a known pattern for some and a hard to understand trick for others.
Yes, and you get used to reduce. map, filter and reduce were hard for me to follow… until I used them two or three times and now I understand them easily and they naturally come to my mind when I need to solve a problem which they can help solving. They are good tools (especially in codebases shared with people who are allergic to loop statements!)
Re: Linus Torvalds' good taste argument for linked lists, explained
#296Earlier quoted context omitted.
Performance is a feature and that null check has a cost. The code is correct. The null check is unnecessary. The bug is passing null in.
Safety is a feature and that null check prevents bugs. I'd rather have slow but safe code rather than fast but buggy code.
Re: Linus Torvalds' good taste argument for linked lists, explained
#297https://meta.slashdot.org/story/12/10/11/0030249/linus-torva...
Here using actually "pp" ;)
Re: Linus Torvalds' good taste argument for linked lists, explained
#298Re: Linus Torvalds' good taste argument for linked lists, explained
#299Earlier quoted context omitted.
I’m not a fan of everything Bukowski wrote, but I wouldn’t try to censor him so that little Jimmy could read it, and I liked the movie Barfly. Similarly, I’m not a fan of everything Linus wrote, but I wouldn’t enforce bad CS101 code on him so that little Jimmy could read it, and I like Linux.
Who is little Jimmy?
Re: Linus Torvalds' good taste argument for linked lists, explained
#300Earlier quoted context omitted.
I thought that only makes sense in JS. In C any nonzero value is considered "truthy", and on most architectures NULL is defined to be (void * )(0) or similar. The logical not operator AKA bang operator will replace truthiness with 0, and falsiness with 1. So applying it twice collapses all nonzero values to 1.
Well, yes, but that does absolutely nothing in this code, as it is immediately used as the argument to an if statement.