Earlier quoted context omitted.
While I agree with the content of your post literally, I think we often underestimate the importance of software reliability and performance, and end up giving it less attention than it deserves. I understand the place for rapid prototyping etc., and that not every software application deals with life-and-death situations — but even those that aren’t, I think our industry suffers a bit here. For example, to this day…
In over 6 years working in this industry, in projects with anywhere from dozens of users to millions of users, not a single bug I have encountered was caused by a "hidden allocation" causing the process to go OOM. Not one instance. One of the two examples he cited in his introduction, the Android one, wasn't even caused by an unhandled OOM error. Android by design will kill unused processes if they're occupying memor…
Zig: software should be perfect [video]
61–70 of 141 posts
Re: Zig: software should be perfect [video]
#62Earlier quoted context omitted.
Come on, a title like that isn’t meant to be taken too seriously. And you’re reaching a bit far. You can write a perfect function that adds two 32 bit integers. There is a subset of code that can be written perfectly. Especially if you don’t need Turing completeness to write it. Zig just tries it’s best to make it easy to write as much as possible of low level code in a perfect way.
> You can write a perfect function that adds two 32 bit integers. how ? the problem of adding two 32 bits integers is itself imperfect since you may at some point have big integers to sum, so any solution is inherently flawed, too
Given two 32-bit signed integers, produce a 32-bit signed integer that is a sum of the inputs; if the sum doesn't fit into 32 bits, wrap modulo 32 bits.
Given two 32-bit signed integers, produce a 64-bit signed integer that is a sum of the inputs.
Given two 32-bit signed integers, produce either a 32-bit signed integer that is a sum of the inputs if it fits into 32 bits, or an error code indicating that it did not fit.
The problem with languages like C is that they let you be imprecise and get away with in. If you just run with "add two signed 32-bit integers", and implement it as "x + y" in C, it will compile, and it will run, but the result is undefined behavior if it overflows (note: it doesn't even mean that you get the wrong value - it can literally do anything at all). In Zig, if you write it as "x + y", it will panic on overflow, which is at least well-defined and fails fast; and the language provides you with tools to implement any of the three properly defined scenarios above in straightforward ways (i.e. you can add with wraparound, or you can add with an overflow check).
Re: Zig: software should be perfect [video]
#63Earlier quoted context omitted.
There are still plenty of exceptions that are unchecked, i.e. subtypes of RuntimeException, which do not have to be declared on the callee. As well as people who think it's a good idea to throw instances of Exception and just tack a "throws Exception" on their methods.
Right — that's a failing of Java the language; not the concept of checked exceptions. At least one problem with Java's exception model that Zig does not have is that some exceptions are "unchecked."
Re: Zig: software should be perfect [video]
#64Re: performance claims, I wonder if the C sha256 implementation would have been more competitive with -march=native -mtune=native?
Why isn't `-march=native -mtune=native` enabled by-default for every piece of software compiled unless explicitly specified otherwise?
Re: Zig: software should be perfect [video]
#65Earlier quoted context omitted.
Come on, a title like that isn’t meant to be taken too seriously. And you’re reaching a bit far. You can write a perfect function that adds two 32 bit integers. There is a subset of code that can be written perfectly. Especially if you don’t need Turing completeness to write it. Zig just tries it’s best to make it easy to write as much as possible of low level code in a perfect way.
> You can write a perfect function that adds two 32 bit integers. how ? the problem of adding two 32 bits integers is itself imperfect since you may at some point have big integers to sum, so any solution is inherently flawed, too
Smalltalk solves that problem by promoting the result to arbitrary precision arithmetic. It does the same for integer division. For example, 5 / 2 returns a Fraction, not an Integer.
Re: Zig: software should be perfect [video]
#66I've wanted a language like this. Java's checked exceptions with some way to offload the bookkeeping to the compiler. What about other run-time exceptions, like divide by zero? Are they checked? What about Hoare's billion-dollar mistake (null pointer exceptions)? Does Zig have non-nullable references?
Pointers can not be null. However you can have optional pointers which are guaranteed to use the 0x0 value as null and have the same size as normal pointers.
Re: Zig: software should be perfect [video]
#67Earlier quoted context omitted.
Why isn't `-march=native -mtune=native` enabled by-default for every piece of software compiled unless explicitly specified otherwise?
Because your cpu has a base ISA, plus extensions. The compiler doesn't know if you're going to only run this binary on your machine, or distribute it to others that may share your base ISA but possibly not your extensions, so it takes the conservative approach and doesn't use them unless signaled to do so via those compiler flags. Also, I think -march implies -mtune.
Re: Zig: software should be perfect [video]
#68Re: performance claims, I wonder if the C sha256 implementation would have been more competitive with -march=native -mtune=native?
I think it would. I posted some observations on this the last time this video was discussed: https://news.ycombinator.com/item?id=17187140 My hypothesis is that Zig's compiler passes the equivalent of -march=native to the backend, which is why it should also be given to the C compiler to give a fair comparison (and a speedup of 30% or so).
Re: Zig: software should be perfect [video]
#69I've wanted a language like this. Java's checked exceptions with some way to offload the bookkeeping to the compiler. What about other run-time exceptions, like divide by zero? Are they checked? What about Hoare's billion-dollar mistake (null pointer exceptions)? Does Zig have non-nullable references?
Re: Zig: software should be perfect [video]
#70Such a language could be visualized as strict-by-default Haskell (with type-classes, uniform pattern-matching, minimalist syntax - everything, except monads) plus ideas from Erlang, Go and Ocaml.
Perfection and imperativeness, it seems, does not match.