7 ms·
I was also curious what direction the article was going to take. The showcase is cool, and the features you mentioned are cool. But for me, Zig is cool is becau
by badtuple 10mo ago
I was also curious what direction the article was going to take. The showcase is cool, and the features you mentioned are cool. But for me, Zig is cool is because all the pieces simply fit together with essentially no redundancy or overloading. You learn the constructs and they just compose as you expect. There's one feature I'd personally like added, but there's nothing actually _missing_. Coding in it quickly felt like using a tool I'd used for years, and that's special.
Zig's big feature imo is just the relative absence of warts in the core language. I really don't know how to communicate that in an article. You kind of just have to build something in it.
- rvrb 10mo agoout of curiosity, what feature do you want?
- brucehoult 10mo agoThe feature I want is multimethods -- function overloading based on the runtime (not compile time) type of all the arguments. Programming with it is magical, and its a huge drag to go back to languages without it. Just so much better than common OOP that depends only on the type of one special argument (self, this etc). Common Lisp has had it forever, and Dylan transferred that to a language with more conventional syntax -- but is very near to dead now, certainly hasn't snowballed. On the other hand Julia does it very well and seems to be gaining a lot of traction as a very high performance but very expressive and safe language.
- zevets 10mo agoI think this is a major mistake for Zig's target adoption market - low level programmers trying to use a better C. Julia is phenomenally great for solo/small projects, but as soon as you have complex dependencies that _you_ can't update - all the overloading makes it an absolute nightmare to debug.
- pjmlp 10mo agoAda has them, and I guess we all agree on its systems programming nature.
- brucehoult 10mo agoNOOOO! What Ada (and Rust) calls generics is very different -- it is like template functions in C++. In those languages the version of the function that is selected is based on the declared type of the arguments. In CLOS, Dylan, Julia the version of the function that is selected is based on the runtime type of the actual arguments. Here's an example in Dylan that you can't do in Ada / Rust / C++ / Java. define method fib(n) fib(n-1) + fib(n-2) end; define method fib(n == 0) 0 end; define method fib(n == 1) 1 end; The `n == 1` is actually syntactic sugar for the type declaration `n :: singleton(1)`. The Julia version is slightly more complex. fib(n) = fib(Val(n)) fib(::Val{n}) where {n} = fib(n-1) + fib(n-2) fib(::Val{0}) = 0 fib(::Val{1}) = 1 println(fib(30)) This is perhaps a crazy way to write `fib()` instead of a conventional `if/then/else` or `?:` or switch with a default case, but kinda fun :-) This of course is just a function with a single argument, but you can do the same thing across multiple arguments. define method ack(m, n) ack(m-1, ack(m, n-1)) end; define method ack(m == 0, n) n+1 end; define method ack(m, n == 0) ack(m-1, 1) end;
- pjmlp 10mo agoYou missed the way Ada does OOP, and went completely overboard talking about generics. As you can see from my comment history, I am quite aware of CLOS, Lisp variants and Dylan.
- brucehoult 10mo agoLast I checked, Ada does not have multimethods/generic functions in the sense of CLOS, Dylan and Julia. It has static function overloading, and single-argument dispatch, just like C++.
- SatvikBeri 10mo ago
- fuzztester 10mo ago>The feature I want is multimethods -- function overloading based on the runtime (not compile time) type of all the arguments. >Programming with it is magical, and its a huge drag to go back to languages without it. Just so much better than common OOP that depends only on the type of one special argument (self, this etc). Can you give one or two examples? And why is programming with it magical?
- brucehoult 10mo agoFor a start it means you can much more naturally define arithmetic operators for a variety of built in and user-defined types, and this can all be done with libraries not the core language. Because methods aren't "inside" objects, but just look like functions taking (references to) structs, you can add your own methods to someone else's types. It's really hard to give a concise example that doesn't look artificial, because it's really a feature for large code bases. Here's a tutorial example for Julia https://scientificcoder.com/the-art-of-multiple-dispatch https://scientificcoder.com/the-art-of-multiple-dispatch
- fuzztester 10mo agoThanks.
- nomdep 10mo agoErlang/Elixir also has that
- badtuple 10mo agoSomething akin to interfaces, but weaker. Right now people roll their own vtables or similar, and that's fine...I actually don't expect these to be added. But because of Zig's commitment to "everything structural is a struct", a very very simple interface type would likely end up being used more like ML's modules. The need for this jumped out at me during Writergate. People had alot of trouble understanding exactly how all the pieces fit together, and there was no good place to document that. The documentation (or the code people went to to understand it) was always on an implementation. Having an interface would have given Zig a place to hang the Reader/Writer documentation and allowed a quick way for people to understand the expectations it places on implementations without further complications. For Zig, I don't even want it to automatically handle the vtable like other languages...I'm comfortable with the way people implement different kinds of dynamic dispatch now. All I want is a type-level construct that describes what fields/functions a struct has and nothing else. No effect on runtime data or automatic upcasting or anything. Just a way to say "if this looks like this, it can be considered this type." I expect the argument is that it's unnecessary. Technically, it is. But Zig's biggest weakness compared to other languages is that all the abstractions have to be in the programmer's head rather than encoded in the program. This greatly hampers people's ability to jump into a new codebase and help themselves. IMO this is all that's needed to remedy that without complicating everything. You can see how much organizational power this has by looking at the docs for Go's standard library. Ignore how Go's runtime does all the work for you...think more about how it helps make the _intent_ behind the code clear.
- andai 10mo agoYeah, the real strength of Zig isn't what's there, but what isn't.
- KingMob 10mo agoOK, but this is true for most younger languages. The older they get, the more they tend to accumulate. Check back in on Zig after another decade.
- smj-edison 10mo ago> Coding in it quickly felt like using a tool I'd used for years, and that's special. That's been my exact experience too. I was surprised how fast I felt confident in writing zig code. I only started using it a month ago, and already I've made it to 5000 lines in a custom tcl interpreter. It just gets out of the way of me expressing the code I want to write, which is an incredible feeling. Want to focus on fitting data structures on L1 cache? Go ahead. Want to automatically generate lookup tables from an enum? 20 lines of understandable comptime. Want to use tagged pointers? Using "align(128)" ensures your pointers are aligned so you can pack enough bits in.
- dragonelite 10mo agoHaving spend a year tinkering in zig and it's absence of features has made me want to drop c#/java professionally and pick up Golang. Its quiet annoying when you see a codebases written in C#/java and you can tell in which year/era it was written because of the language features. The way of writing things in C# changes like every 4 years or so. There's a certain beauty in only having to know 1~2 loops/iteration concepts compared to 4~5 in modern multi paradigm languages(various forms of loops, multiple shapes of LINQ, the functional stuff etc).
- pjmlp 10mo agoYou already have have Go, before and after modules, before and after generics, before and after ranges over function types. Skipping other minor changes. However I do agree C# is adding too much stuff, the team seems trying to justify their existence.
- dragonelite 10mo agoThats true with Go but it feels those features are more rare. Compared to say what feels like almost yearly changes in C# to the point a lot of people think its overwhelming and it usually not clear how much of those features really add to the language and dev experience. My experience with Golang so far is biased because i only recently looked at golang, for the past decade i have been working mostly in java and c#, so most of those newly added features in golang is stuff i'm already deeply familiar with conceptually.