[OT] C vs C++

Dukc ajieskola at gmail.com
Fri Sep 9 09:36:16 UTC 2022


On Thursday, 8 September 2022 at 22:26:12 UTC, H. S. Teoh wrote:
> Haha, wait till you see some of the C code I've had to deal 
> with. Somebody, in a glorious fit of NIH, had decided that it 
> was a good idea to reinvent C++'s OO -- except partially, 
> inconsistently, and without the syntax niceties and compiler 
> guarantees -- by writing function pointers everywhere. And I 
> mean, literally *everywhere*: open up a page of code the code, 
> and almost every line involves at least 1 call to a function 
> pointer. Most lines contain at least 2-3, some really bad ones 
> have 6 or more.  Basically, it's trying to imitate C++ 
> polymorphic code except in C.  But the problem is, since this 
> is all hand-made and not supported nor enforced by the 
> compiler, the correspondence between function pointers and 
> logical virtual method calls is not 1-to-1... meaning that 
> sometimes you *think* a certain funcptr call would go 
> somewhere, but it goes somewhere else instead, because somebody 
> along the line decided to "override" it (unofficially) in order 
> to, I don't know, fix a bug or something.

You got me to doubt my assessment ;).


>> Maybe the conclusion is that C++ is virtually always better 
>> than C in itself, but it's use is teached so badly that it 
>> often ends up worse.
>
> Um, no.  SFINAE + Koenig lookup.  That combo alone will give 
> you migraines for weeks, if not months.  No amount of good/bad 
> teaching will negate the fact that this combo is the stuff of 
> nightmares.  Add to it mix all the other "niceties" of C++, and 
> ... yeah. Not going there.  I think I'm suffering from C++ PTSD.

I disagree somewhat, because it could be taught that one should 
avoid or be extra conservative with SFINAE because Koening 
lookup, and many other things, tend to mess it up. That's what I 
meant with bad teaching: encouraging to use C++ features which 
bite back like that.

>
> Only reach for the ultimate weapon (did I hear, string mixin? 
> ;-)) when no other recourse suffices.

In my opinion string mixins should not always be the last resort. 
Sure they have the downside that they are essentially macros that 
can do anything. Walter did wisely requiring the `mixin` keyword 
when using them, so they stand out clearly and are too ugly to be 
tempting.

But mixins have the upside that they are much simpler to 
understand than template and trait trickery. That's why a string 
mixins are IMO sometimes better than clever templates.




More information about the Digitalmars-d mailing list