News for hackers. Stuff that matters.
Re:The two types of C programmers (a provocative thesis) by preseinger on Sunday April 23, 2023 @06:09PM (#35681180)
it's not possible for human beings to write correct C code, measured over time

this is not a controversial statement, it's the clear conclusion from any evaluation of available evidence

it's fine that you like messing with assembler, but you can't do that safely -- if the programs you write don't need to be correct then carry on, but if they do need to be correct, then you have a professional obligation to use a higher-level language, with stronger guarantees

edit:

> This brings me to my next reason: I have the discipline to write C at a high level.

factually, you do not. nobody does. you think you do, until you don't. human cognition is insufficient to satisfy this requirement. "discipline" does not fix the problem.

Re:The two types of C programmers (a provocative thesis) by gavinhoward on Sunday April 23, 2023 @06:24PM (#35681289)
> it's not possible for human beings to write correct C code, measured over time

I don't disagree [1], but remember that Rust can be unsafe too. Async is not a panacea, and it's confusing. And the `unsafe` escape hatch is still unsafe.

> you have a professional obligation to use a higher-level language, with stronger guarantees

Oh? So we have professional obligations now? For FOSS? News to me.

I don't get paid for my work. Not yet. So I have no obligation.

And when I do get paid, my code will be in my own safe language.

This accusatory response is exactly the kind of thing that puts a lot of people off Rust.

> factually, you do not. nobody does.

When I say "write C at a high level," I don't mean that I'm perfect. I mean that I write excellent C compared to all C programmers out there.

Engineering is not about perfection; it never was. It's about doing the best we can with the tools that we have.

[1]: https://git.gavinhoward.com/gavin/bc/src/branch/master/MEMOR...

Re:The two types of C programmers (a provocative thesis) by tourist2d on Sunday April 23, 2023 @07:09PM (#35681651)
Ask any experienced C developer and they'd all say "I write excellent C compared to all C programmers out there."
Re:The two types of C programmers (a provocative thesis) by gavinhoward on Sunday April 23, 2023 @07:48PM (#35681951)
That is true. I'm repeating what others have judged and told me.

Of course, feel free to judge for yourself.

Re:The two types of C programmers (a provocative thesis) by amoss on Monday April 24, 2023 @01:01AM (#35683835)
This could be true if you consider survivor bias.
Re:The two types of C programmers (a provocative thesis) by camgunz on Monday April 24, 2023 @09:31AM (#35687414)
I'm an experienced C developer and I wouldn't say this. I'm pretty meticulous, I use as much tooling as I can, and I've still written over/underflows, memory corruption, threading heisenbugs, double frees, NULL derefs, etc. etc. etc. My defect rate has gone way down over the years, but that's probably 50/50 experience vs. an attenuation of my ambitions.

I think the proof is in the pudding here. I can't imagine using a messaging client or an email client written in C, and also there isn't much that is written in C anymore even if I wanted to: you're looking at Swift/Java/Kotlin/TypeScript/JavaScript/C#/Vala/Dart/Rust/Go, and maybe C++.

Is anyone writing production servers in C these days? It feels like they're 100% Go and Rust.

There are notable exceptions, in particular I'm thinking about OpenBSD. I think OS dev is a pretty niche area though, especially when you're talking about OpenBSD's wide platform support, so I think it's more the exception that proves the rule than anything.

Re:The two types of C programmers (a provocative thesis) by jtorsella on Sunday April 23, 2023 @06:19PM (#35681244)
Oh wow, someone should alert the Linux kernel maintainers. Do you want to tell them that it’s impossible to write correct C code? And the rust compiler team, too. After all, if nobody can write safe assembly then whatever they’re doing is either unsafe or magically gets the computer to understand rust directly. Or are they relying on LLVM for their code generation? I forget what language that’s written in, but nothing “unsafe” happens there surely.

All code is machine code at bottom. Including the code that maintains abstractions convincing enough for you to think the “memory-safety” of rust or any other language is a static and guaranteed thing and not something that needs “unsafe” scaffolding to support it.

Re:The two types of C programmers (a provocative thesis) by preseinger on Sunday April 23, 2023 @06:29PM (#35681329)
i'm sure the linux kernel maintainers already know that it's impossible for them to write correct C code, no need to tell them
Re:The two types of C programmers (a provocative thesis) by tialaramex on Sunday April 23, 2023 @08:13PM (#35682126)
The Rust compiler developers are well aware that it's not possible to write 100% correct code at scale, not least for their dependencies, LLVM provides Rust with ICE (cases where your program crashes the compiler) and with soundness holes where the LLVM behaviour is definitely wrong but it's arguably exactly why and so until LLVM developers decide why it's wrong and fix it, Rust has to either work around that or accept sub-par results.

Much of the Rust compiler is written in Rust and so has fewer problems.

Re:The two types of C programmers (a provocative thesis) by pjmlp on Monday April 24, 2023 @04:36AM (#35685056)
Re:The two types of C programmers (a provocative thesis) by jtorsella on Monday April 24, 2023 @06:38AM (#35685834)
If the existence of C cves in the kernel proves that it is impossible to write correct C, then by the same token any cves in any rust code prove the same thing about rust. This is such a lazy way of arguing. Say something about why the tradeoffs favor a more restrictive and less performant language or don’t, but don’t dismiss the work of many thousands of C developers that runs most enterprise systems with a knowing wave of the hand - it’s not serious.
Re:The two types of C programmers (a provocative thesis) by pjmlp on Monday April 24, 2023 @07:12AM (#35686095)
So you want something more serious,

https://msrc.microsoft.com/blog/2019/07/a-proactive-approach...

https://security.apple.com/blog/towards-the-next-generation-...

https://www.chromium.org/Home/chromium-security/memory-safet...

https://security.googleblog.com/2022/08/making-linux-kernel-...

Σ (memory corruption) + Σ (logic errors) ≥ Σ (logic errors)

So by reducing in 70% the costs of fixing the errors caused by those thousands of experts, as validated by the above reports, there is already a considerable reduction in software development expenses.

Lets see how serious those developers get to be around security issues, when liability finally takes off.

Re:The two types of C programmers (a provocative thesis) by jtorsella on Monday April 24, 2023 @07:26AM (#35686232)
I appreciate that you are making an argument and will respond when I get a chance later in the day and after I read a few of the links - I’m familiar with like half of them.
Re:The two types of C programmers (a provocative thesis) by preseinger on Monday April 24, 2023 @08:07AM (#35686606)
it is not anyone's claim that the existence of C cves means it is impossible to write correct C

the point that is being made (obliquely) is that manual memory management is not possible for human beings to do effectively at scale

at scale means across a broad demographic of programmers, working on a broad set of programs

if you wanted performant and portable then C was all you had for a long time, and there is a lot of good software written in C, but that does not mean that it is a good tool in perpetuity

strcpy and pointer arithmetic are basically not possible to get right

we need to move beyond this very low level of abstraction

Re:The two types of C programmers (a provocative thesis) by kps on Sunday April 23, 2023 @06:47PM (#35681478)
> it's not possible for human beings to write correct C code

It's not possible for human beings to write correct code.

The hardest bug I ever found in a C program, one that took cumulative weeks of work until a tractable reproduction was found, came down to a ‘<’ that should have been ‘<=’. No language would have stopped that.

Yes, different languages have different levels of expressiveness, and can preclude or expose different kinds of errors. You'll never have a stray pointer in Python, and you'll never OOM making an accidental copy in C.

Re:The two types of C programmers (a provocative thesis) by preseinger on Sunday April 23, 2023 @07:23PM (#35681769)
obviously yes

yet c code is inarguably more error-prone than basically any other language

Re:The two types of C programmers (a provocative thesis) by lelanthran on Monday April 24, 2023 @03:37AM (#35684710)
Nope. Many errors in JavaScript, python, PHP, etc are caught at compile time in C.

Of course, the errors that do get through might be more severe in C than in python, but not always.

After all, the most expensive and destructive RCE ever was in a piece of Java software.

Re:The two types of C programmers (a provocative thesis) by deterministic on Sunday April 23, 2023 @06:55PM (#35681552)
Not true. Check out CompCert, seL4 etc.
Re:The two types of C programmers (a provocative thesis) by tialaramex on Sunday April 23, 2023 @08:22PM (#35682206)
I assume this was a logic error, that is, the code as written was a valid C program that didn't do what you meant.

In that case this could have been caught with more careful unit tests, which would have exercised the erroneous condition, and potentially with fuzzing to excite corner cases. C is... not great for either of these.

Re:The two types of C programmers (a provocative thesis) by gavinhoward on Sunday April 23, 2023 @08:34PM (#35682293)
I don't know why you say that C is bad for exercising error conditions or fuzzing. In my experience, it's the best at those.
Re:The two types of C programmers (a provocative thesis) by tialaramex on Monday April 24, 2023 @06:21AM (#35685700)
It doesn't come with either capability, so you're adding third party tooling to get these working.
Re:The two types of C programmers (a provocative thesis) by gavinhoward on Monday April 24, 2023 @09:01AM (#35687140)
Well, sure, but that's true of any language.
Re:The two types of C programmers (a provocative thesis) by tialaramex on Monday April 24, 2023 @11:23AM (#35688756)
Nope, when I write tests in my Rust the out of box cargo test will check those tests pass.

If I wrote inline Markdown documentation for part of the Rust code with an example, cargo test will try to build my example, and check it works - not much good having a purported "example" which doesn't even work, is it? And yet many languages don't do this.

Re:The two types of C programmers (a provocative thesis) by gavinhoward on Monday April 24, 2023 @02:41PM (#35691442)
You said fuzzing and exercising error conditions. Rust's tooling does not do that. You need something to generate those tests.

Fuzzing is still not part of the default Rust tooling.

Re:The two types of C programmers (a provocative thesis) by GoblinSlayer on Monday April 24, 2023 @04:13PM (#35692549)
Mere existence of a test runner is infinitesimal compared to your proposed careful testing. Saying this as someone who wrote my own test runner, it's a few lines of code.
Re:The two types of C programmers (a provocative thesis) by deterministic on Sunday April 23, 2023 @06:54PM (#35681536)
And yet C code runs the world. You might be right in theory but in practice C is the most successful programming language in history. At work we routinely deploy million+ lines of C in production running large international airlines and airports. And it works.
Re:The two types of C programmers (a provocative thesis) by preseinger on Sunday April 23, 2023 @07:24PM (#35681786)
that C code is prolific is a historical fact, it does not imply anything about efficacy or soundness

"it works" is factually not true, look at ~any CVE

Re:The two types of C programmers (a provocative thesis) by deterministic on Friday April 28, 2023 @03:22AM (#35738480)
C won against all competitors. That is a historical fact. And C runs the world. From operating systems, to device drivers, avionics, navigation, satellites, embedded systems, emulators for Python, container ship engines, medical instruments, enterprise systems etc. That is also a historical fact. No other languages comes even close. Maybe one day a language will surpass C. But not any time soon.
Re:The two types of C programmers (a provocative thesis) by deterministic on Friday April 28, 2023 @03:47AM (#35738631)
No successful software is bug free. Except for proven correct code like CompCert and seL4 of course.
Re:The two types of C programmers (a provocative thesis) by preseinger on Friday April 28, 2023 @02:24PM (#35745165)
of course, but that's not the point being made here
Re:The two types of C programmers (a provocative thesis) by pjmlp on Monday April 24, 2023 @04:37AM (#35685061)
Historical accident, due to UNIX winning out the server room.

In early 1980's it was only running Bell Lab's world and a couple of universities that got hold of the source tapes.

Re:The two types of C programmers (a provocative thesis) by deterministic on Friday April 28, 2023 @03:16AM (#35738442)
The success of UNIX and C is no accident.
Re:The two types of C programmers (a provocative thesis) by hgs3 on Sunday April 23, 2023 @07:51PM (#35681967)
> it's not possible for human beings to write correct C code, measured over time

I agree that C the programming language does not help you avoid memory errors, however, saying it's impossible is too binary. People do make mistakes, whether it's copy editors missing a typo or professional chefs misremembering whether they stocked an ingredient. Projects written in C need longer periods of code review and testing, but they can be made right. The code that took us to the moon was written in assembly after all.

Re:The two types of C programmers (a provocative thesis) by asveikau on Sunday April 23, 2023 @08:20PM (#35682188)
What you mean to say is you have no shot at correct C, and so the language scares you, and you believe since you can't do it nobody does.

It's true that the community at large writes lots of bugs. But that doesn't mean some people aren't productive with the language and write a relatively low number of bugs. There are some projects with better track records at this than others.

Re:The two types of C programmers (a provocative thesis) by preseinger on Sunday April 23, 2023 @10:21PM (#35682979)
no, that is not what i mean to say

at scale, it is not possible for humans to hand-write C programs that are free of segmentation fault class errors

this is not controversial or in any way arguable

Re:The two types of C programmers (a provocative thesis) by throwawaymaths on Monday April 24, 2023 @12:16AM (#35683596)
Sel4 would like to have a word.

Inb4 you move the goalposts for "at scale". This is an operating system with capability-based access control which is not something that most operating systems even have.

Also the cryptographic constraints are part of the proof system.

Re:The two types of C programmers (a provocative thesis) by int_19h on Tuesday April 25, 2023 @06:04PM (#35707342)
I'm not sure Sel4 can be considered "at scale", given the rather extreme amount of effort that went into it.
Re:The two types of C programmers (a provocative thesis) by throwawaymaths on Wednesday April 26, 2023 @08:17PM (#35721670)
you just moved the goalposts.
Re:The two types of C programmers (a provocative thesis) by asveikau on Monday April 24, 2023 @01:16AM (#35683923)
Your opinion is common here. However, you can't just say your opinion is the consensus and that makes people who have other experiences wrong, end of debate. Popularity doesn't indicate truth. I'm sorry you haven't seen it working well, but there are counterexamples where people are productive with a relatively low number of issues.