- From what I can see in the codegen, defer is not implemented "properly": the deferred statements are only executed when the block exits normally; leaving the block via "return", "break", "continue" (including their labelled variants! those interact subtly with outer defers), or "goto" skips them entirely. Which, arguably, should not happen:
var f = fopen("file.txt", "r");
defer fclose(f);
if fread(&ch, 1, 1, f) <= 0 { return -1; }
return 0;
would not close file if it was empty. In fact, I am not sure how it works even for normal "return 0": it looks like the deferred statements are emitted after the "return", textually, so they only properly work in void-returning function and internal blocks.
by Lucasoato
7 subcomments
- > Mutability
> By default, variables are mutable. You can enable Immutable by Default mode using a directive.
> //> immutable-by-default
> var x = 10;
> // x = 20; // Error: x is immutable
> var mut y = 10;
> y = 20; // OK
Wait, but this means that if I’m reading somebody’s code, I won’t know if variables are mutable or not unless I read the whole file looking for such directive. Imagine if someone even defined custom directives, that doesn’t make it readable.
by seabrookmx
2 subcomments
- It's odd that the async/await syntax _exclusively_ uses threads under the hood. I guess it makes for a straightforward implementation, but in every language I've seen the point of async/await is to use an event loop/cooperative multitasking.
by giancarlostoro
4 subcomments
- Syntax aside, how does this compare to Nim? Nim does similar, I think Crystal does as well? Not entirely sure about Crystal tbh. I guess Nim and Vala, since I believe both transpile to C, so you really get "like C" output from both.
- An interesting bit to me is that it compiles to (apparently) readable C, I'm not sure how one would use that to their advantage
I am not too familiar with C - is the idea that it's easier to incrementally have some parts of your codebase in this language, with other parts being in regular C?
- Initial commit was 24h ago, 363 stars, 20 forks already. Man, this goes fast.
by forgotpwd16
1 subcomments
- Basically C2/C3 but Rust influenced. Missed chance to call it C4.
- So, the point of this language is to be able to write code with high productivity, but with the benefit of compiling it to a low level language? Overall it seems like the language repeats what ZIG does, including the C ABI support, manual memory management with additional ergonomics, comptime feature. The biggest difference that comes to mind quickly is that the creator of Zen-C states that it can allow for the productivity of a high level language.
- > String Interpolation (F-strings)
This is so nice. It's crazy how other low-level langs don't have it.
I know Dlang and Rust have it. Maybe Swift too?
The way Dlang does it is nice because you can do a lot of stuff with them at compile time.
- Very similar to any other C-like languages compiling to C (like nim, V, and many smaller hobbyist ones), but I love the keyword "embed". It looks like unlimited potential for fast debbuging, and testing the code without writing boilerplate to read the file and so on.
by saidnooneever
1 subcomments
- i really like this project. fot me its the next level to your own custom C lib.
first your write 'tutorial C'. then after enough segfaults and double frees you start every project with a custom allocator because you've become obsessed with not having that again..., then you implement a library with a custom more generic one as you learn how to implement them, and add primitives you commonly build that lean on that allocator, it will have your refcouters, maybe ctors, dtors etc etc.. (this atleast is my learning path i guess? still have a loooong way to go as always!)
i dont see myself going for a language like this, but i think its inspirational to see where your code can evolve to with enough experience and care
by stevefolta
1 subcomments
- Nice! Compiles in 2s on my unexceptional hardware. But it lacks my other main desiderata in a new language: string interpolation and kebab-case.
- Impressive repos. I've been toying with the ideas myself but it's hard to stay on track with this sort of extremely demanding task. I am however not exporting to C but to low level jit.
A lot of the ideas in there are worth being inspired by.
- That's something I used to try to write, but failed due to complexity. A meta-preprocessor for C to make it a little bit more bearable...
KUDOS
- I wonder how this compares to the Beef programming language.
https://www.beeflang.org/
The Beef programming language was used to write Penny's Big Breakaway.
- The author includes some easter-eggs (printing random facts about Zen and various C constructs) which trigger randomly -- check out the file src/zen/zen_facts.c in the repository...
by alfonsodev
0 subcomment
- Is this the Typescript of C ?
- This feels like a mix of "Cex.C" and "dasae-headers" projects I've seen somewhere before - maybe it's just the Rust and Zig trend.
- Constant hash seed? Never a good idea (std/core.zc)
by Archit3ch
1 subcomments
- Answering the title, why not Julia?
- That's a very nice project.
List of remarks:
> var ints: int[5] = {1, 2, 3, 4, 5};
> var zeros: [int; 5]; // Zero-initialized
The zero initialized array is not intuitive IMO.
> // Bitfields
If it's deterministically packed.
> Tagged unions
Same, is the memory layout deterministic (and optimized)?
> 2 | 3 => print("Two or Three")
Any reason not to use "2 || 3"?
> Traits
What if I want to remove or override the "trait Drawing for Circle" because the original implementation doesn't fit my constraints?
As long as traits are not required to be in a totally different module than the struct I will likely never welcome them in a programming language.
- What about "Cex.C" and "dasae-headers"? they are integrated directly into the C ecosystem
- The tagline also applies to C :-)
- The whole language examples seem pretty rational, and I'm especially pleased / shocked by the `loop / repeat 5` examples. I love the idea of having syntax support for "maximum number of iterations", eg:
repeat 3 {
try { curl(...) && break }
except { continue }
}
...obviously not trying to start any holy wars around exceptions (which don't seem supported) or exponential backoff (or whatever), but I guess I'm kindof shocked that I haven't seen any other languages support what seems like an obvious syntax feature.I guess you could easily emulate it with `for x in range(3): ...break`, but `repeat 3: ...break` feels a bit more like that `print("-"*80)` feature but for loops.
- What's the performance hit?
by alexpadula
0 subcomment
- 18 commits! I hope you keep up with the project, it’s really cool, great work.
- Example at the top of the readme!
by Panzerschrek
0 subcomment
- Is it memory safe?
by RockieYang
0 subcomment
- nice to see it closure support.
- Am I the only one who saw this syntax and immediately though "Man, this looks almost identical to Rust with a few slight variations"?
by sebastianconcpt
0 subcomment
- But at that point why not Rust then?
by Panzerschrek
0 subcomment
- Yet another overly-hyped language with no practical benefits. Is it just another one better C?
by GrowingSideways
4 subcomments
- Why not compile to rust or assembly? C seems like an odd choice.
In fact why not simply write rust to begin with?