Live data from Hacker News

Zen-C: Write like a high-level language, run like C

github.com

41–50 of 159 posts

Re: Zen-C: Write like a high-level language, run like C

#41
> 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.

Re: Zen-C: Write like a high-level language, run like C

#42
post #14

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?

one benefit is that a lot of tooling e.g. for verification etc. is built around C.

another is that it only has C runtime requirement, so no weird runtime stuff to impelement if youd say want to run on bare metal..you could output the C code and compile it to your target.

Re: Zen-C: Write like a high-level language, run like C

#44
post #21

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 produ…

It has stringly typed macros. It's not comparable to Zig's comptime, even if it calls it comptime:

    fn main() {
        comptime {
            var N = 20;
            var fib: long[20];
            fib[0] = (long)0;
            fib[1] = (long)1;
            for var i=2; i
It just literally outputs characters, not even tokens like rust's macros, into the compiler's view of the current source file. It has no access to type information, as Zig's does, and can't really be used for any sort of reflection as far as I can tell.

The Zig equivalent of the above comptime block just be:

    const fibs = comptime blk: {
        var f: [20]u64 = undefined;
        f[0] = 0;
        f[1] = 1;
        for (2..f.len) |i| {
            f[i] = f[i-1] + f[i-2];
        }
        break :blk f; 
    };
Notice that there's no code generation step, the value is passed seamlessly from compile time to runtime code.

Re: Zen-C: Write like a high-level language, run like C

#46
post #19

Earlier quoted context omitted.

Assembly requires way more work than compiling to, say C. Clang and gcc do a lot of the heavy lifting regarding optimisation, spilling values to the stack, etc

Then you're stuck with the C stack, though, and no way to collect garbage.

really? you cant track and count your pointers in C? why not?

Re: Zen-C: Write like a high-level language, run like C

#47
post #21

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 produ…

I am working on mine as well. I think it is very sane to have some activity in this field. I hope we will have high level easy to write code that is fully optimized with very little effort.

Re: Zen-C: Write like a high-level language, run like C

#48
post #20

Earlier quoted context omitted.

[flagged]

> C is the patrician's choice. Is this suppose to be a positive thing? I thought we all wanted to violently murder the patricians. Regardless, C might be a valid IR. I apologize for being bigoted.

Try it again and see how it goes.

Re: Zen-C: Write like a high-level language, run like C

#49

> 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 custo…

Given an option that is configurable, why would the default setting be the one that increases probability of errors?

For some niches the answer is "because the convenience is worth it" (e.g. game jams). But I personally think the error prone option should be opt in for such cases.

Or to be blunt: correctness should not be opt-in. It should be opt-out.

I have considered such a flag for my future language, which I named #explode-randomly-at-runtime ;)

Post reply on HN