Live data from Hacker News

Show HN: Sum (algebraic) types for C in one 100 line header

github.com

31–40 of 46 posts

Re: Show HN: Sum (algebraic) types for C in one 100 line header

#32

Earlier quoted context omitted.

C evolves, even if slowly. I think some devs are fed up of Complexity and excessive abstractions. C has very few language features, it's a very simple language -- while all modern languages have new (complex and taxing) features. It's kinda like a Minimalist movement, can we do the same Modern Mumbo Jumbo but in a simple, minimalistic C way? GC and RAII? Nah, just use Arenas/Pools. Or don't use heap at all. C is an u…

Anyone who thinks C is simple is just aiming the gun at their foot. If you want simple, you want something like Scheme.

Yes, but maybe I want to shoot myself in the foot or am willing to take the risk, it's my computer and nobody can tell me what to do with it. That's why I like C. I've been writing Python for almost two decades now, all the new languages are trying even more to tell me how to do things or that I'm doing them wrong, screw that, I don't want to be coddled or patronised by the language I'm using, I'm writing C.

Re: Show HN: Sum (algebraic) types for C in one 100 line header

#33

Earlier quoted context omitted.

C evolves, even if slowly. I think some devs are fed up of Complexity and excessive abstractions. C has very few language features, it's a very simple language -- while all modern languages have new (complex and taxing) features. It's kinda like a Minimalist movement, can we do the same Modern Mumbo Jumbo but in a simple, minimalistic C way? GC and RAII? Nah, just use Arenas/Pools. Or don't use heap at all. C is an u…

Anyone who thinks C is simple is just aiming the gun at their foot. If you want simple, you want something like Scheme.

Frankly this is why I have trouble taking all this C advocacy seriously. Do managers really want their engineers using C? I understand how it can be pleasurable in the way that listening to vinyl is pleasureable. But my undersanding is that it takes years and years of experience to not make catastrophic errors in C. And that's a lot of risk.

Re: Show HN: Sum (algebraic) types for C in one 100 line header

#34

I know it's a minor thing, but why does this link to GitHub? The repository is described only as being a mirror of a SourceHut repo, and the user's profile has a banner telling that he's part of the giveupgithub.org movement. Looking at this post's submitter username, I think OP is the one who owns the repository, so why do this?

I am confused. If the author is part of the Give Up GitHub movement, then why still keep 29 repositories on GitHub! Obviously, they didn't give it up.

Re: Show HN: Sum (algebraic) types for C in one 100 line header

#35
post #24

+1. It cannot possibly be worse than the C++ `std::variant` blunder.

Honest question: what's wrong with std::variant? I'm quite fond of using it. Sure it has trade offs like being empty by exception, but that's necessary if you don't want it to allocate. Also, pattern matching would be nice instead of std::get with visitor, but that's more of a language issue than an std::variant issue

Everytime I have to use std::get and std::visit I feel like the committee has failed all of us.

Re: Show HN: Sum (algebraic) types for C in one 100 line header

#36
post #5

Question: is C gaining in popularity? If so, why exactly? Are their good reasons to be using C in product development rather than more modern languages?

C evolves, even if slowly. I think some devs are fed up of Complexity and excessive abstractions. C has very few language features, it's a very simple language -- while all modern languages have new (complex and taxing) features. It's kinda like a Minimalist movement, can we do the same Modern Mumbo Jumbo but in a simple, minimalistic C way? GC and RAII? Nah, just use Arenas/Pools. Or don't use heap at all. C is an u…

> Nah, just use Arenas/Pools. Or don't use heap at all.

This will solve more than 90% of problems. I'll also add that replace C pointers with a "Fat Pointer" or Go-like slice struct and avoid the C stdlib. Then you'll have fixed 99% of issues.

Re: Show HN: Sum (algebraic) types for C in one 100 line header

#38

I know it's a minor thing, but why does this link to GitHub? The repository is described only as being a mirror of a SourceHut repo, and the user's profile has a banner telling that he's part of the giveupgithub.org movement. Looking at this post's submitter username, I think OP is the one who owns the repository, so why do this?

I am confused. If the author is part of the Give Up GitHub movement, then why still keep 29 repositories on GitHub! Obviously, they didn't give it up.

not op, but github serves two purposes: git mirror, and reputation/network effects.

By relying on github for the latter while redirecting to another mirror for the former allows you to utilise github's reputational system to promote both your project AND the mirroring alternative.

Re: Show HN: Sum (algebraic) types for C in one 100 line header

#39
post #5

Question: is C gaining in popularity? If so, why exactly? Are their good reasons to be using C in product development rather than more modern languages?

It’s the FFI thing - it’s next to impossible to bind to Cpp or rust in a preferred language. It’s a great tragedy that so much code is cloistered away. In 10 years Zig , maybe Mojo or Odin or something else will have stolen mind share away

Re: Show HN: Sum (algebraic) types for C in one 100 line header

#40
post #24

Earlier quoted context omitted.

Honest question: what's wrong with std::variant? I'm quite fond of using it. Sure it has trade offs like being empty by exception, but that's necessary if you don't want it to allocate. Also, pattern matching would be nice instead of std::get with visitor, but that's more of a language issue than an std::variant issue

> that's necessary if you don't want it to allocate. Wait, what does one have to do with the other?

I'm not totally 100% on this, but:

valueless_by_exception happens when the move assignment operator throws (which should never happen in good C++, but is not disallowed by the language). That means, the variant used to hold value X, we were moving value Y into it, but the move assignment operator failed. What is now the state of the variant? It's not X, since we started running the move constructor, which could have started destroying the old value before throwing. But it's not Y either, because the constructor didn't finish. So what's the value that's being held? The answer is that there is no valid value.

How could this be fixed using allocation? Well, if you assume that std::variant allocated, it could be implemented in such a way that the std::variant just held a pointer to a heap area which stored the actual contents of the value. When you move assign, you construct a new element on the heap and move into that.

If the move assignment completes successfully, you swap the old value pointer for the new one and destroy the old value. But if move assignment/construction fails, you just retain the old pointer: nothing has been destroyed, and the variant still holds a valid value. This is very similar to the "strong exception guarantee" for std::vector, which is violated if the move assignment operator for the value throws.

This is one of many reasons why the move constructor/assignment operator should always be noexcept: there's no reason why it should ever throw, and it violates a bunch of these kinds of guarantees.

I think, anyway. I would be happy to be corrected if I got this wrong.

Post reply on HN