Live data from Hacker News

Zig, the Small Language

zserge.com

41–50 of 429 posts

Re: Zig, the Small Language

#41
post #6

why should I use Zig coming from Python/Go ?

Another use case aside from the typical "high perf" ones: if you're building a cross-platform library with bindings in various language (eg. Swift bindings, Kotlin, C#, etc.), I'd imagine you'd benefit in the long run from having manual memory management and a thin runtime that doesn't clash with the host runtime. But personally I'd choose C/C++ for this, for the sake of existing support in writing bindings and C interoperability.

Re: Zig, the Small Language

#42
What is the appeal of small languages?

If it's simplicity, it seems like complex programs would be supported by complex libraries instead of complex language features, leading to the same level of complexity but with less consistency.

"Smallness" seems to be a sought after feature but I'm not sure why.

Re: Zig, the Small Language

#43
I don't know Zig, but aren't we missing a return here?

  fn count_nonzero(a: []const i32) i32 {
    var count: i32 = 0;
    for (items) |value| { // "for" works only on arrays and slices, use >"while" for generic loops.
       if (value == 0) {
        continue;
     }
    count += 1; // there is no increment operator, but there are shortcuts for +=, \*=, >>= etc.
   }
  }

Re: Zig, the Small Language

#44
post #7

Zig indeed is pretty nice, i just wish it had some more sweet to it - my math type with + - * / overloads - simpler way to fill an array, i can never remember the syntax, it doesn't feel natural `[_]u8{0} * 10;` - smarter type system, i am tired of casting everything twice A good language is not a language set in stone, a good language is a language that doesn't make me feel like i have to suffer because they made a…

"In the beginning the [operator overloading] was created. This has made a lot of people very angry and been widely regarded as a bad move." But in all seriousness that's pretty much antithetical to zig's goals regarding explicitness.

D initially wasn't going to do operator overloading, mainly because C++ iostreams was a disaster (in my not-so-humble opinion) as well as the awfulness of overloading operators to create a DSL.

But I wound up being convinced that on balance it was a good thing. But I was able to inculcate a culture that operator overloading should be restricted to the creation of user arithmetic types.

Not allowing the overloading of unary *, &, and dot also help discourage non-arithmetic overloading.

Re: Zig, the Small Language

#45

Earlier quoted context omitted.

if we can do 1 + 1, we should be able to do vec2 + vec2, same with mat4 * mat4 Odin proved it that it can be made efficiently while keeping sanity

> if we can do 1 + 1, we should be able to do vec2 + vec2, same with mat4 * mat4 why? operator overloading doesn't help you solve any problems. you can have the readability with methods which are named appropriately. operator overloading seems so powerful and useful until you realize one day that it only changes the appearance of things, and makes no difference whatsoever to anything you are actually doing.

i'm not asking for operator _overloading_, i am asking for having operators for my math types

Re: Zig, the Small Language

#46
post #16

why do people care about binary size? I have never understood this. Disk space isn't free but the size of the binaries on my machine doesn't seem like a big problem to me in that regard.

It's usually not the disk space that's the bottleneck, but rather, the CPU instruction cache. On modern Intel and AMD CPUs, the jump from L1 -> L2 alone can triple the latency of a memory fetch. For a "hello world" application, that doesn't really mater, but for, say, an OS kernel, it becomes really important to keep as much of your hot-path code in i-cache as possible.

Re: Zig, the Small Language

#47
post #16

why do people care about binary size? I have never understood this. Disk space isn't free but the size of the binaries on my machine doesn't seem like a big problem to me in that regard.

I can't speak for others, but I care about binary size as a user because it tends to be a reliable signal of overall software quality (though there are definitely exceptions).

I also find it incredibly frustrating when an application I rarely use fails to launch because it wants to force me to download, process and install massive updates for features that I don't even want.

As an engineer, I care about binary size because gigantic binaries tend to require far more time to compile, move around and work with. Gigantic binaries tend to be a reliable signal of slow, toxic, internal processes that chew up positive energy and produce cynicism and frustration in it's place.

It's not about the disk space per se, it's about treating waste as if it's a virtue.

Re: Zig, the Small Language

#48

I tried Zig recently but I found the unsilenceable lints to be a huge productivity killer. I actually posted a link to the GitHub issue this morning. https://news.ycombinator.com/item?id=32751317 This makes a normal workflow with `watchexec zig test` basically impossible, since before I can even run the tests I have to spend time hunting down which variables are used/unused at the moment and (un)commenting them. And…

> I do understand the reasoning (they don't want people committing poor quality code), but this implementation just seems completely backwards to me. It breaks the natural order. It's like saying we won't let you ctrl+s until your tests pass to make sure you don't commit broken code. Stop nannying me and let me get my work done!

Could it be that this problem is due to Zig's stance on "no warnings"? It's admirable to try and partition things into strict "correct" and "incorrect" categories. But with only static information it seems like there's always things that seem a little grey.

Re: Zig, the Small Language

#49

Earlier quoted context omitted.

if we can do 1 + 1, we should be able to do vec2 + vec2, same with mat4 * mat4 Odin proved it that it can be made efficiently while keeping sanity

> if we can do 1 + 1, we should be able to do vec2 + vec2, same with mat4 * mat4 why? operator overloading doesn't help you solve any problems. you can have the readability with methods which are named appropriately. operator overloading seems so powerful and useful until you realize one day that it only changes the appearance of things, and makes no difference whatsoever to anything you are actually doing.

readability is important. specifically, operator overloading is great because it makes code look more like math. when translating from math to code, this is highly useful.

Re: Zig, the Small Language

#50

Earlier quoted context omitted.

if we can do 1 + 1, we should be able to do vec2 + vec2, same with mat4 * mat4 Odin proved it that it can be made efficiently while keeping sanity

The thing about operator overloading is that it was abused during one of the worst era of C++. And vec2 + vec2 can probably be unambiguously translated to assembly code while mat4 * mat4 is an other story. In most cases it should be a function call, and not a trivial one, with SIMD it can be relatively fast but still several orders of magnitude slower than 1 + 1. (we're talking about more than 500 scalar-equivalent o…

> I prefer when the function call is explicit, it is a bit more cumbersome to write, but there is less hidden complexity.

you hide and obfuscate basic operations with functions, that's worse, specially when you have to chain arithmetic operations, with functions it becomes ugly and unreadable

Post reply on HN