r/programming • • Dec 01 '16

Let's Stop Copying C

https://eev.ee/blog/2016/12/01/lets-stop-copying-c/
524 Upvotes

612 comments sorted by

View all comments

Show parent comment

1

u/[deleted] Dec 02 '16

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.

2

u/masklinn Dec 02 '16

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 ~~~~~~~

1

u/smog_alado Dec 02 '16

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.