News for hackers. Stuff that matters.
Re:Tagged Unions Are Overrated by jcelerier on Friday February 19, 2021 @04:22AM (#26191150)
> In object-oriented languages like Java or C++, you can implement your AST as an abstract base class and a set of subclasses, and do matching using straightforward type tests — instanceof in Java, or dynamic_cast in C++.

but at a pretty large cost : now everything has to be boxed, will be dynamically allocated by default (yes, object pools and small-size optimization, but that does not produce very readable code and needs constant care), you risk slicing, every access has an indirection, etc.

Migrating some C++ code from OOP inheritance to variant-like stack-allocated value types has always resulted in n-fold improvements to runtime performance in my case.

Re:Tagged Unions Are Overrated by tom_mellior on Friday February 19, 2021 @05:29AM (#26191532)
> now everything has to be boxed [...] every access has an indirection, etc.

The article makes clear that it is speaking of compiler intermediate representations. Those are pretty much by definition boxed, linked data structures that live on the heap.

> Migrating some C++ code from OOP inheritance to variant-like stack-allocated value types has always resulted in n-fold improvements to runtime performance in my case.

Was this in the context of processing some form of programming language IR?

Re:Tagged Unions Are Overrated by otabdeveloper4 on Friday February 19, 2021 @05:56AM (#26191724)
Yes, C++ is not an "object-oriented language" and never was.

The OO features were added because at the time it was the raging fad and people thought that every language simply must have "OOP".

But "OOP" was never a foundational principle for C++, more like a tacked-on sidecar.

Re:Tagged Unions Are Overrated by tom_mellior on Friday February 19, 2021 @06:10AM (#26191822)
You're arguing that a language that arose specifically to add classes to C was not meant to be object-oriented? I'd be interested in seeing that argument fleshed out in more detail.
Re:Tagged Unions Are Overrated by gpderetta on Friday February 19, 2021 @06:32AM (#26191994)
It is true that subsequent c++ evolution de-emphasised OOP, but you are completely right that the original selling point of C++ over C definitely was (Simula style) OOP.
Re:Tagged Unions Are Overrated by otabdeveloper4 on Friday February 19, 2021 @01:59PM (#26196601)
Three points:

a) 'Simula style' isn't at all like the Smalltalk-derived programming patterns we call 'OOP'. (Simula was about actor-oriented programming anyways, hence the name.)

b) The unique differentiator for C++ was the STL, and not the OOP features that were done better and cleaner in other languages.

c) The killer feature for early C++ adoption was operator overloading, not inheritance. (Pretty much nobody liked using inheritance in C++ even back in the day.)

Re:Tagged Unions Are Overrated by antonvs on Sunday February 21, 2021 @06:22PM (#26218392)
> The unique differentiator for C++ was the STL

This involves such a level of ignorance of the history of C++ that you should consider deleting your comment. The STL didn't exist in C++ for the first decade of its existence.

> Pretty much nobody liked using inheritance in C++ even back in the day.

What is your basis for this claim? Don't bother responding, the answer is that it's nothing more than your fantasizing.

Re:Tagged Unions Are Overrated by gpderetta on Monday February 22, 2021 @05:04AM (#26222703)
Simula and Smalltalk were the two original OO languages. C++ firmly takes its OO capabilities from Simula (the virtual keyword literally comes from there with the same semantics), and is quite distinct from the OO flavour of Smalltalk. Objective-C, with its selector based late binding for example, is clearly Smalltalk inspired.
Re:Tagged Unions Are Overrated by tom_mellior on Saturday February 20, 2021 @10:21AM (#26204716)
> Simula was about actor-oriented programming anyways, hence the name.

Nothing about the name "Simula" suggests actors.

> The unique differentiator for C++ was the STL

https://en.wikipedia.org/wiki/C%2B%2B#History isn't very clear, but it seems to suggest that templates weren't added to C++ until 1990 or later. The STL came around 1993, eleven years after the development of C++ started, not even counting its previous life as C with Classes. Surely in those eleven years people found other differentiators that kept up interest?

Re:Tagged Unions Are Overrated by antonvs on Friday February 19, 2021 @08:44AM (#26193033)
Its original name was actually "C with Classes".
Re:Tagged Unions Are Overrated by mrkeen on Friday February 19, 2021 @09:04AM (#26193233)
I can try:

> add classes to C

C is the foundation. Classes is the sidecar.

Re:Tagged Unions Are Overrated by antonvs on Friday February 19, 2021 @08:43AM (#26193031)
Every statement in your comment is factually incorrect.

See: http://www.cplusplus.com/info/history/