News for hackers. Stuff that matters.
Re:Is C++ fast? by MichaelMoser123 on Friday January 18, 2019 @09:30AM (#18939498)
C++ comes with the OOP mindeset: OOP is about polymorphism, inheritance and encapsulation. Now what if you are abstracting over the wrong library for a given task? Will you be able to question your basic assumptions, or is that an assumption that is not allowed to be questioned? (due to the encapsulation principle)
Re:Is C++ fast? by thestoicattack on Friday January 18, 2019 @09:39AM (#18939558)
I don't think C++ comes with the OOP mindset. At least, not recently. Most people will tell you it's "multi-paradigm." And I would say C++ certainly gives you enough flexibility to dig underneath the abstractions, as TFA shows.
Re:Is C++ fast? by MichaelMoser123 on Friday January 18, 2019 @09:44AM (#18939587)
I am not so sure about the multi-paradigm thing: In c++ everything is a class. Also of you try hard enough then you may implement any paradigm in any language.
Re:Is C++ fast? by lultimouomo on Friday January 18, 2019 @09:47AM (#18939615)
You mean except booleans, integers, floats, pointers, free functions, namespaces, templates and lambdas?
Re:Is C++ fast? by gpderetta on Friday January 18, 2019 @10:57AM (#18940134)
Also a class in C++ is by default exactly the same as a struct (except for default access control which is a minor thing). An OOP style class would be any class type (including struct) with virtual functions which you would have to opt in.
Re:Is C++ fast? by MichaelMoser123 on Monday January 21, 2019 @06:01AM (#18959474)
yes, you can do a C++ program with functions only + integers and array of integers. technically that's C++. Very apt observation! I still guess that the main entities in your c++ program will be classes (not POD)

And I still maintain that most people treat class libraries (such as STL) as given and do not inspect how they are implemented and do not consider what constraints / alternatives do exist. One example: the std::dequeue is a dynamic array, and you can't quite tune the size of the inner array easily by means of template or instance parameters - no one cares. Also many people happily use the shared_ptr class and don't even know that it takes very expensive atomic operations to do the reference counting; I would have expected a template parameter that could determine if shared_ptr is meant for multithreaded use or not. Most people don't care and happily use the shared_ptr. Also there are no intrusive linked lists in STL (well, there are in boost)

I can go on and on about the STL (and other widely used libraries if you care) and I still suspect that they get away with these "issues" in a widely used library because people are used not to question library implementations and treat them as frigging black boxes.

Re:Is C++ fast? by asveikau on Friday January 18, 2019 @03:43PM (#18942873)
I agree with your sentiment but the lambdas do get treated as anonymous classes overloading operator ().
Re:Is C++ fast? by kllrnohj on Friday January 18, 2019 @05:32PM (#18943738)
Not really true. Lambdas can be converted to a class overloading operator() (such as std::function), but they are not inherently that. You can use them as just function pointers, too. Example:

    #include <cstdio>

    void call_func(void(*func)()) {
        func();
    }

    int main(int argc, char* argv[]) {
        // Lambda can be converted to a function pointer
        call_func([]() {
            printf("hello as a function pointer\n");
        });
    }
Re:Is C++ fast? by asveikau on Friday January 18, 2019 @05:54PM (#18943899)
> but they are not inherently that.

I am fairly certain I have had error messages and disassemblies that suggest otherwise. This may however be an implementation detail.

> You can use them as just function pointers, too.

Yes, I know this. It only works when there are no captures. And AFAIK once there are captures you start getting object code that looks a lot like you put those captures into an anonymous class. (When not inlined.)

Re:Is C++ fast? by slavik81 on Friday January 18, 2019 @11:24PM (#18945319)
You can get that sort of behaviour from any class by implementing the conversion operator. I assume that lambda implements `operator(void(*)())` so it is implicitly convertible to a function pointer.
Re:Is C++ fast? by thestoicattack on Friday January 18, 2019 @09:46AM (#18939600)
That's Java, isn't it? I write lots of C++ without classes.
Re:Is C++ fast? by mindcrime on Friday January 18, 2019 @10:34AM (#18939951)
Even though Java is still very "class-centric", in the strictest sense Java doesn't make "everything a class". There have always been primitives for things like int, long, boolean, float, double, etc. And now that we have MethodHandles and what-not, you can (sort of) start to think of functions as first class entities in Java. And there are Lambdas as well which effectively let you build a function without it needing a class to contain it.
Re:Is C++ fast? by thestoicattack on Friday January 18, 2019 @10:49AM (#18940067)
I was being a little flippant and unfair to Java because I was trying to find where the claim "everything is a class" had appeared from.
Re:Is C++ fast? by Sharlin on Friday January 18, 2019 @02:03PM (#18941895)
The "STL" part (data structures and algorithms) part of the C++ standard library uses no OO design at all. The iostreams part does, but it's hardly visible to the user. (No, simply having syntax that allows you to write `data.function()` instead of `function(data)` doesn't make anything object-oriented.)
Re:Is C++ fast? by lultimouomo on Friday January 18, 2019 @09:45AM (#18939596)
There is exactly 0 polymorphism and very limited inheritance in the code referenced by the article.

And STL really isn't based on an OOP mindeset.

Re:Is C++ fast? by pdpi on Friday January 18, 2019 @10:07AM (#18939751)
There is exactly zero _subtype_ polymorphism. The STL uses templates as a means to achieve parametric polymorphism (i.e, generics).
Re:Is C++ fast? by MichaelMoser123 on Friday January 18, 2019 @12:57PM (#18941214)
Yeah, and zero encapsulation also. Keep up the good work!