Comments by "" (@pierreollivier1) on "What's Zig got that C, Rust and Go don't have? (with Loris Cro)" video.

  1.  @_Karlsson  I'm curious now, like I can understand that one might not like Zig's syntax depending on your taste and background, I come from C so for me it's very familiar, and intuitive. Now for the ceremony part I've done some Java so I'm very much aware of the "ceremony fatigue" same with C++, I hate C++ for that reason, I'm tired of spending 5 minutes writing the same thing for each class definition. But in zig I really don't have that feeling, like it's not more verbose than C, it's actually less in a lot of ways, and C is well known to be simple. The stuff that's added is usually small and readable. For example in C when you have a complex struct with lots of dynamic memory allocation for the  initialization, you have to eitheir have a :  this->field3 = (field*) malloc(1 * sizeof(field)); if (this->field3 == NULL) { ....free(this->field1) ....free(this->field2) ....free(this) } and the thing gets longer and longer. or you have to use GOTO: label. in zig just :   errdefer allocator.free(this); and this is just a silly example but point being there's actually a lot of conveniences . Zig has done a fantastic job of making correct but hard thing in C trivial in Zig but easy and error prone stuff from C harder in Zig (like type casting for example, const vs var, unused variable or wrong type, exhaustive switch etc) So I would really appreciate if you could provide any example such that I could see if there is something that I'm missing, because I'm not sure where zig is more verbose ?
    3
  2. That's a feature not a bug imo, firstly all the syntax of the language can and will probably evolve, I remember Andrew saying that once the language is "stable" they will try to improve the syntax to make it more cohesive. But second one of the reason why you have to write a bit more code in Zig is because one of their moto is "no hidden control flow", the reason for this is that it makes the code more readable but it also offers a new capability which is that even people who never programmed in Zig can fairly easily read and understand what some zig code is doing I have one example of that I was working on a linter for C to autofix my style and I had a bug in the AST and a friend of mine who never coded in Zig was able to sit down with me and help me figured where the bug came from despite never seing any Zig prior to that, I don't think I would be able to do the same in C++, Rust or Haskell for that matter. The same thing can't be said about C++ templates, or Rust Macro, yet Zig comptime just read like normal code to anybody. One good exercise that I can advice you to try for yourself to understand how the explicitness of the language makes it trivial to read it, is to go into llvm compiler c++ codebase, pick a random part and try to understand what it does, then try going into a similar part of the Zig compiler codebase and understand what it does. The difference is the answer why it's a bit more verbose and less syntactically convenient. On top of that I don't think syntax should be a primary concern, the lifetime of any code is that you spend less than 10% of your time typing code, 90% reading it. Even for projects in teams at companies, your code will maybe take a few weeks or month to be written, but it will lives for years, so in the grand scheme of things I don't think that syntax is such a big deal especially if the trade off of weird syntax, enhances readability and maintainability at scale. Also you've mentioned C++ and Rust which in my opinion have both one of the ugliest and convoluted syntax that I know, in comparison zig feels simpler, but I guess it's familiarity.
    2
  3. 1
  4. 1
  5.  @_Karlsson  I get your point, but still can't really understand it, in my experience C end up more verbose when you try to make idiomatic and correct code. Because of dynamic memory allocation failure you always need to check if the pointer is valid and if not you need to either signal an error and do some cleanup or do the cleanup directly which in both cases is quite verbose. Probably 10 % of my code is just if (this == NULL) cleanup; and the lack of optional value makes it even more cumbersome to handle error correctly because as soon as one of your function does some memory allocation, it can fail and as such you need to check that where it's called we check and include some cleanup code, which ends up polluting everything. Also the fact that you don't have generics means you either have to write custom code for each data types, or use void* which is slower and ugly, or use header and casting which is dangerous, or use macro which is cumbersome, error prone and not easy to debug. Zig is not perfect of course, there's quite a few area where it's inconsistent at best and straight up weird in the worst case. But I really don't understand the "verbosity" complaint, like if you write even a small program like idk reimplenting cat, The same code in Zig is easier to follow, and quite a lot shorter, because it's easier to handle options, and arguments, it's easier to handle errors, and memory management is pretty much automatic with defer. The same code in C is ok I'm not saying it's bad but if you look at it there's a lot of verbosity involved in checking every pointers, and cleanup code everywhere, premature returns etc.
    1
  6. 1