I was part of a team at a job about 20 years ago that ported an existing C codebase over to (then new) Java. Once we got everything working, a co-worker who was very familiar with the old C codebase remarked that with C it took a lot longer to get things working the first time, but once they were working, they stayed working whereas with Java you could get things working pretty quick, but you'd start to see problems…
Author here. This is my experience, though I started in Java and transitioned to C. My C code also does not need to be updated for language changes and such.
Am I a Good C Programmer?
21–30 of 39 posts
Re: Am I a Good C Programmer?
#22Earlier quoted context omitted.
Author here. This is my experience, though I started in Java and transitioned to C. My C code also does not need to be updated for language changes and such.
How do you feel about Go if you've ever worked with it? It seems like it was intended to solve exactly those types of pain points associated with maintaining Java programs
Re: Am I a Good C Programmer?
#23This is the usual argument, "I am a good careful driver, only the other ones do mistakes, so we don't need seat belts".
Author here. I think you need to read to the end of the post. And then read the one it links to because that one says that I will rewrite all of my new project in a memory-safe language. (bc, unfortunately, needs to stay in C because it needs to have zero dependencies.) I'm not making the argument that C is good, or that I am good at C. I'm comparing myself against the average.
Couldn't you write it in Golang? That's also popular for creating standalone executables (ignoring the dynamically linked libc when necessary).
I'm not saying you're obligated to switch. I just assume you wrote bc in C because you find it fun, based on your "Why I write C when I care about memory safety" post.
Re: Am I a Good C Programmer?
#24Earlier quoted context omitted.
Author here. I think you need to read to the end of the post. And then read the one it links to because that one says that I will rewrite all of my new project in a memory-safe language. (bc, unfortunately, needs to stay in C because it needs to have zero dependencies.) I'm not making the argument that C is good, or that I am good at C. I'm comparing myself against the average.
> (bc, unfortunately, needs to stay in C because it needs to have zero dependencies.) Couldn't you write it in Golang? That's also popular for creating standalone executables (ignoring the dynamically linked libc when necessary). I'm not saying you're obligated to switch. I just assume you wrote bc in C because you find it fun, based on your "Why I write C when I care about memory safety" post.
And that was part of my original requirements because I knew that fact at the time I started.
Re: Am I a Good C Programmer?
#25Earlier quoted context omitted.
> (bc, unfortunately, needs to stay in C because it needs to have zero dependencies.) Couldn't you write it in Golang? That's also popular for creating standalone executables (ignoring the dynamically linked libc when necessary). I'm not saying you're obligated to switch. I just assume you wrote bc in C because you find it fun, based on your "Why I write C when I care about memory safety" post.
Unfortunately not, because bc is used to build the Linux kernel, and requiring Go to build the Linux kernel is not good. And that was part of my original requirements because I knew that fact at the time I started.
Re: Am I a Good C Programmer?
#26Earlier quoted context omitted.
Unfortunately not, because bc is used to build the Linux kernel, and requiring Go to build the Linux kernel is not good. And that was part of my original requirements because I knew that fact at the time I started.
I see. I didn't realize that's what you meant by dependency-free. There's still a dependency on there being a C compiler, though.
Edit: In fact, there's really a dependency on POSIX sh and various standard POSIX utilities, but Linux also requires those to build, so those are also "free."
Re: Am I a Good C Programmer?
#27Earlier quoted context omitted.
I think comparing an activity that can result in loss of life to one that doesn't is probably on the dishonest side.
Hospitals in at least 4 states diverting patients from emergency rooms after ransomware attack - https://www.usatoday.com/story/news/nation/2023/11/28/ardent... Moreover, it is untenable to maintain a small island of "secure software" for "important things" in a vast ocean of careless and vulnerable code. Inevitably, the island gets infected, and not even air-gaps can save it, as stuxnet showed.
Why is it inevitable? As long as it doesn't connect to other software (via internet or other means), isn't it possible to formally verify one critical software component, e.g. in pacemakers?
I'm not saying that C would necessarily be the best choice for formally verifying it, though.
Re: Am I a Good C Programmer?
#28This and the Curl article make me wonder what factors impact the proportion of security bugs which are memory safety bugs. The most obvious variable is codebase size - Microsoft/Chromium both are huge codebases, with multiple millions (billions?) of lines of code each. Curl appears to clock in closer to 100k, and Daniel states "51% (22 of 43) of the issues rated high or critical was due to C mistakes." bc appears to have ~20k lines of code, and this article gives C bug rate closer to 10%. Feature set/attack surface area feels like another important variable, though I'm sure there are arguments for others as well.
I'd be nice if we had more directly comparable numbers as well. The denominator for Microsoft's 70% number is "number of CVEs". The denominator for Chromium's number is "high severity security bugs". Curl's 51% number uses a similar metric, and I think the denominator for bc's ~10% number is just "bugs" (though to be fair, OP does discuss this in the post).
All that being said, I still think the data point introduced by this article is better to have than not.
Re: Am I a Good C Programmer?
#29This is an interesting article! I think more of this kind of bug-type/origin-breakdown is a good thing to have. This and the Curl article make me wonder what factors impact the proportion of security bugs which are memory safety bugs. The most obvious variable is codebase size - Microsoft/Chromium both are huge codebases, with multiple millions (billions?) of lines of code each. Curl appears to clock in closer to 100…
Thank you. :)
One thing I am going to do in my new project is catalog all bugs fixed after first release with the following data points:
* Is it a C bug?
* Is it in a stable module of the monorepo? (I will mark things stable after they have been tested.)
* Is the bug in a release, even if it's in an unstable module?
* Is it a build bug?
* Is it a test bug?
* Etc.
I'll keep the catalog in a human- and machine-readable format. This should provide a good set of data.
I would be thrilled if people downloaded my code for human study, analysis, and code archeology.
Re: Am I a Good C Programmer?
#30Earlier quoted context omitted.
Author here. This is my experience, though I started in Java and transitioned to C. My C code also does not need to be updated for language changes and such.
How do you feel about Go if you've ever worked with it? It seems like it was intended to solve exactly those types of pain points associated with maintaining Java programs