Live data from Hacker News

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

github.com

101–110 of 159 posts

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

#101

Earlier quoted context omitted.

Yeah, immutability should probably use a `let` keyword and compiler analysis should enforce value semantics on those declarations.

Agreed, using `var` keyword for something that is non-var-ying (aka immutable) is not very intuitive.

Mutability is distinct from variability. In Javascript only because it's a pretty widely known syntax:

    const f = (x) => {
      const y = x + 1;
      return y + 1;
    }
y is an immutable variable. In f(3), y is 4, and in f(7), y is 8.

I've only glanced at this Zen-C thing but I presume it's the same story.

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

#102

Nice! Compiles in 2s on my unexceptional hardware. But it lacks my other main desiderata in a new language: string interpolation and kebab-case.

Oh, it _does_ have string interpolation, my bad. Sadly, not by default -- you still have to go back and add an "f" before the string once you've started typing it and then realize that you want an interpolated string. Also, it doesn't always work -- if I define two interpolated string variables in one function, GCC chokes in a way I'm not understanding. And every interpolated string variable consumes 4K of global memory.

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

#103

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.

From what I see, Zen-C aims to be "C with super-powers". It still uses C pointers for arrays and strings. It transpiles to single human-readable C file without symbol mangling. No safety. Not portable (yet?).

Nim is a full, independent modern language that uses C as one of its backends. It has its own runtime, optional GC, Unicode strings, bounds checking, and a huge stdlib. You write high-level Nim code and it spits out optimized C you usually don't touch.

Here’s a little comparison I put together from what I can find in the readme and code:

    Comparison          ZenC           Nim
    
    written in          C              Self-Hosted
    targets             C              C, C++, ObjC, JS, LLVM (via nlvm), Native (in-progress)
    platforms           POSIX          Linux, Windows, MacOS, POSIX, baremetal
    mm strategy         manual/RAII    ARC, ORC(ARC with cycle collector), multiple gc, manual
    generated code      human-readable optimized
    mangling            no             yes
    
    stdlib              bare           extensive/batteries-included
    
    compile-time code   yes            yes
    macros              comptime?      AST manipulation
    
    arrays              C arrays       type and size is retained at all times
    strings             C strings      have capacity and length, support Unicode
    bounds-checking     no             yes (optional)

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

#104
post #101

Earlier quoted context omitted.

Agreed, using `var` keyword for something that is non-var-ying (aka immutable) is not very intuitive.

Mutability is distinct from variability. In Javascript only because it's a pretty widely known syntax: const f = (x) => { const y = x + 1; return y + 1; } y is an immutable variable. In f(3), y is 4, and in f(7), y is 8. I've only glanced at this Zen-C thing but I presume it's the same story.

"immutable variable" is an oxymoron. Just because Javascript did it does not mean every new language has to do it the same way.

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

#105
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 wonder, how can a programming language have the productivity of a high-level language ("write like a high-level language"), if it has manual memory management? This just doesn't add up in my view. I'm writing my own programming language that tries "Write like a high-level language, run like C.", but it does not have manual memory management. It has reference counting with lightweight borrowing for performance sensi…

C is literally a high level language.

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

#107
post #101

Earlier quoted context omitted.

Mutability is distinct from variability. In Javascript only because it's a pretty widely known syntax: const f = (x) => { const y = x + 1; return y + 1; } y is an immutable variable. In f(3), y is 4, and in f(7), y is 8. I've only glanced at this Zen-C thing but I presume it's the same story.

"immutable variable" is an oxymoron. Just because Javascript did it does not mean every new language has to do it the same way.

There are two distinct constructs that are referred to using the name variable in computer science:

1) A ‘variable’ is an identifier which is bound to a fixed value by a definition;

2) a ‘variable’ is a memory location, or a higher level approximation abstracting over memory locations, which is set to and may be changed to a value by an assignment;

Both of the above are acceptable uses of the word. I am of the mindset that the non-independent existence of these two meanings in both languages and in discourse are a large and fundamental problem.

I take the position that, inspired by mathematics, a variable should mean #1. Thereby making variables immutably bound to a fixed value. Meaning #2 should have some other name and require explicit use thereof.

From the PLT and Maths background, a mutable variable is somewhat oxymoronic. So, I agree let’s not copy JavaScript, but let’s also not be dismissive of the usage of terminology that has long standing meanings (even when the varied meanings of a single term are quite opposite).

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

#108

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.

I’d say that the point of async/await is to create a syntax demarcation between functions which may suspend themselves (or be suspended by a supervisory system) and those functions that process through completely and cannot be suspended (particularly by a supervisory system). The means to enable the suspension of computation and allow other computations to proceed following that suspension are implementation details.

So, having an async function run on a separate thread from those functions that are synchronous seems a viable way to achieve the underlying goal of continuous processing in the face of computations that involve waiting for some resource to become available.

I will agree that inspired by C#’s originating and then JavaScripts popularization of the syntax, it is not a stretch to assume async/await is implemented with an event loop (since both languages use such for implementation).

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

#109
post #105

Earlier quoted context omitted.

I wonder, how can a programming language have the productivity of a high-level language ("write like a high-level language"), if it has manual memory management? This just doesn't add up in my view. I'm writing my own programming language that tries "Write like a high-level language, run like C.", but it does not have manual memory management. It has reference counting with lightweight borrowing for performance sensi…

C is literally a high level language.

Seriously, in the discussion happening in this thread C is clearly not a high-level language in context.

I get your statement and even agree with it in certain contexts. But in a discussion where high-level languages are presumed (in context) to not have memory management, looping constructs are defined over a semantics inferred range of some given types, overloading of functions (maybe even operators), algebraic datatypes, and other functional language mixins: C most certainly IS NOT a high level language.

This is pedantic to the point of being derailing and in some ways seemed geared to end the discussion occurring by sticking a bar in the conversations spokes.

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

#110
post #72

Earlier quoted context omitted.

Does Odin compile to C? I thought it only uses LLVM as a backend

Same question but for Jai.

Jai does not compile to C. It has a bytecode representation that is used primarily for compile time execution of code, a native backend used mostly for iteration speed and debug builds, and a LLVM target for optimized release builds.
Post reply on HN