Live data from Hacker News

Algebraic Data Types for C99

github.com

191–200 of 233 posts

Re: Algebraic Data Types for C99

#191

Earlier quoted context omitted.

Typing features affect the way we design APIs. Libraries written in languages with type classes and without them can have completely different designs. If nested pattern matching is not available, this will not affect the APIs, only the function bodies -- because desugaring is local by definition.

That doesn't matter in practice. If two programming languages have the same underlying feature but one has syntactic sugar to make it very easy to use and the other does not (so is quite cumbersome to use) then you'll find that the library ecosystem for the former language will see the feature in widespread use whereas the ecosystem of the latter will tend to shun the feature. This is one of the social factors of pro…

> "anything goes" languages such as LISP have struggled to gain widespread adoption: with no philosophy every programmer becomes an island unto themselves.

There are already two misconceptions.

First: "Lisp has no programming philosophies" and styles.

Not every program starts by zero. Since Lisp exists since the end 1950s, it has seen quite a lot in programming styles over the years and it may contain traces of several. Generally it may support more than one programming paradigm. For example during the Common Lisp standardization there was a wish to have a standardized object system. So instead of the multiple possible approaches (actors, message passing, prototype-based, ...), Common Lisp has just one: CLOS, the Common Lisp Object System. So, much of the object-oriented code written in CL is implemented in one particular object system: CLOS. Object Lisp, Flavors, LOOPs, Common Objects, and a bunch of other once had thus been replaced by one standard.

CLOS also defines a bunch of user-level macros: DEFCLASS, DEFMETHOD, DEFGENERIC, ... Everyone using CL & CLOS will use those macros.

Second: "every programmer becomes an island unto themselves". If we look at the way CLOS was designed: there was a core group of six people from three companies. Around that there was a mailing-list based communication with a large group of interested people. Early on a prototype was implemented as a portable implementation of CLOS. This was widely distributed among interested parties: implementors, companies, research groups, ... Then reports about the language extension and its layers were published, books were published, application & library code was published.

One of famous books coming out of this effort: "The Art of the Meta-Object Protocol". It contained also a toy implementation of CLOS in Common Lisp. Book and the implementation of CLOS (both the larger prototype and the toy implementation) showed in excellent quality how to write object-oriented Lisp code.

https://mitpress.mit.edu/9780262610742/the-art-of-the-metaob...

So, there are communities, which share code and coding styles. Not every programmer is alone and starts from zero.

Re: Algebraic Data Types for C99

#192

Earlier quoted context omitted.

Typing features affect the way we design APIs. Libraries written in languages with type classes and without them can have completely different designs. If nested pattern matching is not available, this will not affect the APIs, only the function bodies -- because desugaring is local by definition.

That doesn't matter in practice. If two programming languages have the same underlying feature but one has syntactic sugar to make it very easy to use and the other does not (so is quite cumbersome to use) then you'll find that the library ecosystem for the former language will see the feature in widespread use whereas the ecosystem of the latter will tend to shun the feature. This is one of the social factors of pro…

> I believe this is why "anything goes" languages such as LISP

Why do you think that Lisp is an "anything goes" language? What's your baseline? I think that C is no less an "anything goes" language, but with a much less pleasant UI.

> with no philosophy every programmer becomes an island unto themselves

Some people actually think that Lispers tend to be too philosophical

Re: Algebraic Data Types for C99

#193

Earlier quoted context omitted.

C has always had them, it's called union. In practice you need to couple it with an enum, and your visitation mechanism is a switch statement. But C doesn't impose that on you and lets you do it as you see fit.

lol this is like saying C doesn't need structs, you can just declare the variables with a common prefix separately! See ma, product types!

That doesn't work since you cannot pass that as a single argument to a function.

Re: Algebraic Data Types for C99

#194
post #102

Earlier quoted context omitted.

Isn’t ADT abbreviation for Abstract Data Type? Or does it depend in context nowadays?

You answered your own question: it depends and the context and is confusing imo. Both are very common in compsci

No I didn’t, I provided two options and asked which case it was. I could’ve assumed OP had used the wrong abbreviation.

Re: Algebraic Data Types for C99

#196
post #169

If I ever implement a product from scratch again, discriminated unions with compiler enforced exhaustive pattern matching is a hard requirement. It’s too powerful to not have.

Union types are my biggest wish for Dart, but unfortunately it doesn't look like they'll be added any time soon.

They've recently added support for compiler-enforced pattern matching over sealed classes, which I suppose does get you halfway there though.

Re: Algebraic Data Types for C99

#197

Earlier quoted context omitted.

lol this is like saying C doesn't need structs, you can just declare the variables with a common prefix separately! See ma, product types!

That doesn't work since you cannot pass that as a single argument to a function.

So? make the function accept multiple arguments?

Re: Algebraic Data Types for C99

#198
post #169

If I ever implement a product from scratch again, discriminated unions with compiler enforced exhaustive pattern matching is a hard requirement. It’s too powerful to not have.

What languages could fit that description today? I don't really understand what it even means but maybe I could understand better if I could look at examples in languages which have them.

Re: Algebraic Data Types for C99

#199
post #169

If I ever implement a product from scratch again, discriminated unions with compiler enforced exhaustive pattern matching is a hard requirement. It’s too powerful to not have.

What languages could fit that description today? I don't really understand what it even means but maybe I could understand better if I could look at examples in languages which have them.

For example Rust: https://doc.rust-lang.org/std/keyword.enum.html

Re: Algebraic Data Types for C99

#200

Earlier quoted context omitted.

That doesn't matter in practice. If two programming languages have the same underlying feature but one has syntactic sugar to make it very easy to use and the other does not (so is quite cumbersome to use) then you'll find that the library ecosystem for the former language will see the feature in widespread use whereas the ecosystem of the latter will tend to shun the feature. This is one of the social factors of pro…

> I believe this is why "anything goes" languages such as LISP Why do you think that Lisp is an "anything goes" language? What's your baseline? I think that C is no less an "anything goes" language, but with a much less pleasant UI. > with no philosophy every programmer becomes an island unto themselves Some people actually think that Lispers tend to be too philosophical

Lisp is anything goes because of macros. Hire ten different Lisp programmers and you’ll get ten different domain specific languages and no one will understand what everyone else has done. If there is a unifying philosophy of Lisp, it’s probably “don’t use macros” and yet so many ignore it!

For all its faults, C is quite easy to read and understand, even by beginner C programmers. Yes, C also has macros but their clumsiness helps to discourage their use.

Post reply on HN