188 points · by WendigoJaeger · 6y ago · 103 comments
It's cool that you got the built-in linker to work. When I tried, I got a bunch of "unsupported architecture" errors and had to use GNU ld. Have things gotten better recently or is this an ARM-vs-Thumb thing?
I was excited to be able to use packed structs to represent the different IO registers -- at last, no more OR-ing the wrong flag into the wrong register! -- but unfortunately those don't quite work right on ARMv4T yet: https://github.com/ziglang/zig/issues/2767
Also the integer overflow section struck me as kinda odd - what if I want wrapping behavior? That's not exactly a super uncommon scenario.
When you want arithmetic to wrap, you should use some way to explicitly denote that you want it to wrap. (I think it could look like an operation with a modulo reduction or mask applied to it.)
defer is way more transparent than RAII, because your code is right there in the function call, not hidden in a pile of classes that might change underneath.
>defer is way more transparent than RAII, because your code is right there in the function call, not hidden in a pile of classes that might change underneath.
I mean, sort of? It seems way less composable though, if you have an object which contains 5 different resources, now you have to defer 5 things? How does this interact with return values, if you defer file.close() for example but return the file, does it still get closed? And if you have a heap allocated array of those objects, where objects get inserted at different places, defer doesn't work at all anymore, since it's just bound to function scope? Because that's usually the scenario that can be annoying to handle in C (opposed to just closing whatever was opened in the same function scope), so it seems a bit odd to me to kind of violate that "no hidden control flow" principle for something that doesn't even solve the primary issue that C resource handling has.
https://www.youtube.com/watch?v=Z4oYSByyRak
(good watch)
https://www.youtube.com/watch?v=Gv2I7qTux7g
A lot has changed since then, and a lot has changed since that Localhost talk. To catch up:
* (the older talk happened here)
* 0.3.0 release notes - https://ziglang.org/download/0.3.0/release-notes.html
* 0.4.0 release notes - https://ziglang.org/download/0.4.0/release-notes.html
* (the newer talk happened here)
* 0.5.0 release notes - https://ziglang.org/download/0.5.0/release-notes.html
https://duckduckgo.com/?q=site%3Anews.ycombinator.com+zig+la...
But Game Boy Advance games don't really fit that description. GBA games don't accept untrusted input, and nothing bad happens if they're "compromised". (Like, when people discovered arbitrary code execution in Super Mario World, no one was worried about the security implications.) So languages like C or Zig that let you cowboy values directly into specific memory locations can be a better choice.
I'm excited about Zig in particular because the mission statement seems to be "C but nicer" -- you get the same basic programming model, but with things like instance methods, generic types, better macros, arbitrary-bit-integer types and a "crash when hitting undefined behavior" compile mode.
Swift fills that slot, but only on Apple platforms. Linux hardly has portable support even for file access and Windows will get supported some day, and most 3rd party libraries assume Apple anyway.
D has a great community, but still found lacking in some areas.
.NET AOT compiled with the learnings taken from System C# (7.x - 9) is the closest for my daily coding activities.
Ideally Delphi like with automatic memory management.
Or maybe having a Rust IDE with visual representation of lifetimes would already be productive enough.
I would say why I really like Zig is because the minimalism of C is still there in the syntax and it makes a whole lot of very smart choices to keep this simplicity while being so much more expressive than C.
If you really need some Rust pro's I would say it is great as the language that finally brings more of ML and functional ideas into high performance programming. Most languages nowadays have fp things but Rust has it very deep into its core. Other than that it is great to see proof systems reaching the mainstream and the security guarantees its ownership system gives is great.
0.5.0 Documentation https://ziglang.org/documentation/0.5.0/#Introduction
root std library https://github.com/ziglang/zig/tree/master/lib/std
examples of writing and reading to a file https://github.com/ziglang/zig/blob/master/lib/std/event/fs....
There are also a ton of projects that the creator has done with Zig, you can check those out for more examples as well.
https://github.com/andrewrk?utf8=%E2%9C%93&tab=repositories&...
Looks like he has an advent of code repo too.
Documentation for Zig isn't great, but it's become much easier now that the standard library is searchable: https://ziglang.org/documentation/master/std
1. https://www.youtube.com/watch?v=hBCsWEQ_asM&list=PLviMr_WImM...
* How dependent on libc is Zig, if at all?
* What kind of runtime expectations does Zig have? Does it need a malloc, for example?
* How big is its standard library?
* Is it possible to write code without its standard library?- Zig has no hard dependency on libc, it's the user's choice whether he wants to link it or not. It ships musl libc and can build/link it for most (all?) supported targets.
- Most of Zig's standard library works on freestanding targets. No runtime needed. There are no implicit allocators, so the user must use an allocator shipped with the standard library or implement their own.
- Standard library is still in its early days but already provides a lot of functionality out of the box, from containers to io.
- Using the standard library is optional. When it is used, only what is used gets included. The standard library is built from source every time (though there is caching) and its semantic analysis basically does LTO in the codegen stage so you end up with pretty slim binaries.
Here's a couple of examples:
* How dependent on libc is Zig, if at all?
* What kind of runtime expectations does Zig have? Does it need a malloc, for example?
* How big is its standard library?
* Is it possible to write code without its standard library?
The impression I've gotten is that the GBA is powerful enough that you can write most of your programs in C, but some performance-critical stuff (like if you're trying to draw pixels directly instead of using the sprite/tile hardware) is best written in assembly. If you're interested in learning more, I would highly recommend this tutorial: https://www.coranac.com/tonc/text/toc.htm
I'd say it's one of the best systems to get into on-the-metal Homebrew.
There’s more potential complexity if you want to do complex things and maybe 3D is hard (I’ve never done it) but the basics are about as straightforward.
On top of that, DS cartridges are 8 - 512 MB.
Personally, I value that aspect highly because it means if I choose to work with a language that I can understand, read, and possibly contribute to the compiler if needed.
You would have about the same if the compiler were written in a lingua franca. For whatever it's worth, I have in the past had to work inside the gfortran compiler, and I wouldn't have been able to do that if it were written in Fortran.
Self-hosting (which nowadays often isn't "full" self-hosting, it's implementing a frontend and possibly parts of a mid-end only and letting a framework like GCC or LLVM do the rest) is useful because it proves that it has reached a certain level of maturity, as you say. Another advantage is that this gives you a non-trivial piece of software written in the language which can be used for testing and benchmarking. If you introduce a compiler bug, there is a certain likelihood that you will notice it immediately. This might not be the case if you only had small toy programs to test with.
Really pining for a non backlit display I control.
Never thought this would be possible but given the readable code...maybe I should try?! Anybody know where I could start?
Other ones are Android based, so there you can use it via NDK.
I suggest putting the README images in a doc directory so visitors know at first glance that they aren't part of the app.
But all in all from my time following both for several months they have a lot of similarities. They're only slightly more different than one another than C# and Java.