Live data from Hacker News

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

github.com

91–100 of 159 posts

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

#91
post #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 name…

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

They're objecting to the "given", though. They didn't comment either way on what the default should be.

Why should it be configurable? Who benefits from that? If it's to make it so people don't have to type "var mut" then replace that with something shorter!

(Also neither one is more 'correct')

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

#92

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

It's not ideal but it seems like something an LSP could tell you on a hover event. I didn't see an LSP (I didn't look that hard either) but presumably that's within the scope of their mission statement to deliver modern language ergonomics. (But I agree with sibling comments that this should be a keyword. Another decent alternative would be that it's only global in scope.)

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

#95
post #17

Earlier quoted context omitted.

> what this adds I guess the point is what is subtracts, instead - answer being the borrow-checker.

So it re-adds manual lifetime checking. Got it.

It might or might not be a toy project, I'm not sure, but one advantage of subtracting the borrow checking is that the compiler avoids a lot of complex machinery.

Borrow checking in Rust isn't sound AFAIK, even after all these years, so some of the problems with designing and implementing lifetimes, region checking, and borrow checking algorithms, aren't trivial.

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

#96
post #55

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.

man I haven't heard anything about Vala in ages . is it still actively developed/used? how is it?

Vala is still being developed and used in the GNOME ecosystem. Boo, on the other hand, is pretty dead.

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

#98

Earlier quoted context omitted.

Makes it easy to "try before you buy", too. If you decide it's not for you, you can "step out" and keep the generated C code and go from there.

This isn't a very sane plan. The ~300 LOC example mini_grep ( https://github.com/z-libs/Zen-C/blob/main/examples/tools/min... ) compiles to a ~3.3k LOC monstrosity ( https://pastebin.com/raw/6FBSpt1z ). It's easier to rewrite the whole thing than going from the generated code. At least for now, generated code shouldn't be considered something you're ever supposed to interact with.

I looked at it primed for the worst by your comment, but it’s honestly not so bad. A lot of setup, data type code and what looks like overloads.

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

#99
post #71

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.

Noob question: if it just compiles to threads, is there any need for special syntax in the first place? My understanding was that no language support should be required for blocking on a thread.

One advantage is that it gives you the opportunity to move to a more sophisticated implementation later without breaking backwards compatibility (assuming the abstraction does not leak).
Post reply on HN