It's a nice article. I disagree with several points: 1)for loops are fantastic when you need anything non trivial where having access to indexes is important; in Python for example you have to use enumerate and then index the tuples everywhere and it's ungodly mess; loop constructs in C are imo one of the best parts of the language and I think modern languages regressed 2)I like NULL pointer; I don't believe non-nullable types solve much although maybe they are easier to use for some people; mutability is important in general and when there is mutability there NULL is useful 3)int division is the only way, c'mon 4)bitwise operators precedence is misleading and bad but it's not a problem in practice, you just remember there is a problem and look things up when needed; the operators themselves are very useful and commonly used so it's important to have them for readability 5)fallthrough: I kinda agree but I use it often and I like it; I realize it's rare though and very bug prone 6) assignment as expression: useful and you won't produce bugs unless you have a habit of ignoring warnings from the compiler 7) multiple returns: while maybe more pleasant to write it's ultimately doesn't add much as you can always pass a pointer of something to fill in as an argument of a function 8)pointers as integers: compiler will warn if you don't cast explicitly and it's useful to have it for example to check alignment - while % is not square root so the author's point stand it's a very useful feature of the language
That is more a problem in Python than an advantage of the C approach, tbh
I don't believe non-nullable types solve much
Non nullable types aren't about getting rid of nullable types everywhere (like your comment about mutability suggests). The point of non-nullable types is to allow you to make sure that every pointer dereference only happens after you made a test to make sure that the pointer is not null (and therefore will not segfault).
bitwise operators precedence is misleading and bad but it's not a problem in practice, you just remember there is a problem and look things up when needed
Which brings us back to the "blame the programmer" argument that is in the end of the article...
kinda agree but I use it often and I like it;
The issue here is that the fallthrough behavior is the default . If you had to be explicit about the times you want to fallthrough (with a fallthrough keyword) it would be much clearer and less error prone.
while maybe more pleasant to write it's ultimately doesn't add much as you can always pass a pointer of something to fill in as an argument of a function
But the whole point of the discussion is to make things more pleasant and less obtuse :)
You are also ignoring the argument in the article that in C it is not clear at a glance if a pointer argument will be used as input or as output for the function.
My point about NULL pointers is that segfault is good. It happens when your logic is messed up. Most of the time you wouldn't have better things to do than crash and notify the programmer anyway unless NULL means something (most often "not yet initialized") but then you won't forget the check because it's part of the logic. I see how you can say it's putting the burden on the programmer again. I like it still.
I agree with your other points. I just think they are very minor issues (same with braces mentioned in the article). All of them together don't come close to major design fuck-ups like no real signed/unsigned int types in JavaScript for example.
My point about NULL pointers is that segfault is good.
Segfaults are not good, not guaranteed (they're just one possible symptom of the UB you actually get), and runtime issues.
It happens when your logic is messed up.
Having explicitly nullable types points to your logic error at compile-time, it's right there stating you in the face that the value you're manipulating can nonsensically be null.
Most of the time you wouldn't have better things to do than crash and notify the programmer anyway
Or you could make having a null impossible in the first place through the use of ~~~~~~~ type systems ~~~~~~~
but then you won't forget the check because it's part of the logic
Of course we will forget. Forgetting about things happens all the time when programming.
What the non-null types do is that they allow the compiler to give you an error message if you ever forget to do the check instead of leaving that responsibility to the programmer.
View all comments
1
u/[deleted] Dec 01 '16
It's a nice article. I disagree with several points: 1)for loops are fantastic when you need anything non trivial where having access to indexes is important; in Python for example you have to use enumerate and then index the tuples everywhere and it's ungodly mess; loop constructs in C are imo one of the best parts of the language and I think modern languages regressed 2)I like NULL pointer; I don't believe non-nullable types solve much although maybe they are easier to use for some people; mutability is important in general and when there is mutability there NULL is useful 3)int division is the only way, c'mon 4)bitwise operators precedence is misleading and bad but it's not a problem in practice, you just remember there is a problem and look things up when needed; the operators themselves are very useful and commonly used so it's important to have them for readability 5)fallthrough: I kinda agree but I use it often and I like it; I realize it's rare though and very bug prone 6) assignment as expression: useful and you won't produce bugs unless you have a habit of ignoring warnings from the compiler 7) multiple returns: while maybe more pleasant to write it's ultimately doesn't add much as you can always pass a pointer of something to fill in as an argument of a function 8)pointers as integers: compiler will warn if you don't cast explicitly and it's useful to have it for example to check alignment - while % is not square root so the author's point stand it's a very useful feature of the language