Introduction to the Zig Programming Language
andrewkelley.me
andrewkelley.me
I really like this corner of the language design world. People always say that C is too entrenched and none of these languages are compelling enough to make a large number of developers switch, but I disagree. Someone said that C and Lisp are two local optima in the space of programming languages... I think that Lisp probably is, but C is only near a local optimum. There is a true local optimum remaining to be found.
[1] https://github.com/BSVino/JaiPrimer/blob/master/JaiPrimer.md
[2] https://github.com/BSVino/JaiPrimer/blob/master/JaiPrimer.md...
> I've been following the project, and he has some great ideas that I plan to shamelessly copy such as Struct Of Array support. Running arbitrary code at compile time is on the table, but I haven't figured everything out about it yet. Jonathan Blow is an interesting character. I have a lot of respect for him, but I don't always agree with him. I feel like his perspective is insightful but also limited in some ways. I'm sure the same is true for myself, but all that is to say, our respective languages will be (and already are) different enough to warrant being different projects. For example, one of my goals is "friendly to open source package maintainers (such as Debian)". This entails things like keeping a meticulous record of how to bootstrap the compiler without compromising security, having a reproducible build, providing ways for the maintainers to configure various things, etc. Based on what I know about Jon, he'll either be completely apathetic about package maintainers, or potentially even have a hostile attitude.
> Also no spoilers for The Witness please. I'm waiting until it comes out on Linux to play :-)
Absolutely. But one problem that new languages face is that libraries are part of how much the language helps you do what you are trying to do. So to gain any traction, a new language needs to have libraries...
> Complete C ABI Compatibility
... and there they are! Nicely done, though this is a fairly common solution these days. Or, it could be regarded as a cheat, because you don't have your own library...
> Alternative Standard Library
... and another point of criticism dies.
I also like the difference between debug and release builds. All in all, this looks pretty nice.
> Cyclone is no longer supported; the core research project has finished and the developers have moved on to other things. (Several of Cyclone's ideas have made their way into Rust.) Cyclone's code can be made to work with some effort, but it will not build out of the box on modern (64 bit) platforms).
Overall this project looks interesting. I'm interested to see where it goes in the future and what design trade offs end up being implemented.
I think my pet language (Myrddin) actually has you almost covered. It doesn't have methods, but it does have traits, which allow similar things at compile time.
You have an example of generics and traits here, in the std namespace:
https://github.com/oridb/mc/blob/master/lib/std/htab.myr
https://github.com/oridb/mc/blob/master/lib/std/iterutil.myr
Otherwise, it's one of those things that you don't realize how useful it is until you can't do it. But not often, and ideally a Sufficiently Expressive Language wouldn't need code generation—but this is targeting C's niche, not Haskell's.
The only reason to keep semicolons I can think of is to look familiar to C programmers, so as not to scare them off. I’m not very familiar with that demographic, but I think most of them would be fine with it, especially if they have used other semicolon-less languages. Semicolons, which are present on about 50% of lines, add visual noise and the cognitive load of remembering to type them.
Think of it like a sliding scale: on the far extreme of no redundancy, a typo could be a runtime error instead of a compile error. On the far extreme of redundancy, you have to express your code twice in different ways. Having semicolons is a reasonable balance between the extremes.
Semicolons help get a better error message for the following typo, if `foo` can take either 0 or 1 arguments:
if (true) {
foo(;
bar *= 2;
baz(
"first",
"second",
);
}
The compiler can easily tell you that you forgot a ) on line 2. If semicolons were optional, the program would be this: if (true) {
foo(
bar *= 2
baz(
"first",
"second",
)
}
The simplest error message to implement would complain that you forgot a ) somewhere within lines 2 to 7, and also that the argument to `foo` contains two statements instead of one expression. This error message would be less helpful.However, with the semicolonless language, you could still write the compiler to give the better error message. You could have a heuristic that that this combination of errors suggests a different error, or you could parse indentation for error-checking purposes. It would just require more work on the part of the compiler writer.
This is good stuff, and I plan to work on some embedded projects to experience firsthand the needs of this kind of project.
Does this mean something like (pseudo-C):
struct weird_bit_field {
uint8_t x : 32;
};
i.e. an 8-bit int that takes 4 bytes of space? Or am I misunderstanding something?If we take those two languages as the extremities of a spectrum, where would you put Zig on that spectrum?
Jai optimizes for performant memory management. Several of its features, such as SOA pointers, make organizing your data to take advantage of the processor cache easier if not as easy as managing memory in any other way.
It looks like Zig optimizes for simple memory management. Without all the bells an whistles the other languages offer, the easiest way to manage your memory is the most obvious way. Which is good from a prinicple-of-least-surprise perspective.
And then operations like append or resize could return an error (since memory allocation can fail), and I want to make sure the semantics for that are reasonable.
That and a Map data structure I want to make sure have convenient semantics since these primitives are used in many software applications.
I(tried(once(in(college(but(c(is(not(my(style()))))))))))(<- I tried once in college but lisp is not my style)
A language to replace C implemented in C++. ;-)
Did anyone here watch the video? I mean the author said a lot of cool things about being more pragmatic and all that stuff, while implementing it in LLVM/C++, what may be, as you say, a wise decision.
There's no assignment of guilt, I just found it ironic.
Maybe it is because of LLVM build system?