Live data from Hacker News

“C is how the computer works” is a dangerous mindset for C programmers

words.steveklabnik.com

31–40 of 387 posts

Re: “C is how the computer works” is a dangerous mindset for C programmers

#31
post #10

C has never been "how the computer works", its abstract model is way too… well, abstract. But there is an interesting catch to it: because C is so important, and programmers at large know so little "real C", vendors do their damndest to make it work for them. A well-known microcontroller forum in Germany is constantly pushing that you need to make your code safe in the case of concurrent access to a variable by a mai…

Yes, except it's "less abstract" than any other language in mainstream use...

Re: “C is how the computer works” is a dangerous mindset for C programmers

#32
post #23

This may be a little off topic but it is something that until now I’ve never questioned in my entire career: Is the c in C supposed to stand for “computer“? If not, what is it?

According to Wikipedia, C is named C because it resulted from work done by Dennis Ritchie to improve the language B, and C comes after B. B came from Ken Thompson making a cut down version of the language BCPL, so he just kept the first letter.

https://en.wikipedia.org/wiki/C_(programming_language)

Re: “C is how the computer works” is a dangerous mindset for C programmers

#33
post #23

This may be a little off topic but it is something that until now I’ve never questioned in my entire career: Is the c in C supposed to stand for “computer“? If not, what is it?

It's the successor to the B programming language (also written by Ritchie and Thompson), which was derived from "BCPL": Basic Combined Programming Language.

Re: “C is how the computer works” is a dangerous mindset for C programmers

#34
post #6

Actually I look forward for enough momentum to be created in the community, to allow new C standards to change the way undefined behaviors are conceived, and make them as specified as possible, and even when they cannot in reasonable unique ways, to provide reference possible behaviors to select in order to have the least unexpected outcome for the programmer. Especially now that low level programming is abstracting…

You are never going to get any guaranteed sensible behaviour for a double free or an use after free [1]. In comparison to those giant issues, all other instances of UB are minor.

[1] well, you can today by swapping malloc for a GC-enabled implementation, but the fact is that almost nobody does.

Re: “C is how the computer works” is a dangerous mindset for C programmers

#35
post #6

Actually I look forward for enough momentum to be created in the community, to allow new C standards to change the way undefined behaviors are conceived, and make them as specified as possible, and even when they cannot in reasonable unique ways, to provide reference possible behaviors to select in order to have the least unexpected outcome for the programmer. Especially now that low level programming is abstracting…

> allow new C standards to change the way undefined behaviors are conceived,

Of all the potential issues that might be attributed to C, undefined behavior (UB) is the one that creates few to no problems at all.

To me, complaining about UB is like complaining about the quality of a highway once they intentionally break through the guard rails and start racing through the middle of the woods.

The reason why some behavior is intentionally left undefined is to enable implementations to do whatever they find best in a given platform. This is not a problem, it's a solution to whole classes of problems.

https://en.wikipedia.org/wiki/Undefined_behavior

Re: “C is how the computer works” is a dangerous mindset for C programmers

#36
post #23

This may be a little off topic but it is something that until now I’ve never questioned in my entire career: Is the c in C supposed to stand for “computer“? If not, what is it?

AFAIK the established history is that C was the successor to a language called B, which was a successor to a language called BCPL (which means "Basic Combined Programming Language"). So if anything, the "C in C" would mean "Combined". But most likely it doesn't mean anything at all, except "C comes after B" ;)

Re: “C is how the computer works” is a dangerous mindset for C programmers

#37

Wait until they learn that machine code is not exactly how the computer works either. The hardware is doing things to your code you might not expect.

It's turtles all the way down.

We tend of think of everything as an ideal model in a vacuum, forgetting that in real life that the implementation details are often gory with caches and microcode and fault tolerance and all sorts of hidden details put in there to make things easier to work with or faster.

Re: “C is how the computer works” is a dangerous mindset for C programmers

#38
post #6

Actually I look forward for enough momentum to be created in the community, to allow new C standards to change the way undefined behaviors are conceived, and make them as specified as possible, and even when they cannot in reasonable unique ways, to provide reference possible behaviors to select in order to have the least unexpected outcome for the programmer. Especially now that low level programming is abstracting…

It would also be nice if Rust had a specification. Without a spec it's impossible to build a correct alternative Rust implementation.

Re: “C is how the computer works” is a dangerous mindset for C programmers

#39
post #10

C has never been "how the computer works", its abstract model is way too… well, abstract. But there is an interesting catch to it: because C is so important, and programmers at large know so little "real C", vendors do their damndest to make it work for them. A well-known microcontroller forum in Germany is constantly pushing that you need to make your code safe in the case of concurrent access to a variable by a mai…

"Concurrent access" isn't actually an accurate description of what's going on. Microcontrollers are generally single-core, single-threaded devices. The most common pipeline goes

main thread -> interrupt processing -> resume main thread.

If you're modifying a variable in the interrupt you should declare it volatile so as to avoid the compiler optimizing it and introducing unexpected behavior. Adding a mutex would just be worthless overhead.

Re: “C is how the computer works” is a dangerous mindset for C programmers

#40
post #10

C has never been "how the computer works", its abstract model is way too… well, abstract. But there is an interesting catch to it: because C is so important, and programmers at large know so little "real C", vendors do their damndest to make it work for them. A well-known microcontroller forum in Germany is constantly pushing that you need to make your code safe in the case of concurrent access to a variable by a mai…

Yes, except it's "less abstract" than any other language in mainstream use...

You're right. But that wasn't my point. My point was that C isn't the close-to-the-machine language that many programmers think it is.

That other languages don't qualify, either, is beside the point. Ruby or Java aren't mistaken to be close-to-metal.

Point in case: you don't even see anything about Harvard vs. von Neumann architecture in portable C sources. Not to speak of micro code or anything like that.

Post reply on HN