HNHacker News
TopNewBestAskShowJobs

lerno

1,425 karma · joined April 1, 2014

submissionscomments
lerno··on Show HN: The C3 programming language (C alternative language)
I asked and got Bas's[1] permission to use C3 as a name when I first started out.

[1] Bas van den Berg, the author of C2.

lerno··on Show HN: The C3 programming language (C alternative language)
It is possible to use a single-header library as part of C3 libraries or your project. However, it must be noted that this will inhibit the ability to cross compile, as the compilation of the header is outsourced to the natively installed C compiler.

For that reason it's not an option for the standard library, but can certainly be useful for programs and libraries.

For faults, they are usually defined with `faultdef` which allows you to define one or more faults:

    faultdef SOMETHING_WENT_SIDEWAYS, BIG_OOPS;
Then you use them as if they were constants:

    if (x > 0) return BIG_OOPS?;
If they are defined in another module, say "foo::bar::baz", then:

    if (x > 0) return baz::BIG_OOPS?;
Using path shortening "foo::bar::baz::BIG_OOPS" would also be valid, but is not necessary nor recommended.
lerno··on Show HN: The C3 programming language (C alternative language)
C3 allows arbitrary extensions of any types, so things like `vec1.dot(vec2)` is actually implemented as a generic method macro over all vector types added by the math module.

Given Zig's preference for closed modules, I don't expect this to be on the roadmap, but rather would need to be implemented as functions.

lerno··on Show HN: The C3 programming language (C alternative language)
Back in the day when C's closest competitor was Pascal, C wasn't particularly hard to use. Pascal was easier for manipulating strings and C better at doing low level data manipulation.

But at the time there was little need for high level abstractions, and it was fine to just allocate an array with N number of entries and that was the maximum the program allowed.

Today we're dynamically allocating memory with intricate relationships, especially in object oriented programming.

This makes C look really hard to use – but it can actually be much improved with just an improved string library and a good dynamic array.

But there are also cross platform concerns for things like networking and here C offers little to help.

Regardless whether you're using Zig, C3 or Odin you're going to have a much easier time than C with straight up libc.

So I think a better comparison is that Zig is a bit like using the C++ containers. If you've ever struggled to mutate a std::vector while iterating over it, you know it's a bit complicated to figure out exactly what functions fit where.

The final solution might be performant, but it's a lot more to remember than say `iterator.remove_element()` that you might encounter in some other language. However, it does offer more ways to tweak it, and it's very explicit in what happens.

lerno··on Show HN: The C3 programming language (C alternative language)
No, they are the same.
lerno··on Show HN: The C3 programming language (C alternative language)
Ah, that is indeed true. However, the plan is to have the language fixed at 1.0, only updating stdlib and tooling after that.
lerno··on Show HN: The C3 programming language (C alternative language)
If you want to have your own Base32 where giving a padding = 0xFF instead returns an error, it's commonplace to have a wrapper that will explicitly do the check and return an error if it fails, and otherwise call the function:

    macro String? encode2(Allocator allocator, char[] src, char padding = DEFAULT_PAD, Base32Alphabet* alphabet = &STANDARD)
    {
        if (padding >= 0xFF) return INVALID_PADDING?;
        return encode(allocator, src, padding, alphabet);
    }
Maybe a better place to ask these questions are on the Discord if you have an account: https://discord.gg/qN76R87
lerno··on Show HN: The C3 programming language (C alternative language)
For grabbing the CPU features, there is some rudimentary implementation for x86 here: https://github.com/c3lang/c3c/blob/master/lib/std/core/priva... but not properly tested (which is to say, I would not count on it to work properly).

The `@require` here is creating a contract. You can't give a padding that is 0xFF, that's a programming error. However, you might have data which is invalid – in that case the typical error is INVALID_CHARACTER. To pass in a too small buffer is a programming error since the output buffer must be calculated first, so that's why that is not an error either. This was a deliberate change to make the API tighter.

So it's quite possible to add an "INVALID_LENGTH" error, but that should only be there in case one does encryption / decryption where the length cannot be easily determined beforehand i.e. it's part of the unknown input which the function determines. But in the Base32 implementation this is not the case. Either use it with an allocator for it to allocate sufficient memory for the data, or calculate that the buffer you pass in is big enough (or run into asserts if it isn't)

lerno··on Show HN: The C3 programming language (C alternative language)
Yes: https://c3.handmade.network/blog/p/8486-the_case_against_a_c...
lerno··on Show HN: The C3 programming language (C alternative language)
The hard thing is staying with the project. Lots of interesting C-like projects have died over time, such as https://www.kitlang.org
lerno··on Show HN: The C3 programming language (C alternative language)
I tried Zig in 2017-2018 span (and as part of research I've read quite a bit of Zig over the years). To me the language had some details not previously tried out: special operators for wrapping ops, error value based error returns and pervasive NPOT types. But overall it felt unnecessarily verbose with what I feel were unnecessary changes to established syntax in standard constructs such as "for" and "while". For this reason I started to contribute to C2 instead.

However, my impression was obviously coloured by being around 45 at the time and I was used to program in many different programming languages. Plus I grew up with BASIC, Pascal and C.

There's going to be quite a different experience for someone coming from Go/JS/Java and venturing into low level programming for the first time!

That is not to say that all of the people being enthusiastic about Zig is coming from those particular languages, but I think that C is considered a scary language for many people, so C alternatives tend to attract people from higher level languages to a higher degree than C itself.

When I eventually started on C3, I incorporated some features from Zig. I ended up removing all of them as I found them to be problematic: untyped literals combined with implicit widening, unsigned error on overflow, special arithmetic operators for wrap, saturation.

However, I am very grateful that Zig explored these designs.

From Odin I ended up including its array programming, but for vectors only. I also adopted Odin's use of distinct types.

But most of the C3 features are GCC C extensions plus ASTEC inspired macros.

lerno··on Show HN: The C3 programming language (C alternative language)
There is an overlap between module and class namespacing through static members and functions. Zig sees this and says "let's only have the latter" (on structs), which means among other things that in Zig a file is a structure. Most other languages says "let's have both".

In C3 it goes the other way despite having methods, and says "let's not allow static variables or methods".

This also goes hand in hand in the language approaches between open/close. Zig is very strongly "closed" and C3 is very much "open" (adding methods to types anywhere, appending to modules anywhere etc)

It's an interesting contrast that leads to very different code layouts.

lerno··on Show HN: The C3 programming language (C alternative language)
I don't like to say "never", because other things make change that invalidates previous conclusions.

For example, let's say that for some reason macros were removed (this is very unlikely to happen, but as a thought experiment), then the symmetry between macro/fn definitions wouldn't be an argument anymore, and the question could be revisited.

Similar things have happened before: the optional type syntax changed from `int!` to the more mainstream `int?`. So why did I stick with `int!` for so long? Because initially it was called a "failable" and had different semantics. Revisiting this syntax after other changes to the syntax in 0.6.0, made it clear that `int?` was now fine to use.

So that's why I don't say never. But it would need for the situation to change in some way.

lerno··on Show HN: The C3 programming language (C alternative language)
Now I'm confused, what do you mean? What grammar changes?
lerno··on Show HN: The C3 programming language (C alternative language)
It's a good language, you should try it out as well.
lerno··on Show HN: The C3 programming language (C alternative language)
(Funny story, I seem to have a bout of visual migraine at the moment and misread your comment until just now and had to remove what I wrote).

I didn't mean to give the impression that I'm putting down Zig. It's more that I've noticed that people tend to frame problems differently with Zig than with Odin.

To explain what I mean by framing, consider OO vs procedural and the way OO will frame the problem as objects with behaviour that interact, and procedural will frame the problem as functions being invoked mutating data.

The difference isn't at all that stark between Odin and Zig, but it's present nonetheless. And clearly Zig is doing something which a lot of people like enjoy. It's just that the person using Zig seems to enjoy different aspects of programming (and it seems to me be in the spirit of "the challenge of finding an optimal solution") than the person using Odin.

lerno··on Show HN: The C3 programming language (C alternative language)
If I would have liked, I could have done something like `import std::io::file as file;` but I noticed that we keep getting this issue that we’re renaming things all of the time, and usually in the same way. This is why path shortening is there. To directly get something like the informal `file_open` namespacing in C programs.
lerno··on Show HN: The C3 programming language (C alternative language)
Did you know that Wikipedia editors will aggressively remove Wiki entries about less known languages. There are already several wiki articles on Odin by various authors that have been removed over the years.

Talking about GitHub numbers, we can look at VLang, which had an astronomical trajectory initially due to overpromising and selling a language that would solve long standing issues such as no manual memory management but no GC needed etc.

Such viral popularity creates a different trajectory from organically growing word of mouth such as in the Odin case.

Vlang also has a Wikipedia page.

Is this then proof that it is a viable alternative to the general public? This is what you argue.

lerno··on Show HN: The C3 programming language (C alternative language)
Blake2 and other hashes are most welcome.

As for HashMap you are completely correct: there are many different types of maps that are needed. Concurrent maps, insertion ordered maps etc. And even variations of the small things: are keys copied or not!

I talked about this on a stream recently, how the standard library is in need of a lot of additional Maps, Sets and Lists.

So if you’re interested in contributing then you’re very welcome to do so.

lerno··on Show HN: The C3 programming language (C alternative language)
This is not that novel. It is inspired by the similar feature in the Odin language.
lerno··on Show HN: The C3 programming language (C alternative language)
Also, `fn` is used to make type inference for lambdas syntactically simple. But I would lie if I said I haven’t been considering removing `fn` many times. But there are good reasons for keeping it, despite the break with C.
lerno··on Show HN: The C3 programming language (C alternative language)
Isn’t it a somewhat unfair characterization that ”C3 promotes itself more” and ”is pushed on HN and other social media” and that because of this C2 for some reason experiences harm?

C2 is over 11 years now. C3’s recent breakthrough this last half year is unlikely to have had much impact on its ability to grow the last 10 years.

lerno··on Show HN: The C3 programming language (C alternative language)
The difference here is that a preprocessor runs before parsing and semantic analysis. In C3 compile time if runs in the analysis step, so after parsing.

So the macros and compile time execution occurs after parsing in C3, but in C everything happens at lexing, before the code is parsed.

lerno··on Show HN: The C3 programming language (C alternative language)
Yes, this is a very real problem that I've also written about: https://c3.handmade.network/blog/p/8486-the_case_against_a_c...
lerno··on Show HN: The C3 programming language (C alternative language)
Oh, I think you missed something then:

There is both `$if` and `$switch` compile time statements for this: https://c3-lang.org/generic-programming/compiletime/#if-and-...

At the top level and `@if` attribute is used to achieve the same thing: https://c3-lang.org/language-common/attributes/#if

lerno··on Show HN: The C3 programming language (C alternative language)
But you have to. Ambiguities hint at lack of redundancies that also affects code reading. When you quickly scan something like `file.open` vs `file::open` the former is also more unclear to a reader without more context.
lerno··on Show HN: The C3 programming language (C alternative language)
C3 has "path shortening", so for example given `open(...)` in std::io::file is usually used as `file::open(...)`. If we would to write this as `file.open(...)`. Consider now the case of mistyping `open`: `file.openn(...)`. Is this (A) mistyping the function open in module `std::io::file` or is it (B) the global/local `file` is missing from the current scope?

Also, "io", "file", "random" etc are commonly used variables, so the issue with shadowing is real.

`File file = file::open(...)` is completely unambiguous and fine. `File file = file.open(...)` on the other hand would be bad.

If the language had flat modules, or no path shortening, then it would be possible.

lerno··on Show HN: The C3 programming language (C alternative language)
C3 follows the C ABI, so no it doesn't do it and it's not planned.
lerno··on Show HN: The C3 programming language (C alternative language)
What kind of conditional compilation are you missing?
lerno··on Show HN: The C3 programming language (C alternative language)
Other than C3, there is Jai, Odin, Zig and Hare which are the ones that have any traction right now that I know of. Many interesting projects have been started but ultimately later abandoned.

Going to C++ competitors there is obviously Rust, but also Nim, Crystal, Beef and a lot of others. (And Jai is a C++ competitor too)

← PreviousPage 7 of 13Next →