15 ms·
Zig Programming Language 0.1.1: First beta release
- ddevault 9y agoI 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 9y agoNote: 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 9y agoHey Andy, I'm getting a 403 on your docs page: http://ziglang.org/documentation/ http://ziglang.org/documentation/
- AndyKelley 9y agoThe link was outdated in the README. Fixed. http://ziglang.org/documentation/master/ http://ziglang.org/documentation/master/
- ddevault 9y agoIf you're going to make claims like this in public I think you had better back them up.
- halayli 9y agoYour feedback is not constructive. At least give examples why it's stdlib is immature or why the string handling is braindead and what you think is missing. This way the community would know more what to work on.
- ddevault 9y agoI should have mentioned that I approached Zig with my feedback at that time and engaged in discussions on the matter. My concerns were largely disregarded.
- halayli 9y agomaybe they were disregarded because the feedback was too generic and cannot be acted on. My point was if you're giving feedback make sure the receiver can do something specific about it.
- timthelion 9y agoI 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.
- ngrilly 9y agoI disagree. We don't have enough incremental improvements, because it's difficult to improve a language and migrate the existing code base at the same time. I'd be happy with a better C (for example get rid of header files and #include), a better Python (for example better parallelism without a GIL), a better Go (for example with a solution for generics and marginally less verbose error handling), a better JavaScript, etc. I'm mentioning "mainstream" languages on purpose.
- sitharus 9y agoThe problem with incremental improvements is you have to keep backwards compatibility. This is a big issue when it comes to keywords. For instance this is valid C#: using async = Task<string>; class BadIdea { public async async async(async async) { } }
- steveklabnik 9y agoRust has a fun similar one. I'm assuming for the same reason as C#: contextual keywords. union union<'union> { union: &'union union<'union>, } https://github.com/rust-lang/rust/blob/59675d29eb47eb743026dcc0737884f548f2197a/src/test/run-pass/weird-exprs.rs#L110-L112 https://github.com/rust-lang/rust/blob/59675d29eb47eb743026d...
- gsnedders 9y agoSo 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 9y agohttps://github.com/zig-lang/zig/wiki/Why-Zig-When-There-is-Already-CPP%2C-D%2C-and-Rust%3F https://github.com/zig-lang/zig/wiki/Why-Zig-When-There-is-A...
- namelost 9y agoLack of operator overloading limits the audience of a language to non-numerical applications (e.g. no gamedev).
- AndyKelley 9y agoOne counter example: https://youtu.be/rX0ItVEVjHc?t=589 https://youtu.be/rX0ItVEVjHc?t=589
- lucozade 9y agoLimit the audience for end user applications, possibly. If this were generally true then C wouldn't be used in numerical applications which is clearly not the case. I think this is the wrong way to look at it. Where C still has advantages over many languages is where the developer's primary mental model is the machine the program is running on. That's why it's used for device drivers and low level library work. Over the last couple of decades, C has become less and less good at this task as the C model and the machine have steadily diverged. At the same time, it's limitations have been exposed more and more. In my view, Zig is aiming at this space i.e. where the developer is primarily interested in what the machine is doing. What they have done is kept the C model (largely) but mitigated or removed some of the egregious failings of C. Zig may not be unique in doing this but it's definitely quite rare. Rust, Go, Swift et al aren't attempting to do this. This isn't a criticism just a perfectly legitimate difference of priority. As I failed my soothsaying exam, I'm in no position to predict which, if any, will succeed. I hope (without much justification) that having language diversity will encourage natural selection.
- sitharus 9y agoI 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 9y agoThere 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 9y agoI 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 9y agoI 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 9y agoI 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 9y ago
- steveklabnik 9y agoCongrats 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.
- vortico 9y agoAndrew Kelley makes some great projects! Some other ones are the libsoundio cross platform playback/recording library and the genesis DAW.
- ngrilly 9y agoAndy, 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 9y agoYeah 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 9y agoIncremental 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.
- lossolo 9y agoSyntax 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 9y agoThe “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 9y agoDeallocating/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-safe/ http://huonw.github.io/blog/2016/04/memory-leaks-are-memory-... 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 9y agoZig + borrow checker is my ideal language
- fasquoika 9y agoMaybe 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.
- 9y ago
- e12e 9y agoWell, 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.zig https://github.com/zig-lang/zig/blob/master/example/cat/main...
- AndyKelley 9y agoHandling every possible error in a clear way isn't pretty, but somebody's gotta do it.
- e12e 9y agoBut do you have to use so many percentage signs to handle all the errors? :)
- AndyKelley 9y agoThis 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 9y agoA 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
- oblio 9y ago
- keithnz 9y agoDoes Zig have a compile to C option? This would open it up to a massive embedded world.
- AndyKelley 9y agoNo but we have the other way around - C to Zig. Why would you want to go to C?
- zem 9y agobecause there are C compilers available for everything out there.
- keithnz 9y agoNearly 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 9y agoLLVM aims to solve this problem. (Side note: is there an LLVM backend for C?)
- tiehuis 9y agoThere 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
- abiox 9y agoi would say for using Zig with Arduino (it's possible llvm will ship AVR support in the future) and other microcontrollers.
- 9y ago
- zem 9y agothe 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-fields.html http://andrewkelley.me/post/a-better-way-to-implement-bit-fi...
- kbp 9y agoCommon 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>.
- nikisweeting 9y agoCongratulations 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!
- _pmf_ 9y agoNice 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).
- dtech 9y agoBut has every Zig taken off for great justice? sorry
- samuell 9y agoFeel 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__nzbCSFnnHicWrjxpW5l6-O3w/edit#gid=0 https://docs.google.com/spreadsheets/d/1BAiJR026ih1U8HoRw__n... :)
- eradicatethots 9y agothis language is super cool. High hopes.
- nurettin 9y agoSo the idea is to build new languages instead of fixing/extending older ones and getting an existing user base immediately because...?
- oblio 9y agoCan 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 9y agoA 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_ 9y agoMaybe you want something like Babel JS but for C - i.e. a transpiler.
- nurettin 9y agoPretty sure they had a similar idea in mind when they invented the C preprocessor.
- viperscape 9y agoTranspilers are what’s helping JavaScript, and moving it along, eg; class and modules were needed, transpilers provided it, now it’s being adopted
- dkersten 9y agoMost existing C compilers (eg clang or gcc) are pretty large and complex beasts. Its often easier to start from scratch than it is to extend an existing codebase that you have never worked in before. It depends on your goals: if you want to appeal to an existing user base and use an existing ecosystem, then modifying existing compilers (or compiling to an existing language) is probably a good idea, but if that isn't a goal for whatever reason, then doing so may not be worth it. Not saying this is a good thing, just that it happens (at least, in my experience).
- Dinux 9y agoWe already have enough alternatives to C, and C itself is working pretty well for most OS-level developers.
- audunw 9y agoWhat? Which alternatives to C? Fortran and Pascal? I don't know of a single modern alternative to C. I wouldn't count Rust, because a replacement for C should be a dead simple language. Rust is a C++ alternative. C works pretty well, but it could definitely be improved in a meaningful way. Personally, I think it's just about time for a good C replacement, and Zig's goals are perfect for that.
- ndh2 9y agoWe also have enough naysayers and party poopers trying to discourage language authors. Yet here you are...
- srean 9y agoI wish I could upvote this enough.
- eggy 9y agoI 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.