Live data from Hacker News

Learning C3

alloc.dev

81–90 of 163 posts

Re: Learning C3

#82

This looks promising, but I wonder what advantages it has over Rust. Community support is very important for a programming language, and given that this is the first time I am hearing about this project, it still has some way to go. Edit: ABI compatibility & two way interop with C seems to be a pretty big selling point!

Community support in C3 is massive, as you can use C libraries directly, it might parallel or exceed Rust on that metric, and the barrier to adding native C3 wrappers or versions is significantly lower too. Rust is solving a different problem, that of safety over all else. C3 on the other hand is more akin to developer experience above all else. If you find something that should be easier to do in C3, that's a bug.

Is massive really the right word to use here? I’ve never heard of C3, meanwhile most big tech companies are hiring Rust developers of some sort.

Re: Learning C3

#83

There was already a better evolution of C called clay. It had templates and ownership. It was C compatible and could be used as a substitute. https://github.com/jckarter/clay/wiki/Clay-for-C---programme...

It might be interesting to note that none of the C alternatives: C3, Zig, Odin, Hare, Jai use ownership nor RAII.

Overloading is also generally missing from today's breed of C alternatives.

There has certainly been many attempts at C alternatives: eC, Cyclone etc etc

Re: Learning C3

#84
post #78

Earlier quoted context omitted.

> The whole point of C is that you know exactly what's going on and it's relatively clear in the code itself. Given the widespread undefined behavior and the ways that compilers aggressively rely on that to reorganize and optimize your code, that hasn't been the case for many many years. Sure, if you're using dmr's compiler on a PDP-11, then C is a pretty transparent layer over assembly, which is itself a fairly thin…

Rescheduling instructions is not relevant, is it? Are there architectures which change the semantics of the instructions by changing execution order?

> Rescheduling instructions is not relevant, is it?

I guess it probably depends on why a user might want to think of C as low level. The user visible semantics shouldn't change, I hope, but the performance might.

Re: Learning C3

#85
Strikes me as so so.

defer is the kind of thing I would mock up in a hurry in my code if a language or framework lacked the proper facilities, but I think you are better served with the with statement in Python or automated resource management in Java.

Similarly I think people should get over Optional and Either and all of that, my experience is that it is a lot of work to use those tools properly. My first experience with C was circa 1985 when I was porting a terminal emulator for CP/M from Byte magazine to OS-9 on the TRS-80 Color Computer and it was pretty traumatic to see how about 10 lines of code on the happy path got bulked up to 50 lines of code that had error handling weaved all around it and through it. When I saw Java in '95 I was so delighted [1] to see a default unhappy path which could be modified with catch {} and fortified with finally {}.

It's cool to think Exceptions aren't cool but the only justification I see for that is that it can be a hassle to populate stack traces for debugging and yeah, back in the 1990s, Exceptions were one of the many things in the C++ spec that didn't actually work. Sure there are difficult problems with error handling such as errors don't respect your ideas of encapsulation [2] but those are rarely addressed by languages and frameworks even though they could be

https://gen5.info/q/2008/08/27/what-do-you-do-when-youve-cau...

putting in ? or Optional and Either though are just moving the deck chairs on the Titanic around.

[1] I know I'm weird. I squee when things are orderly, more people seem to squee when they see that Docker lets them run 5 versions of libc and 7 versions of Java and 15 versions of some library.

[2] Are places where the "desert of the real" intrudes on "the way things are spozed to be"

Re: Learning C3

#86

Earlier quoted context omitted.

Just curious - in what situations would you want to use `foreach` (with the intent to iterate over a sequence), but use `i += 2` instead of `i++`? I can only think of a situation where I want to group elements by pairs, but then I'm explicitly not doing a "for each", and would prefer to explicitly use a regular `for`.

Vectorization unrolling?

In that case I advice using actual C3 vectors. They are a built in type that will use simd (or similar) under the hood if the compilation target supports it.

Re: Learning C3

#89
post #18

This looks promising, but I wonder what advantages it has over Rust. Community support is very important for a programming language, and given that this is the first time I am hearing about this project, it still has some way to go. Edit: ABI compatibility & two way interop with C seems to be a pretty big selling point!

I want to second this comment. The comparison shouldn't be with C, it should be with C++, Rust, or Zig. The place to go is actually the C3 comparison page: https://c3-lang.org/faq/compare-languages/ There you can see that there are very few items "in C3 but not Rust", for example. Mainly "it's a familiar C-like language". I am also suspicious of the macro system. I'd like more of an explanation of how it works. Espec…

The comparison is with C because C3 wants to be “C, but better”. Rust doesn’t have that design goal, it doesn’t look like an incremental update to C and it’s more akin to C++ in philosophy (with an ML-inspired syntax)

There is a space for a C alternative, and Rust ain’t it.

Re: Learning C3

#90

Strikes me as so so. defer is the kind of thing I would mock up in a hurry in my code if a language or framework lacked the proper facilities, but I think you are better served with the with statement in Python or automated resource management in Java. Similarly I think people should get over Optional and Either and all of that, my experience is that it is a lot of work to use those tools properly. My first experienc…

C3 error handling is fairly novel though. It tries to find a sweet spot between composability, explicitness and C compatibility.

The try-catch has nice composability:

    try {
        int x = foo_may_fail();
        int y = bar_may_fail(x);
    } catch (... ) {
        ...
    }
Regular Result types need to use flatmap for this, and of course error codes or multiple returns also struggle with this. With C3:

    int? x = foo_may_fail();
    int? y = bar_may_fail(x);
    if (catch err = y) {
       ...
       return;
    }
    // y is implicitly unwrapped to "int" here
This is not to say it would satisfy you. But just to illustrate that it's a novel approach that goes beyond Optional and Either and has a lot in common with try-catch.
Post reply on HN