News for hackers. Stuff that matters.
Re:What Makes the Zig Programming Language Unique? by WalterBright on Wednesday October 05, 2022 @11:56PM (#33104215)
D has has compile time function evaluation for 15 or 16 years now. It doesn't have a special keyword, either. It's simple - everywhere the grammar has a const-expression, then compile time function evaluation is in play.
Re:What Makes the Zig Programming Language Unique? by kazinator on Thursday October 06, 2022 @02:23AM (#33105026)
The idea behind compile time evaluation is that expressions which are not syntactically constant expressions can also be evaluated at compile time. A function definition can be marked as being available at compile time. When the body of a function f(x) refers to x, that is not a constant expression syntactically. However, an expression like f(3) can be considered a constant expression, since it passes a constant to function that has been marked as a compile-time function.
Re:What Makes the Zig Programming Language Unique? by WalterBright on Thursday October 06, 2022 @03:07AM (#33105339)
D uses `enum` to specify a manifest constant, which evaluates at compile time:

    int i = f(3); // evaluate at run time
    enum i = f(3); // evaluate at compile time
Note that it's not the function that is specified as being run at compile time, it is the use of the function that determines it. There is no difference between compile time functions and runtime functions. The use that triggers a function to be evaluated at compile time is when the function call is in a const-expression.
Re:What Makes the Zig Programming Language Unique? by kazinator on Thursday October 06, 2022 @03:31AM (#33105509)
Could this function be used that way?

  enum res = toggle_gpio(FRONT_LED_2);
Obviously, there is no difference between run-time functions that are qualified for compile-time execution, and compile-time functions.

Then, suppose we have all these requirements

- We want a separate compilation model where the code which is calling f(3) at either compile or run time knows nothing about how f is defined, only how it's declared.

- We want not to include the compiled image of f in the target program, if if is only called at compile time, only if at least one call to it somewhere in the program is staged to run-time.

- We want to make sure that if f is called at compile time, nobody can change its definition to accidentally call for run-time semantics like toggle_gpio(FRONT_LED_2).

and that's how we probably arrive at a declarative mechanism like constexpr that goes on the function, rather than trying to orchestrate thing remotely/indirectly by placing a call to the function into a compile-time context.

Re:What Makes the Zig Programming Language Unique? by WalterBright on Thursday October 06, 2022 @04:00AM (#33105691)
D guarantees that a function annotated with `pure` will also work at compile time. But compile time does allow calling some impure functions, as long as the path taken through the function's body is pure. This greatly expands the palette of functions able to be executed at compile time.

Not including functions never called for runtime execution in the runtime is a normal compiler optimization. No user input is necessary.

If the function's semantics change so it is no longer runnable at compile time, the compiler will let you know when you try it. If you want to force the detection, just call it at compile time with dummy declaration.

> that's how we probably arrive at a declarative mechanism like constexpr that goes on the function, rather than trying to orchestrate thing remotely/indirectly by placing a call to the function into a compile-time context.

This issue is raised now and then, and in 16 years of CTFE in D it has never ever been reported as causing an actual problem.

Re:What Makes the Zig Programming Language Unique? by jbb67 on Thursday October 06, 2022 @04:40AM (#33105983)
I really like zig and think it is potentially a great language. I also used D a little in the past too, but somehow drifted away but some of the comments here make me want to revisit it

Great we have many good languages to choose from

Re:What Makes the Zig Programming Language Unique? by kazinator on Thursday October 06, 2022 @05:59PM (#33114637)
If a compile-time function opened a text file, read the content and returned it as a string (which becomes a literal), I would consider that pure.
Re:What Makes the Zig Programming Language Unique? by nurettin on Thursday October 06, 2022 @01:23AM (#33104670)
I never liked the original D in the early 2000s, especially the anti-C++ marketing rhetorics. But the post-alexandrescu D is amazing. Just last week I placed a delegate bound to a closure into an immutable struct within a child thread's run function and passed it into the main thread via send to be called and it actually worked! What an amazing language. There aren't many 3rd party libraries, though. And whatever exists is highly questionable.
Re:What Makes the Zig Programming Language Unique? by WalterBright on Thursday October 06, 2022 @03:12AM (#33105376)
Fortunately, D now has a C compiler embedded into it (ImportC). ImportC will compile C11 Standard code, and automatically make the interface to that C code available to D.

This means, if a C library is available, D can use it.

(There are some exceptions. While ImportC will handle C preprocessor metaprogramming just fine, those metaprogramming macros won't be available to the D code, other than simple #define manifest constant declarations.)

Re:What Makes the Zig Programming Language Unique? by kazinator on Thursday October 06, 2022 @02:24AM (#33105040)
> And whatever exists is highly questionable.

Could it be because some of it, say, places a delegate, bound to a closure, into an immutable struct within a child thread's run function, and passes that to another thread via a send to be called?

Re:What Makes the Zig Programming Language Unique? by nurettin on Thursday October 06, 2022 @02:55AM (#33105254)
I think so, I mean, if it is a one-off POC, nobody is going to build their uber-for-can-opener startup on top of it. But if billions of closures are actively passed around every day by thousands of projects, and lots of bug fixes and features are deployed continuously, why not build your airbnb-for-doghouses empire using that library today?
Re:What Makes the Zig Programming Language Unique? by arunc on Sunday October 09, 2022 @12:19AM (#33138238)
> What an amazing language. There aren't many 3rd party libraries, though. And whatever exists is highly questionable.

Can't agree more. Such a powerful language but with an absolute meager ecosystem! No dogfooding.

GC and crashes are pretty common on long running high performance apps. They should just build things from the ground up using betterC.

Re:What Makes the Zig Programming Language Unique? by marmada on Thursday October 06, 2022 @03:43PM (#33113053)
One thing I'm curious about is, fundamentally it looks like Zig is going to be the more popular language. I don't know why, but that's just my gut feel. It looks like Zig will get the traction that D never did.

So when I see comments like this that say "D also has X feature", I'm curious about why D didn't take off but Zig (likely) will.

Re:What Makes the Zig Programming Language Unique? by Tozen on Thursday October 06, 2022 @08:49PM (#33116078)
D is consistently ranked, by TIOBE index, in the top 30s of programming languages. Zig is not even ranked in their top 100 nor has even achieved 1.0. Appears to be a number of years away from 1.0, which also means all kinds of things can happen and other languages can get more of a spotlight.

In Zig's near category, there are other languages like Odin, Jai, Vlang, Rust, etc... For example, by the time Zig reaches 1.0, Jai (which is in Beta) might be publicly released, others languages might have added some "killer" features, and/or others in development might have also reached production quality.

Zig has quite a long way to go, and if anything may never achieve the popularity or widespread usage of D. Examples of the difficulty of programming languages rising through the ranks, is Nim and Crystal. Both Nim (2008) after 14 years and Crystal (2014), have not even made it into the top 50.

Re:What Makes the Zig Programming Language Unique? by super_flanker on Friday October 07, 2022 @04:01PM (#33126228)
TIOBE's data is so botched, seriously typescript is ranked 40, below Scratch, below COBOL, heck even below FoxPro.

And no Vlang is not a programming language, it's a scam and should be treated as one.

Re:What Makes the Zig Programming Language Unique? by Tozen on Saturday October 08, 2022 @12:37AM (#33129812)
> TIOBE's data is so botched...

Stop deluding yourself. If we take out TIOBE, and use the IEEE's Top Programming Languages of 2022 (https://spectrum.ieee.org/top-programming-languages-2022), D is still recognized (even higher than the 30s) while Zig, Nim, or Crystal do not even make their chart. That's the reality.

> Vlang...

To begin with, you are a known troll (with possibly multiple troll accounts at HN) that has spent over an year engaging in slander and lies about the language almost any time it's mentioned.

Looks like you are the creator or involved with some other language that can't get as much support or popularity. It would be advisable for you to stop being obsessed with Vlang. How many years of your life will you waste on such childish antics? You would be better off focusing on making your programming language better, if it's not already too late and its a failure.

As for pushing this bold face lie that the language is a "scam", that's both ludicrous and easily proven false. Vlang has many hundreds of code examples and projects. Easily found at:

1) Vlang examples on GitHub (https://github.com/vlang/V/tree/master/examples).

2) Vlang at Rosetta Code (https://rosettacode.org/wiki/Category:Vlang).

3) Awesome Vlang at GitHub (https://github.com/vlang/awesome-v).

The "scam" is you tricking yourself into thinking that your troll tactics are working. Instead, your continual and unnecessary defamation is making what you are even more obvious.

Re:What Makes the Zig Programming Language Unique? by p0nce on Saturday October 08, 2022 @12:41PM (#33133788)
The demand for COBOL programmers is higher than ever.
Re:What Makes the Zig Programming Language Unique? by odysseus on Thursday October 06, 2022 @08:30PM (#33115947)
Take off every zig