News for hackers. Stuff that matters.
Re:The two types of C programmers (a provocative thesis) by gavinhoward on Sunday April 23, 2023 @05:48PM (#35680987)
I'm the former kind: I choose C because I like it above all else. [1]

That said, like the author, I'm trying to find an alternative. Well, more like I'm building my alternative because I hate Go. And Rust. And anything else.

I don't know why C fits my brain, but it does. I think it's because my brain is low-level; I like messing with assembler when I get the chance to optimize.

[1]: https://gavinhoward.com/2023/02/why-i-use-c-when-i-believe-i...

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.
Re:The two types of C programmers (a provocative thesis) by pier25 on Sunday April 23, 2023 @06:17PM (#35681229)
What type of projects do you work on?
Re:The two types of C programmers (a provocative thesis) by gavinhoward on Sunday April 23, 2023 @06:26PM (#35681306)
A compiler/interpreter, build system, init system, version control system, among others.

It's all in a monorepo that has my "libc".

Re:The two types of C programmers (a provocative thesis) by tacitusarc on Sunday April 23, 2023 @05:49PM (#35681000)
How do you feel about zig?
Re:The two types of C programmers (a provocative thesis) by gavinhoward on Sunday April 23, 2023 @05:54PM (#35681058)
I hate it.
Re:The two types of C programmers (a provocative thesis) by throwawaymaths on Monday April 24, 2023 @12:14AM (#35683589)
Care to explain why?
Re:The two types of C programmers (a provocative thesis) by gavinhoward on Monday April 24, 2023 @12:24AM (#35683634)
Several things, but I'll name two.

comptime just doesn't fit my brain well.

Async Zig gives me a headache. [1]

[1]: https://gavinhoward.com/2022/04/i-believe-zig-has-function-c...

Re:The two types of C programmers (a provocative thesis) by throwawaymaths on Monday April 24, 2023 @12:34AM (#35683692)
Got it. Thank you for your perspective. I can appreciate that comptime is tricky. Indeed, async zig is hard and annoying (but you're wrong about the function coloring... Here is someone's project where they call an async function alternately from a sync or async context with zero lines of code:

https://youtu.be/lDfjdGva3NE?t=1999

Yielding is async and threaded is sync)

Re:The two types of C programmers (a provocative thesis) by gavinhoward on Monday April 24, 2023 @12:51AM (#35683782)
I'm not wrong.

He claims that you can call functions fine in either mode if the functions are known at compile time. I never disputed that.

If he tried to call those functions with possibly unknowable function pointers at runtime, I doubt it would work as well.

There is a difference between compile time and runtime. At compile time, Zig can transform known functions to async to allow turn to call async functions. At runtime, that's not possible.

The 75 examples in my post show that.

Re:The two types of C programmers (a provocative thesis) by throwawaymaths on Monday April 24, 2023 @11:03AM (#35688500)
sure, a sync function and an async function get compiled to two different things under the hood, but IMO colored/uncolored is about ux, not what happens under the hood. In go, or erlang, which don't have async coloring, you don't actually care what the system does under the hood. More generically, if a system takes a private function and can choose to inline it, you probably wouldn't moan that under the hood it's doing something different and thus "inlining is function coloring". Maybe you would.

I guess the question hinges on "just how hard" counts as "hard" for #3. I would say "not having to write an event loop because the compiler generates another version for the sync-calling-async with a single keyword" case counts as "not hard", but this is a matter of perspective. The language design still has rough edges, and you certainly ran into them, but with the function pointer stuff, I think you were really trying hard to break it to prove a specific point (this is a good thing! it will allow the team to fix it). To that point, they simply hadn't run into the specific runtime/comptime thing that you ran into, but it's pretty easy to see how exactly what you ran into can be addressed and fixed at comptime, it... just hasn't yet.

Re:The two types of C programmers (a provocative thesis) by gavinhoward on Monday April 24, 2023 @02:36PM (#35691378)
It can't be addressed at compile time. That's the whole point of the uncomputability of the Halting Problem.

The Zig compiler would have to have perfect knowledge of all functions that can be called anywhere. At compile time. Alan Turing proved that this is impossible.

In other words, Zig cannot address it. Ever.

Re:The two types of C programmers (a provocative thesis) by throwawaymaths on Monday April 24, 2023 @07:21PM (#35694581)
Ok? The universe of all code that can be created by the zig compiler is strictly bounded for any given project, the halting problem does not apply. At worst, you can do an exhaustive search. The context that you're running the code in can ultimately be known, and the pointer can be set to the appropriate version based on calling context.
Re:The two types of C programmers (a provocative thesis) by gavinhoward on Monday April 24, 2023 @11:31PM (#35696233)
No, you can't do an exhaustive search.

Say you're a library author. You distribute pre-built library files.

You've already lost because the compiler does not know your clients' code when it compiles your library.

I am not kidding when I say it's provably impossible.

Re:The two types of C programmers (a provocative thesis) by throwawaymaths on Tuesday April 25, 2023 @11:38AM (#35701983)
"pre-built library files" are not a thing in zig right now, unless you use the c abi, which doesn't have async?

Even supposing zig had prebuilding someday, you would probably have to extern it using async directly declared in the callconv (.async is an option in callconv) and so yes, the compiler would know. It's just that currently zig has a lot of "let the compiler figure out".

Re:The two types of C programmers (a provocative thesis) by gavinhoward on Tuesday April 25, 2023 @02:35PM (#35704744)
Wat.

The Zig compiler is finite and deterministic, yes, but that's not the problem.

The problem is that user code is not finite nor deterministic.

Even worse, Zig's compiler may be deterministic and finite, but the language is not, by far. In fact, the language is one of the most infinite languages in existence because just the type system is uncomputable! [1]

(In this context, the word "undecidable" used by that source means "uncomputable".)

If the type system is uncomputable, then the type system will never be able to resolve all uses of function pointers everywhere.

The whole point of the Halting Problem is that you could have a finite and deterministic Turing Machine that runs other Turing Machines, and that finite and deterministic Turing Machine could run into situation where it never halts.

I never say this when people ask (because most people don't understand), but the real reason I don't like Zig is because of how infinite the language is, starting with its uncomputable type system.

This makes Zig one of the most unreasonable [2] programming languages in existence.

If you don't believe me, ask the Zig team how they plan to solve this problem. Don't ask them if they plan to solve it; ask them how.

Then if they reply, email me [3] with their proposed solution, and I will destroy it. I will do that no matter how many solutions they come up with because math says I will always win.

But if they say they can't, will you believe them?

[1]: https://3fx.ch/typing-is-hard.html#zig

[2]: https://fsharpforfunandprofit.com/posts/is-your-language-unr...

[3]: https://gavinhoward.com/contact/

Re:The two types of C programmers (a provocative thesis) by kristoff_it on Tuesday April 25, 2023 @04:15PM (#35706114)
> If you don't believe me, ask the Zig team how they plan to solve this problem. Don't ask them if they plan to solve it; ask them how.

The Zig compiler has a counter that describes the maximum allowed amount of branching that the compiler can do while evaluating comptime code. The counter can be manually set to a higher value but all compilations will eventually fail if your comptime logic is too loopy. In practice the guideline is to not overuse comptime and instead create a dedicated build step for things like creating pre-computed value tables.

> Then if they reply, email me [3] with their proposed solution, and I will destroy it. I will do that no matter how many solutions they come up with because math says I will always win.

cringe

Re:The two types of C programmers (a provocative thesis) by gavinhoward on Tuesday April 25, 2023 @06:25PM (#35707565)
> The Zig compiler has a counter that describes the maximum allowed amount of branching that the compiler can do while evaluating comptime code.

Okay, here's a solution. It's already implemented. Nice.

Now let me destroy it.

You said those compilations "fail"; I presume there's an error that kicks in.

In that case, then some valid Zig programs will be rejected, but your type system is now not technically Turing-complete. It's also less powerful; there are going to be things that Zig's type system cannot express.

But wait; that's a user-defined setting? This means that either users will increase that setting when they need to and run into the same problem, or follow your guideline:

> In practice the guideline is to not overuse comptime and instead create a dedicated build step for things like creating pre-computed value tables.

It sounds like a dedicated build step would be the better option than comptime, to be honest.

Also, if you step out to dedicated build steps, then the compiler no longer has complete visibility into that code when analyzing. At that point, the Halting Problem applies again.

Also, what do you do if a user needs to pass a function pointer to a C function? I presume they must use a sync function? If so, that seems like a direct application of the function colors definition; some functions are unusable in certain places. If not, I'd be interested in what Zig does there.

Re:The two types of C programmers (a provocative thesis) by kristoff_it on Wednesday April 26, 2023 @05:32AM (#35711308)
> In that case, then some valid Zig programs will be rejected, but your type system is now not technically Turing-complete. It's also less powerful; there are going to be things that Zig's type system cannot express.

I think you're a bit too high on all this compsci theory stuff.

All computations in all languages (including ones generally considered to be turing complete) fail when you run out of resources like RAM or patience. Zig introduces an artificial quantity that can be used as a machine-independent way to ensure all compilations eventually end in either success or failure. It's like a timeout, but an actual timeout would be inconsistent across different machines (with different performance characteristics).

The actual state of things is much more boring than what your analysis tries to suggest: comptime is used to do some metaprogramming whose practical value is in good part determined by it not being too crazy, so the fact that you can't make a DisprovesCollatzConjecture type is actually fine.

You have found another feature of Zig that's even more mundane than async where you're trying really hard to misunderstand everything to indulge in... "destroying".

I think your own wording betrays the fact that you care about needlessly debating people more than actually understanding the tools in front of you in order to produce better software.

Re:The two types of C programmers (a provocative thesis) by gavinhoward on Wednesday April 26, 2023 @08:42AM (#35712757)
Comptime is too crazy.

I have an acquaintance who was trying to write a Zig compiler. Comptime was his bane.

If you think I care about "needlessly debating people more than actually understanding the tools in front of me," let me dispel that notion.

I was once a fan of Zig.

Yep. I was. I thought it was great and was even going to rewrite all of my monorepo in it.

And then I started studying it in detail, trying to understand it. It took a while, but I came to realize that Zig appears good and has flashy ideas, but that Andrew just didn't understand the consequences of his design decisions.

In other words, I spent time trying to understand Zig before I ever got these opinions.

To go back to the topic, sure the use of this may appear boring, but if tools have a hard time working with Zig code, so will people. That's my problem with it.

You are absolutely right that this is a "boring" part of Zig, but that doesn't mean it's good. It means that that's where complexity hides.

Once I figured that out, I realized that to make better software, it would be better for me to stick with C.

My wording, by the way, comes from a bit of exasperation because to me, it feels like you, Andrew, and the rest of the Zig team are reluctant to accept criticism or that Zig isn't perfect or even the best.

Re:The two types of C programmers (a provocative thesis) by throwawaymaths on Wednesday April 26, 2023 @08:16AM (#35712492)
> then some valid Zig programs will be rejected

A program is defined to be invalid when it runs out of counters. Problem solved.

>Also, if you step out to dedicated build steps, then the compiler no longer has complete visibility into that code when analyzing.

You can't really "generate code" in these dedicated build steps. Kristoff is talking about generating data. you could maybe build an object file, but then it's bound in using c abi, statically, which we've already solved in this conversation.

>Also, what do you do if a user needs to pass a function pointer to a C function? I presume they must use a sync function? If so, that seems like a direct application of the function colors definition;

In the long run for zig, calling out to c abi, much less one which takes a function pointer, much less one which you happen to have as async, is going to be a rare enough operation that I think people aren't clamoring to go and use it, which fails one of the criteria for your function coloring list. Besides, you just quickly wrap it in noasync context and you're done (you can't pass a zig callconv function directly to a c abi callconv site without at least a tiny wrapper anyways).

Re:The two types of C programmers (a provocative thesis) by gavinhoward on Wednesday April 26, 2023 @09:24AM (#35713292)
> A program is defined to be invalid when it runs out of counters. Problem solved.

Except that the counter can be adjusted by users.

> You can't really "generate code" in these dedicated build steps. Kristoff is talking about generating data. you could maybe build an object file, but then it's bound in using c abi, statically, which we've already solved in this conversation.

So any code generated outside has to be sync? That's exactly what I thought.

But even if Zig only allowed people to generate only data, this is a pretty big limitation.

This may not be a problem now, but it does mean that as Zig programs grow, people will run into this problem. I suspect that this means that Zig will struggle more than C to scale, maybe even more than C++ or Rust.

> In the long run for zig, calling out to c abi, much less one which takes a function pointer, much less one which you happen to have as async, is going to be a rare enough operation that I think people aren't clamoring to go and use it

This assumes that people won't want to interface with software that isn't in Zig. This is another way that Zig will struggle to scale.

> Besides, you just quickly wrap it in noasync context and you're done

This sounds exactly like a special calling technique mentioned in the function colors post.

> (you can't pass a zig callconv function directly to a c abi callconv site without at least a tiny wrapper anyways).

And this also sounds exactly like a special calling technique.

Re:The two types of C programmers (a provocative thesis) by throwawaymaths on Wednesday April 26, 2023 @08:08PM (#35721612)
> Except that the counter can be adjusted by users.

So? You've changed the program, and now it's valid. (as my handle suggests) I was a math major: arbitrarily large but finite is a different category than infinite, and that makes all the difference in the world.

> his sounds exactly like a special calling technique mentioned in the function colors post.

No, but the seam between async and sync in most other implementations requires writing an entire event loop. In this case it's often a single keyword, six characters. At worst, you write an extra function header to wrap it.

It's not the extraness that matters, it's the pain of doing so. Hell, even go requires you write "go" in front of your function to run it asynchronously, and I don't think that this counts as "colored functions".

Re:The two types of C programmers (a provocative thesis) by Spex_guy on Tuesday April 25, 2023 @04:31PM (#35706346)
> If the type system is uncomputable, then the type system will never be able to resolve all uses of function pointers everywhere.

Can you elaborate on what you mean here, and the problems this might cause? Do you mean that some function pointers cannot be resolved to concrete functions? Or that the process of evaluating comptime may be infinite? Or some other problem where the compiler can't determine whether a function pointer is needed for a given function?

Re:The two types of C programmers (a provocative thesis) by gavinhoward on Tuesday April 25, 2023 @06:10PM (#35707406)
These are great questions.

All of the above, actually.

Turing-completeness and the uncomputability thereof are widespread, easy to build, hard to keep away, and affects everything that might happen at runtime.

A list of things that can happen is infinite, but that list absolutely includes:

* Whether a particular function pointer resolves to certain functions,

* Whether evaluating the comptime portion of a Zig program will take forever,

* Whether the compiler fails to exclude a particular function from being used as a function pointer at a particular place.

Turing-completeness is a wildly powerful property, but that power is not free; the inability to figure out what might happen in a program is only just the biggest and most apparent cost.

The problems this might cause can be summarized like this: you can never know what a program will do for a given set of inputs until you run the program on those inputs, and even then, you might never know if the program never halts.

Does that make sense?

Re:The two types of C programmers (a provocative thesis) by throwawaymaths on Wednesday April 26, 2023 @08:21AM (#35712535)
> Whether a particular function pointer resolves to certain functions

This is only a turing completeness issue if the list of functions is infinite. It is not, in zig.

Re:The two types of C programmers (a provocative thesis) by gavinhoward on Wednesday April 26, 2023 @09:28AM (#35713333)
You don't need an infinite list of functions to run into the problems with Turing-completeness. You only need effectively infinite behavior, which means all you need is effectively infinite possible inputs.
Re:The two types of C programmers (a provocative thesis) by throwawaymaths on Wednesday April 26, 2023 @08:15PM (#35721656)
this is simply untrue. I'm sorry. I recommend studying math a bit more rigorously before making claims in the future.
Re:The two types of C programmers (a provocative thesis) by GoblinSlayer on Monday April 24, 2023 @12:55PM (#35690149)
>I have special array types that I use instead of straight pointers, and those arrays store their bounds.

You cheat. You don't write C the hard way. But ok, that's an easier way to use C today.

Re:The two types of C programmers (a provocative thesis) by gavinhoward on Monday April 24, 2023 @03:37PM (#35692128)
Okay? I mean, I have the discipline to admit I need to do that and the discipline to actually do it.

I'm okay with cheating if it reduces bugs.