HNHacker News
TopNewBestAskShowJobs

lerno

1,425 karma · joined April 1, 2014

submissionscomments
lerno··on Show HN: The C3 programming language (C alternative language)
Just to be clear, I don't mean the description of Zig to put down the language or the community. It's the best I can do to describe the difference between Zig on one hand and Odin/C3 on the other.

A more concrete example that might explain it better is looking at Advent of Code solutions.

One thing that struck me was that doing typical tasks for parsing would be 2-3 functions stringed together in a smart way in the Zig solutions, whereas in Odin and C3 it was achieved by having a single standard library function that did these steps.

From what I understand, there is a pushback against creating convenience functions in the Zig standard library, if the same thing can be achieved by stacking together a few functions.

My understanding is that doing these smart things with the Zig library with the existing functionality of considered a cool way to leverage existing code.

In C3, and I feel Odin as well, the lack of such a convenience function would be considered an omission to patch, and that having to stack things together should be reserved for specialized solutions, rather than having to stack things together for everyday tasks.

Thus in C3 and Odin, it is okay to trade detailed explicitness for convenience, whereas this is a no-no in Zig.

But what this means is that Zig users tend to celebrate and focus on smart and clever code, whereas this is a complete non-goal in C3 and Odin.

I could probably have formulated this better before.

lerno··on Show HN: The C3 programming language (C alternative language)
If you pass them as parameters, then there are in/out/inout annotations to limit usage. But other than that, there isn't anything.
lerno··on Show HN: The C3 programming language (C alternative language)
For what it's worth, I found the Zig community on the biggest Zig discord very nice and welcoming. But that said, there is a lot of "you have to understand Zig" sentiment. Also, there is a lot of "I discovered Zig and it's finally showing me how to program" echoed as well.

I don't find this an unfair judgment but rather an observation.

I think this naturally arises from the language claiming to be "a programming language designed for robustness, optimality, and clarity" (See for instance https://www.recurse.com/events/localhost-andrew-kelley)

If you feel that this is an optimal programming language that gives more robustness and clarity than other languages, then it's natural to be preachy about it.

This is similar to Rust being sold as safe language, where similarly the proponents of Rust feel that the advantages of Rust need to be spread.

As a contrast, Odin focuses on "joy of programming" as its main goal, and the author does not make any claims of the language having killer features to choose it over something else.

However, it seems to be successful in that new users tend to remark how pleasant and fun it is to program in the language.

lerno··on Show HN: The C3 programming language (C alternative language)
Did you see this? https://c3-lang.org/language-common/cinterop/
lerno··on Show HN: The C3 programming language (C alternative language)
I wrote a short blogpost about this before, trying to answer the question: https://c3.handmade.network/blog/p/8886-why_does_c3_use_%252...
lerno··on Show HN: The C3 programming language (C alternative language)
As the author, let me add something beyond the comparison. Zig and Odin are very different languages, Odin is – as its slogan goes - "for the Joy of Programming". Zig on the other hand doesn't feel that this is a goal. From what I can tell Zig fans like to wrestle with the features of Zig to figure out how to fit their solutions within the constraints of the language. A mental challenge, similar to that of fighting the borrow checker in Rust. People who "figured out" Zig tend to be fiercely loyal to the language in a similar way as Rust evangelists to Rust.

C3 has a lot in common with Odin, but very little in common with Zig.

C3 has a slightly different feature set than Odin (e.g. more compile time execution, has methods, contracts, but doesn't have Odin's matrix programming and more extensive runtime reflection), but the goals aligns strongly with Odin's.

If you prefer C syntax and semantics you might like C3 better, but Odin is a fine language too.

lerno··on Show HN: The C3 programming language (C alternative language)
`::` simplifies the module vs identifier resolution.

In C3 there is something called "path shortening", allowing you to use `foo::bar()` in place of something like `std::baz::foo::bar()`. To do something similar with `.` is problematic, because you don't know where the path ends. Is `foo.baz.bar()` referring to `foo::baz::bar()` or `foo::baz.bar()` or `foo.baz.bar()`?

lerno··on C3: Reading and Writing Files
The other articles on C3 can found here: https://ebn.codeberg.page/programming/c3/
lerno··on Tilde, My LLVM Alternative
1. C is universal, any other language is a dependency.

2. If you're using something like C# or Kotlin or whatever, then you're not serious about compilation speed.

3. You will need to provide a C API anyway.

lerno··on Tilde, My LLVM Alternative
No, just no
lerno··on Tilde, My LLVM Alternative
The QBE author has said that good compilation speed was not a design goal. It also outputs asm which then has to be run through GCC or Clang, which nullifies any benefit of being a standalone backend.
lerno··on C3 (a C-like programming language) hits 0.6.6
There isn't anything official. Tonis maintains an "Awesome C3" repo on GitHub: https://github.com/tonis2/Awesome.c3 (curation is all done by Tonis, I don't have any say what goes into it).

Share it on the C3 discourse: https://c3lang.discourse.group or the C3 discord (but I think you already did that?)

Other than that... r/Programming, r/C3Lang and r/ProgrammingLanguages might be considered.

lerno··on C3 (a C-like programming language) hits 0.6.6
Feel free to post any questions about C3 and compiler dev in the comments.
lerno··on Zig's comptime is bonkers good
I find that the hard part with designing macros and other metaprogramming constructs that run at compile time is not adding POWER - that part is easy, but to make it readable and easy to understand.

If a reader of the code needs to stop to work out the code then that is a weakness, not a strength - as such a pause in code reading affects everything from refactoring to spotting bugs.

In Zig, compile time code looks like runtime code and you cannot easily know which is which without looking up the definition of the variables.

Turning some statements into compile time, like for, requires ”inline” while some, like if, always folds at compile time if it is constant resolved, skipping even semantic checking of the ”dead” branch.

Grasping this at a glance is very challenging.

There is also the issue of generating types - and not just values - at compile time.

This means that a tool refactoring a compile time defined struct member must know how that struct member was created - which may be through arbitrary code execution.

All of this, and including ”build.zig”- the build tool describing how to compile a project using code invocations, makes it extremely challenging for an IDE to reason about code and provide meaningful analysis and refactoring tools.

Which also in the end may affect overall code quality.

So it’s a trade-off. For a contrast, look at C3 which has a comparable amount of compile time but tries to be IDE friendly.

lerno··on Understanding the Odin Programming Language
Some people love this, some think it’s a necessary sacrifice - a rite of passage to endure in order to produce ”optimal” software.

Others try Odin or C3 instead.

lerno··on Tsoding livestreams trying out C3 (programming language) [video]
`goto` is trivial to implement. `goto` doing the right thing jumping over `defer` and implicitly unwrapping optionals (flow-typing) is less nice as you suddenly need to track much more things in the front end.

And you might say "so what, the compiler can be complicated, just make the language easy to use". However, one design constraint is to not make the language hard to reimplement.

And you might not agree with that constraint, but some people feel that this is indeed important. Important enough to not include `goto` as long as the use cases of `goto` are all covered.

lerno··on V Language Review (2023)
Then again, out of the C alternative languages Zig, Odin and C3 - Zig’s always been the one with the most open bugs despite (or due to?) having by far the most amount of people working on it.

Ironic now when the compiler is written in Zig considering how Zig is advertising itself as being better at stability and reliability than C/C++ (the C3 compiler is written in C and Odin’s compiler is a C-like C++)

lerno··on Polymorphic Types in C [pdf]
The `any*` fat pointer in C3 is a version of this: https://c3-lang.org/anyinterfaces/ Once this is available the step to embedding some runtime type information isn't far.
lerno··on Odin Programming Language
If you aren’t looking for languages that have more fancy memory management things (ref counting, borrowing or similar) then the active ones I know of are in alphabetical order: C3, Hare, Jai (might be slightly more of a C++ alternative), Odin and Zig.

Additionally: Hare stated Win and Mac will be unsupported. Jai is still closed source.

lerno··on Odin Programming Language
Such binaries will not be able to use anything but the special C-compatible types and calls, which is quite the limitation. Image if C++ static libraries could only use C compatible POD structs and none of the C++ parameter types for example.
lerno··on Odin Programming Language
I would argue that Zig’s inability to produce static or dynamic libraries that use Zig features in its API is a much bigger problem that Odin’s lack of a package manager.

Neither Odin nor C3 has any problems with this, and it simply follows from Zig’s semantics that it is rendered impossible.

So will Zig semantics change (which would be a big change indeed), or will Zig precompiles libraries always be forced to go by way of special C-compatible calls and types?

Before I’d declare Zig the winner due to a package manager I’d be sure to figure that one out.

lerno··on Show HN: The C3 programming language reaches feature-stabiliy
Well, `Stack.push()` is because it's a method. But ok, why `fn void push() { ... }`? It's actually a long story.

Originally C3 was merely an extension of C2 - which was largely a streamlined C syntax + modules + struct methods. BUT C2 introduced `func` as a function prefix, plus `type Foo struct { ... }` for type declarations to simplify parsing.

So C3 inherited that, but scaled back on the divergence from C, making struct declarations the more familiar `struct Foo { ... }`. The `func` felt too heavy, so it was later reduced to `fn`.

But couldn't that "fn" also be removed? It seemed as if the grammar would allow that while keeping the grammar simple.

However, there were arguments against:

(1) `fn` was also used as a keyword for defining lambdas and function pointers in a straightforward way.

(2) it is symmetric with macro definition: `macro int foo(x) { ... }` and `fn int foo(x) { ... }`

(3) it makes it trivial to search for functions using regex or even plain text search.

While some people wanted it removed, there were a lot more who argued for keeping it esp for that last reason.

I don't really have a personal preference, but it is helpful to keep some additional simplification to the grammar to allow further modifications or additions.

lerno··on Show HN: The C3 programming language reaches feature-stabiliy
Well, I tried to design languages years ago (10+ years ago). They never amounted to anything or even got further than writing a lexer. C3 wouldn't have happened if I didn't have the design of C2 (and of course the C language) to lean on.
lerno··on A decade of developing a programming language
Sigh. Please don’t refer to the rather exceptional nature of Zig’s self hosting. There has been an insane amount of work put into the Zig compiler by various contributors. Probably easily eclipsing the effort to write two separate compilers. The whole WASM deal comes AFTER they essentially built the compiler both in C++ and Zig to reduce bootstrapping steps. That just addresses the bootstrapping cost and not the fact that you have to build the compiler at least twice - and if you do it before 1.0 - more than twice. Cargoculting Zig’s development isn’t going to give you Zig’s success. Zig is successful because of Andrew presenting a vision of a language that lots of people was attracted to, and then cultivating the community well. It’s a well known fact in the community that the first C++ compiler had to go because it wasn’t well written, not because self hosting is great.
lerno··on A decade of developing a programming language
I’ve written about this at some length, but long story short: type modeling and semantic checking is intimately connected to the language semantics, so aside from very simple “look at the properties of the underlying nodes, derive properties of the current node”, it is hard to present any generic approach. In fact, there are many possible way to approach modeling types even with the exact same semantics, leading to different trade offs (just compare different C compilers and you’ll see!).

So this is actually harder to do that it might seem. The best advice I have is to contribute to a compiler or two and understand their semantic checking model.

lerno··on String theory lied to us and now science communication is hard [video]
I was originally pursuing a career in theoretical physics. My master thesis was going to be a literature study on string theory.

The more I read, the more I went “what the heck, this theory can’t possibly be true, it’s so ad hoc with rules made up just to make it pass tests that otherwise would prove it conclusively wrong”

It made me disillusioned and I eventually ended up working as a developer instead.

I guess my instincts were right, because there has been extremely little real progress the last 25(!) years in the field…..

lerno··on Favorite Compiler and Interpreter Resources
”When you can”, is nothing I disagree with, but also bad advice in that it doesn’t give any criteria.

For example: if you are writing the parser for a compiler you will spend years on, then a handwritten parser is great! You can tweak error handling easily and do all sorts of things in an easy to read and understand manner.

If you are writing a tool that will take some code and transform or analyse it in some way which isn’t a full-blown compiler, then a parser generator is nice to focus on the actual meat of the problem.

lerno··on Problems of C, and how Zig addresses them
What do you think about C3 then? https://c3-lang.org
lerno··on Problems of C, and how Zig addresses them
This isn't about Zig, but I found that I prefer something similar to concepts over traits/interfaces, as the former are somewhat limited as to what they express.

    /**
     * @checked x & 1 "The input parameter must allow bit operations"
     */
    macro bool is_power_of_2(x)
    {
      return x != 0 && (x & (x - 1)) == 0;
    }
In the example above (disregard the fact that it's placed in the doc comments) we'd get an error if `x & 1` is invalid (doesn't pass semantic checking). This is the simplest possible example. Basically if you pass in a float or a struct you would then get "The input parameter must allow bit operations" rather than a dump of errors from the macro body.

We can imagine other constraints, such as checking the value (if constant) to conform with valid ranges and so on.

This is more of a "contract" style constraint that can be placed directly at the call location, rather than pushing down the check further down into macro body, for example something like this:

    macro bool is_power_of_2(x)
    {
      $assert($checks(x & 1), "The input parameter must allow bit operations");
      return x != 0 && (x & (x - 1)) == 0;
    }
In this example the error would be localized to the macro, which perhaps isn't what we want, even if the compiler is kind enough to tell us where the macro was included.
lerno··on Zig: Great Design for Great Optimizations
As a counterpoint, see this blog post on why wrapping-overflow-is-UB is bad for safety and correctness: https://c3.handmade.network/blog/p/7640-on_arithmetics_and_o...

The gist of it is that (a + b) - c becomes different from a + (b - c) and (a - c) + b.

While Rust picks a “fast” default that ensures non-trapping code is safe in this regard.

Zig on the other hand would make incorrect ordering UB which might not be immediately obviously wrong - it completely depends on the optimizations run, something which runs completely counter to notions of correctness.

← PreviousPage 8 of 13Next →