C3 looks promising, but any language that supports nulls needs null-restricted types, not whatever those contract comments are. If I wanted to have to null-check everything, or YOLO it, I would just write Java... and even Java is seeking to fix this: https://openjdk.org/jeps/8303099
I'm on the fence about function contracts like this. I've seen them for a decade in other languages, but never really used them, so I can't say how I feel about them. But having them be inside comments is just weird.
Learning C3
61–70 of 163 posts
Re: Learning C3
#62Re: Learning C3
#63Earlier quoted context omitted.
Indeed. There’s a port for macOS though. And yet out all these newer C-like languages, it looks like Hare probably takes the crown for simplicity. Among other things, Hare uses QBE[1] as a backend compiler, which is about 10% the complexity of LLVM. [1] https://c9x.me/compile/
QBE is an art project. Read the source.
Re: Learning C3
#64Earlier quoted context omitted.
the problem with picking C++ is that eventually you onboard someone who uses the warts in their code, and then the warts become like craft glitter.
Maybe instead of building a restricted C++ we should be building parsers that restrict what C++ features we use.
Re: Learning C3
#65> Don't misunderstand me - I love using foreach in other languages; the added syntax better expresses your intent, reducing logic errors. It did jump out at me as "this isn't C" though. Because it's not. The whole point of C is that you know exactly what's going on and it's relatively clear in the code itself. C++ hides logic in abstractions for the sake of convenience. This is a C++ thing. How does it know how to it…
Given the widespread undefined behavior and the ways that compilers aggressively rely on that to reorganize and optimize your code, that hasn't been the case for many many years.
Sure, if you're using dmr's compiler on a PDP-11, then C is a pretty transparent layer over assembly, which is itself a fairly thin layer over the CPU. But today, C is an ambiguous high level communication language for a highly optimizing compiler which in turn produces output consumed by deep pipeline CPUs that freely reschedule the generated instructions.
Re: Learning C3
#66Most of these features have been used by countless C++ developers for the past decades -- I really don't see the point in adopting a language that's mostly C++ but without some of the warts. Either pick C++ or something like Rust.
the problem with picking C++ is that eventually you onboard someone who uses the warts in their code, and then the warts become like craft glitter.
Unfortunately adhering to modern tooling is always a quixotic battle, even when they come for free on modern FOSS compilers.
Re: Learning C3
#67Earlier quoted context omitted.
It's an interesting problem. Originally I experimented with both having ` ` and `&` syntax, so `int&` being a ref (non null) and `int ` being a pointer. The thing you notice then are two things: 1. You want almost all pointer parameters non null. 2. Non-null variables is very hard to fit in a language without constructors. Approaches to avoid constructors/destructors such as ZII play very poorly with ref values as we…
> Approaches to avoid constructors/destructors such as ZII play very poorly with ref values as well. What you end up with is some period of time where a value is quasi valid - since non-null types need to be assigned and it's in a broken state before it's initially assigned. I don't see that as a problem; don't separate declaration from assignment and it will never be unassigned. Then a ZII non-null pointer is always…
That's tricky when you want to write algorithms where you can start with an uninitialized object and are guaranteed to have initialized the object by the time the algorithm completes. (Simplest example - create an array B which contains the elements of array A in reverse order.)
You can either allow declaring B uninitialized (which can be a safety hazard) or force B to be given initial values for every element (which can be a big waste of time for large arrays).
Re: Learning C3
#68C3 looks promising, but any language that supports nulls needs null-restricted types, not whatever those contract comments are. If I wanted to have to null-check everything, or YOLO it, I would just write Java... and even Java is seeking to fix this: https://openjdk.org/jeps/8303099
It's an interesting problem. Originally I experimented with both having ` ` and `&` syntax, so `int&` being a ref (non null) and `int ` being a pointer. The thing you notice then are two things: 1. You want almost all pointer parameters non null. 2. Non-null variables is very hard to fit in a language without constructors. Approaches to avoid constructors/destructors such as ZII play very poorly with ref values as we…
Re: Learning C3
#69Earlier quoted context omitted.
It's an interesting problem. Originally I experimented with both having ` ` and `&` syntax, so `int&` being a ref (non null) and `int ` being a pointer. The thing you notice then are two things: 1. You want almost all pointer parameters non null. 2. Non-null variables is very hard to fit in a language without constructors. Approaches to avoid constructors/destructors such as ZII play very poorly with ref values as we…
> Approaches to avoid constructors/destructors such as ZII play very poorly with ref values as well. What you end up with is some period of time where a value is quasi valid - since non-null types need to be assigned and it's in a broken state before it's initially assigned. I don't see that as a problem; don't separate declaration from assignment and it will never be unassigned. Then a ZII non-null pointer is always…
Otherwise it's quite straightforward that they have an uninitialized state (zero) and are then wired up when used. Trying to prevent null pointers here is something that the program to do. However, making the compiler guarantee without requiring constructors it is a challenge I don't know how to tackle.
Re: Learning C3
#70Earlier quoted context omitted.
It's an interesting problem. Originally I experimented with both having ` ` and `&` syntax, so `int&` being a ref (non null) and `int ` being a pointer. The thing you notice then are two things: 1. You want almost all pointer parameters non null. 2. Non-null variables is very hard to fit in a language without constructors. Approaches to avoid constructors/destructors such as ZII play very poorly with ref values as we…
the hacker news markdown parser seems to have swallowed your asterisks, which are essential to understanding your comment.