13 ms·
Ziglings: Learn the Zig programming language by fixing tiny broken programs
- leetrout 6y agoI wish these types of projects would identify themselves as koans in the README or something. Makes it much easier to surface exercises like this when googling. I think this is the best way to learn languages. Does anyone know of any for TypeScript?
- jamesholden 6y agoI saw your comments and I was thinking to myself.. "They should have one for Regex (regular expressions). That would be a cool way to learn it." Apparently someone did. ¯\_(ツ)_/¯ TIL https://regex101.com/ https://regex101.com/
- markbnj 6y agoI have regex101 open in a tab any time I am developing a regex :). It's an awesome tool, and I especially appreciate the mini language reference in the lower right corner of the window.
- nick__m 6y agoRegex101 is especially useful, I use it to check for catastrophic backtracking¹ before committing a regex. 1-https://www.regular-expressions.info/catastrophic.html https://www.regular-expressions.info/catastrophic.html
- yarinr 6y agohttps://github.com/typescript-exercises/typescript-exercises https://github.com/typescript-exercises/typescript-exercises
- BasedInfra 6y agoNever heard of koans before, it’s a brilliant idea for learning a new language. Opportunity for a index or site for koans.
- danpalmer 6y agoKoans are a fairly well-known technique, and if you Google "<language> koans" you'll find something for most languages. I like it as a learning style.
- gmfawcett 6y agoLet's hope that nobody invents a language called Zen -- they will run into problems. :)
- kristoff_it 6y agoif you want to have a laugh, check the news section of ziglang.org. There was also a pretty big discussion on HN at the time.
- gmfawcett 6y agoHah! I didn't know of any Zen languages -- just to find one a stone's throw away from Zig. Thanks for pointing that out. (And that news story... what an absolute mess of a situation.)
- maddyboo 6y agoI love these sorts of resources! I just created an "awesome list" [1] to keep track of resources specifically centered around learning by example. I've only got a few so far, several of them being from this thread. Contributions welcome! [1]: https://github.com/b0o/awesome-by-example https://github.com/b0o/awesome-by-example
- davegauer 6y agoYou're absolutely right. My own first exposure to this type of learning resource was Ruby Koans. I believe Rustlings (which was my direct inspiration) also credits RK. I'll update the README with the grandparent attribution. :-)
- haberman 6y agoNeat concept. Exploring the difference between what successfully compiles vs. what won't seems like a great way of getting more familiar with the language. I've written a little over 1,000 lines of Zig at this point and I really like it. I think its key feature is a rich compile-time imperative programming environment ("comptime"). If you can have full compile-time imperative code execution, you can get a lot of the benefits of more complicated language features (like C++ templates) "for free." In C++ templates are "a language within a language", but even templates with all their complexity cannot solve all of the problems you might want to solve at compile-time, so C++ has been gradually expanding its compile-time code execution features so that more and more of the language is available at compile-time (constexpr, consteval, etc). Zig jumps straight to the finish line by making most of the language available at compile-time from the outset, and in doing so avoids the need to add the complexity of templates in the first place. Having "slices" as a first class type feels like a general and powerful solution to the problems that std::string_view and std::span are trying to solve. I am comparing Zig to C++ a lot, which many Zig fans would probably take exception to as Zig does not aspire to be a better C++, but rather a better C. Indeed many key C++ patterns like RAII are explicitly out of scope. But to me Zig bridges the gap between C and C++ by solving many of the problems that make C feel too spartan without jumping to the incredible complexity of C++. There are a few things about Zig that give me pause. I've noticed that compile-time feels like a very lazy environment, meaning that functions do not seem to undergo full semantic analysis unless they are called from somewhere. You can write a function that compiles successfully, leading you to believe the function is syntactically and semantically coherent, only to find that when you add an actual call to that function, the compiler now flags errors inside that function. This adds some friction to development, because the act of writing a function is no longer a self-contained activity. Writing the function feels more like sketching it; later when you actually call it you have a new set of compile errors to contend with. I also miss tools like ASAN to catch memory errors. I'm guessing things like that will come with time. Overall I feel very positive on Zig.
- fpoling 6y agoZig compile-time evaluation even allows to construct an arbitrary type like a struct with a platform-specific members all using the same core language. This beats even Rust macros and in retrospect I wonder why this not used in other languages? Even Lisp ended up with macros with own sub language instead of making the core language more useful for code generation. Or consider Go attempts at generics. Something like Zig approach will fit it more I think than various generics proposals.
- jedisct1 6y agoThis is a very good idea! A nice way to discover a very promising language.
- smallstepforman 6y agoI’m interested in exploring Zig, but the draconian measure to ban hard tabs is pushing me (and many others from what I’ve read online) away from it. Andrew, get off your high horse, allow hard tabs, and we can all join hands and work together.
- mssundaram 6y agoYou're saying this from atop your own high horse. I used to fight about prettier (js) gofmt and so on. I just finally found I don't care. It's more fun to just code and watch it all get autoformatted to the project or language standard
- smallstepforman 6y agoThe reason hard tab people dislike code editors which convert to spaces is that pressing backspaces during editing removes one space, not all auto-inserted spaces. This ends up being very frustrating (since you need to press backspace 4 times). Most “used” languages allow both. Accept tab as another white space character and life goes on. Compile errors for hard tabs is a stubborn decision.
- dnautics 6y ago> The reason hard tab people dislike code editors which convert to spaces is that pressing backspaces during editing removes one space, not all auto-inserted spaces This is simply not the case for any editor I have used recently.
- sedatk 6y agoIn addition to this, "de-indentation" can be achieved with Shift-Tab instead of backspace.
- kortex 6y agoAny editor worth it's salt will indent with tab and de-indent with shift tab with the cursor at the first non whitespace. Any good editor will de-indent with the cursor anywhere on the line.
- deleted 6y ago[deleted]
- yoshuaw 6y agoHeh fun: this was inspired by Rustlings, which in turn was inspired by NodeSchool. Mozilla Berlin used to host NodeSchool and the Rust Hack & Learn evenings. It became a bit of a hang spot, and at some point we had a pretty consistent group of folks who'd go to both. Marisa realized Rust could use something similar to NodeSchool, and started hacking on Rustlings during these evenings — which now a few years later has really taken off! It's really cool to now see other languages in turn be inspired and follow from Rustlings ^^
- dleslie 6y agoI really wish zig were a gcc frontend; the m68k and sh2 targets available in gcc make it desirable for a certain form of hobby programming.
- danielEM 6y agoC target would solve it, I would be happy to use it with sdcc
- dleslie 6y agoHa, making gameboy games in zig would be neat.
- Bekwnn 6y agoI'm not sure on the specifics of what you mean, but zig comes bundled with and wraps gcc. `zig cc` command directly forwards to gcc (try `zig cc --version`) and zig's build system can be used to build C programs. Zig currently is able to target quite a bit. There's a good chance you could open an issue and it would get added, or find an existing issue and see where it is on the roadmap.
- dleslie 6y agoI was under the impression it was limited to llvm supported targets; of which m68k is not officially supported.
- travisgriggs 6y agoI keep meaning to look into zig more. Can it be used for embedded chips like M0s yet? I'd love to hear if anyone's cross compiling to embedded chips in any real projects with it. Or it's strongest play still command line tools on Linux?
- hansvm 6y agoZig is still "not production ready," embedded is still rough, and you might have to contribute to Ziglang itself to get any particular architecture working appropriately. That said, yes people are using Zig a little for embedded stuff: https://codelv.com/blog/2020/5/using-zig-and-the-stm32h7-to-drive-stepper-motors https://codelv.com/blog/2020/5/using-zig-and-the-stm32h7-to-... https://www.mdeditor.tw/pl/2Ap9 https://www.mdeditor.tw/pl/2Ap9 Xtensa is less supported. M0 might also have some issues: https://github.com/Schroedingers-Hat/xtensa-zig https://github.com/Schroedingers-Hat/xtensa-zig I've been meaning to try it out for embedded myself; I'll let you know how it goes.
- account-5 6y agoIf I wanted, as a complete novice, to learn a lower level language, where would be the best place to start. I always get confused by all these new languages. Ive heard of: nim, rust, D, V, and now Zig. Where do I start? Should I start with C or C++? Or pick one of these? But which one? Im currently looking at Lisp because I read it was good for alot of things. I'm also aware of Go and Swift but not looked into them at all.
- tigerlily 6y agoDepends what you want to do. Starting with C is good, because then you get to learn the pitfalls, and hence understand the problems the other languages solve, and their advantages and disadvantages.
- kilburn 6y agoWhat's your goal? Why do you want to learn a "lower level" language? Do you have experience in "higher level" languages? I would say that a better approach in your case is to start by saying "I want to write programs to solve problems like XXXX", or "I want to learn a language that lands me a job doing YYYY". For example, if you want to: - build network services -> golang - fiddle with OS level stuff (schedulers, memory management, etc.) -> C - write high performance calculation/simulation programs -> julia - get a nice solid base that can cover most of the above and has a promising future -> rust Nim, D, V, Zig are very niche and I wouldn't recommend as a first "lower level" language (because you'll have a harder time finding answers, and they won't give you clear benefits over the other options in any problem space). C++ is... huge. Modern C++ is a fine language, but you'll have to learn a lot to be able to handle it.
- account-5 6y agoIm not what I consider a programmer though I can program. Ive most experience with Python, on Linux I use shell scripts but am no expert. On windows I use AutoHotKey, though I know most wont consider it a proper language. My main aim is really to learn about it. I wouldnt mind having a broad general experience in high level and low level before I decide to focus on anything in particular. I've started looking a compilers and how they work im working through a book about building a compiler. Im really just interested in whats going on in the background. I always find myself wondering about the implementations of the languages I'm using.
- aequitas 6y agoTo bad testing[0] isn't introduced in any of the examples. As breaking the compile step only get's you so far with generating interesting challenges. [0] https://ziglang.org/documentation/master/#Zig-Test https://ziglang.org/documentation/master/#Zig-Test