
Zig Programming Language 0.1.1: First beta release - moomin
http://ziglang.org/download/0.1.1/release-notes.html
======
sitharus
I think it’s great people keep experimenting with new languages. Sure many
will die off and be forgotten, but the people involved will learn and create.
If we keep waiting for someone else to make the perfect language we’ll never
get anywhere.

I like how error handling is structured, though I’m undecided on if I prefer a
specific case of a more extensible system. Pretty sure it’s right for 80% of
cases though.

------
ngrilly
There are two really interesting ideas in Zig that I'd like to find in Go:

\- The %% operator and the %return expression used to simplify error handling.

\- The concept of compile-time parameters used to implement generic functions
and generic data structures.

~~~
polskibus
I don't mean to troll here. Aren't generics officialy excluded forever from Go
lang roadmap? I'm not following Go much, but that's what I recall from months
ago.

~~~
orph4nus
I think they are still open to it, in a very sceptical way. Basically they are
asking [1] the public/users for papers/documents/articles/blogs, describing
the use cases of generics in Golang. How would they use it? Why is it required
(as in can you not do it easily/better without generics)? Stuff like that.
They basically aren't convinced that generics is something they need/want in
Go, but if the users can convince them, they will still go for it in the
future of Go.

[1]: [https://blog.golang.org/toward-go](https://blog.golang.org/toward-go)

    
    
       "I'm focusing today on possible major changes, such as 
       additional support for error handling, or introducing 
       immutable or read-only values,
       or adding some form of generics,
       or other important topics not yet suggested.
    
       We can do only a few of those major changes.
       We will have to choose carefully."

~~~
GenericsMotors
I find it interesting that they're asking the community what the use cases for
generics are, when internally Go does support generics for its built-in
collection types...hmmm I wonder why?!

Maybe because it provides compile-time type safety and reduces the amount of
boilerplate that would otherwise be required. Yet they can't see the
usefulness outside of this single case?

Seems disingenuous to me.

~~~
pjmlp
Basically it allows for any Gofer on HN and similar forums to defend the idea
"they are working on it" without any actual visible action.

------
e12e
Well, it certainly looks ambitious. But... It's not very pretty? Looks a bit
like an unholy union of TeX and C?

[https://github.com/zig-
lang/zig/blob/master/example/cat/main...](https://github.com/zig-
lang/zig/blob/master/example/cat/main.zig)

~~~
AndyKelley
Handling every possible error in a clear way isn't pretty, but somebody's
gotta do it.

~~~
e12e
But do you have to use so many percentage signs to handle all the errors? :)

~~~
AndyKelley
This is the ugliest thing about zig. Can you come up with a better proposal to
capture the semantics? I'd love to see it. I've tried and this is the best I
can do.

~~~
hawski
A keyword maybe?

For unary case:

    
    
      // original:
      %%io.stdout.printf("Hello, world!\n");
      
      // my favorite ideas:
      try io.stdout.printf("Hello, world!\n");
      dare io.stdout.printf("Hello, world!\n");
      // others:
      err io.stdout.printf("Hello, world!\n");
      ex io.stdout.printf("Hello, world!\n");
      bet io.stdout.printf("Hello, world!\n");
      bid io.stdout.printf("Hello, world!\n");
    

For the binary operator:

    
    
      // my favorite ideas:
      a yet b
      a odd b
      a but b
      a ex b // extra or except
      a err b
      a bail b
      // others:
      a else b // Would overloading the meaning have sense?
      a esc b // escape
      a alt b // alternate
      a aux b // auxiliary
      a sub b // substitute
      a prox b // proxy
      a then b
      a eor b // error or
      a repl b // replacement
      a supp b // supplemental
      a %or b

~~~
AndyKelley
These are good ideas. we also need alternatives for these :

%defer %return

~~~
hawski
Some may fit previous propositions.

For %defer:

    
    
      error defer deallocateFoo(foo);
      but defer deallocateFoo(foo);
      ex defer deallocateFoo(foo);
      failsafe deallocateFoo(foo);
      bail defer deallocateFoo(foo);
    

For %return:

    
    
      fn doAThing(str: []u8) -> %void {
          const number = try parseU64(str, 10);
          // ...
      }
    

"try" could mean "return an error in case of an error" aka "%return". Then
"dare" could mean "panic in case of an error" aka "%%foo();".

Or use "ex" or "but" everywhere:

    
    
      ex foo();
      const num = foo() ex 42;
      const num = ex foo();
      ex defer bar(baz);
    
      but foo();
      const num = foo() but 42;
      const num = but foo();
      but defer bar(baz);

~~~
ant6n
Ex sounds a lot like example, rather than exception.

I really like the use of keywords, leveraging our extensive understanding and
intuition of language to make a language more clear and intuitive.

Symbolic operators work well if they are borrowed from math (e.g. third
grade), making up new ones often results in a painful learning phase.

------
gsnedders
So why would I be interested in Zig rather than Rust, if I'm trying to replace
C code with something safer and more modern?

~~~
AndyKelley
[https://github.com/zig-lang/zig/wiki/Why-Zig-When-There-
is-A...](https://github.com/zig-lang/zig/wiki/Why-Zig-When-There-is-Already-
CPP%2C-D%2C-and-Rust%3F)

~~~
namelost
Lack of operator overloading limits the audience of a language to non-
numerical applications (e.g. no gamedev).

~~~
AndyKelley
One counter example:
[https://youtu.be/rX0ItVEVjHc?t=589](https://youtu.be/rX0ItVEVjHc?t=589)

~~~
gravypod
In that video he just said that operator overloading was good for math
operations. That's not a counter example.

~~~
abiox
even for math operations, "we'll let it go" would seem to be a different
sentiment than "good". :)

------
nikisweeting
Congratulations Andy, I've seen you working on this for a long time and am
very impressed by the rigor it takes to release a language this large on your
own. I look forward to seeing cool projects built in Zig!

------
steveklabnik
Congrats on the release! Zig is not my cup of tea, but I'm glad it exists. I
still owe you a full review sometime, Andy. Never enough hours in the day.

------
lossolo
Syntax looks almost exactly like Rust with some elements from Go and D.

What about memory management ? They say there is no GC so manual memory
management? Any memory safety features ?

~~~
iainmerrick
The “defer” statement makes it easy to ensure important code gets run once
even if there are multiple returns (along with %defer for error cases). That
covers at least 95% of fiddly manual allocation problems -- the kind of thing
RAII helps you avoid in C++, or “using” in Python and C#.

~~~
dbaupp
Deallocating/RAII is not memory safety. Leaking all memory is, in fact, a
tried-and-true way to get memory safety (GC'd languages are semantically doing
this: GC is "just" an optimization), since it means problems like use-after-
free are impossible. Memory leaks are great to eliminate, but they can't lead
to the corruption that memory unsafety can cause.
[http://huonw.github.io/blog/2016/04/memory-leaks-are-
memory-...](http://huonw.github.io/blog/2016/04/memory-leaks-are-memory-safe/)

Rephrasing the parent's question: does Zig try to ensure memory safety (e.g.
no use-after-free, dangling pointers, iterator invalidation, data races)?

~~~
eradicatethots
Zig + borrow checker is my ideal language

~~~
fasquoika
Maybe look at the language that inspired Rust: Cyclone
[http://cyclone.thelanguage.org/](http://cyclone.thelanguage.org/) . It's just
a research language (which the site claims is "done") but maybe worth a look.

~~~
eradicatethots
Seems pretty cool, too bad it’s dead now though

------
zem
the reference to a 5-bit number in the intro was intriguing; i don't think
i've ever seen a language that would support that (maybe pascal with type
subsetting).

this seems to be the best description of it:
[http://andrewkelley.me/post/a-better-way-to-implement-bit-
fi...](http://andrewkelley.me/post/a-better-way-to-implement-bit-fields.html)

~~~
kbp
Common Lisp allows integer types of however many bits you want using SIGNED-
BYTE and UNSIGNED-BYTE (don't let the names confuse you; a byte isn't
necessarily 8 bits):

    
    
        CL-USER> (the (unsigned-byte 5) 31)
        31
        CL-USER> (the (unsigned-byte 5) 32)
        ; Evaluation aborted on #<SIMPLE-TYPE-ERROR expected-type: (UNSIGNED-BYTE 5) datum: 32>.

------
vortico
Andrew Kelley makes some great projects! Some other ones are the libsoundio
cross platform playback/recording library and the genesis DAW.

------
ngrilly
Andy, is it a coincidence or have some features of Zig been inspired by Go?
More specifically: defer, the syntax for the array type with [] as a prefix
instead of a suffix, and the syntax for array literals.

~~~
AndyKelley
Yeah both of those were inspired by Go, which I'm sure were inspired by older
ideas.

There's nothing new under the sun. What Zig brings to the table is high
quality engineering and bringing the ideas together in a way that makes sense.

~~~
ngrilly
Incremental improvements and cross-pollination are great! I don't need a
language with manual memory management for my current projects, but I'll
definitely keep an eye on Zig. It solves most things I dislike in C, and keeps
the good stuff.

------
_pmf_
Nice to see Windows support. I think first class Windows support is an
underrated factor in Rust's adoption as opposed to other similar languages
(i.e. it had pretty good Windows support very early).

------
samuell
Feel free to help fill out the relevant details about it in our crowd-sourced
feature comparison spreadsheet about statically compiled languages:
[https://docs.google.com/spreadsheets/d/1BAiJR026ih1U8HoRw__n...](https://docs.google.com/spreadsheets/d/1BAiJR026ih1U8HoRw__nzbCSFnnHicWrjxpW5l6-O3w/edit#gid=0)
:)

------
eggy
I am still trying to learn Rust here and there, but Zig seems to click more
with me. I love Rust's documentation. Is there a Zig book in the works? I will
continue to use the site for reference, and translating C snippets of mine. I
like the libc independence of it for my toy programs and game dev jams. I was
using TCC64 for them before.

------
keithnz
Does Zig have a compile to C option? This would open it up to a massive
embedded world.

~~~
AndyKelley
No but we have the other way around - C to Zig. Why would you want to go to C?

~~~
keithnz
Nearly every platform has a C compiler. Many embedded platforms have almost no
language alternatives. No way Zig ( or Rust, or Go ) is ever going to target
them all.

~~~
Gaelan
LLVM aims to solve this problem. (Side note: is there an LLVM backend for C?)

~~~
tiehuis
There was, but it was removed in LLVM 3.1 [1].

It seems as there have been some attempts to revitalize it [2] but these are
targeting older versions and would probably require a lot more work to ever
get back in-tree.

[1]
[http://releases.llvm.org/3.1/docs/ReleaseNotes.html](http://releases.llvm.org/3.1/docs/ReleaseNotes.html)

[2] [https://github.com/JuliaComputing/llvm-
cbe](https://github.com/JuliaComputing/llvm-cbe)

------
dtech
But has every Zig taken off for great justice?

sorry

------
eradicatethots
this language is super cool. High hopes.

------
timthelion
I think that it is sad that we keep on creating new programming languages that
are not radically different. The Zig language ecosystem faces the same
problems as C and the compiler will preform many of the same tasks, lexing,
parsing, optimizing, documentation, supporting all sorts of weird edge cases
and use cases. From what I see in the introduction, I don't see a convincing
case for a new language here. This kind of incrementalism is not worth another
persons years of effort to create a parallel path.

I think that if you are going to spend years creating a new language, you
ought at least to try something new. Otherwise, you become just another
amateur landscape artists. Maybe you're paintings will look nice, but they'll
never really be of any great value to society.

~~~
jaredklewis
What languages were “radically” different when they were relased? My take:
COBOL, C, SmallTalk, lisp, ML, prolog, Shell. I’m might be missing some, but I
think the pattern is clear. Only C remains among the most popular languages.

Almost all widely used languages today (c++, php, ruby, java, python,
javascript, etc...) are incremental improvements on old ideas.

I think your opinion that the most used programming languages today are not
“of any great value” to be bumpkis.

~~~
kbp
What was radically different about C when it was released? It doesn't seem to
stand out that much to me from the backdrop of BCPL, Algol, Bliss, Pascal,
etc.

~~~
moomin
I’d say you’re right, it wasn’t that different. I think what made the
difference for C was Unix (and a very good introductory book).

------
Sir_Cmpwn
I spent some time with Zig a while ago. Here are my conclusions:

\- The string handling is braindead

\- The compiler and stdlib is immature. This seems like the first programming
language the guy has written. You should have a few failures to learn from
before you make a Serious Programming Language imo.

\- Code run at compile time is a neat idea but has a weird syntax and really
really complicates the internals of the compiler and related tooling.

Unfortunately this is no C replacement IMO.

~~~
AndyKelley
Note: The set of people in the Zig community who are blocked is size 1 and it
is Sir_Cmpwn. He is blocked for being rude, destructive, and making a large
number of incorrect claims, which he ignores the rebuttals to.

~~~
bpicolo
Hey Andy,

I'm getting a 403 on your docs page:
[http://ziglang.org/documentation/](http://ziglang.org/documentation/)

~~~
AndyKelley
The link was outdated in the README. Fixed.
[http://ziglang.org/documentation/master/](http://ziglang.org/documentation/master/)

------
Dinux
We already have enough alternatives to C, and C itself is working pretty well
for most OS-level developers.

~~~
ndh2
We also have enough naysayers and party poopers trying to discourage language
authors. Yet here you are...

~~~
srean
I wish I could upvote this enough.

------
nurettin
So the idea is to build new languages instead of fixing/extending older ones
and getting an existing user base immediately because...?

~~~
oblio
Can anyone even fix C, at this point? You can't break backwards compatibility
and the last standard that is widely adopted is C89, from 28 years ago. C99
and C11 haven't been adopted by Microsoft, so as far as I know their adoptions
among developers is somewhat low.

If big companies can't move the needle for C, how can a single developer do
it?

~~~
nurettin
A single developer can apparently create a whole new language, complete with a
module system, a proof system, a constraint system, a parser/lexer, but can't
extend C by adding new flags to the compiler that are optional and don't
necessarily break anything from old code and lets you selectively upgrade your
sources.

~~~
_pdp_
Maybe you want something like Babel JS but for C - i.e. a transpiler.

~~~
nurettin
Pretty sure they had a similar idea in mind when they invented the C
preprocessor.

