Live data from Hacker News

Why I don't spend time with Modern C++ anymore

linkedin.com

51–60 of 264 posts

Re: Why I don't spend time with Modern C++ anymore

#51
post #48

I know why I don't like C++ anymore, it's just no fun.Its slow to compile, the errors are like 6 lines long full of template and class hierarchy that makes it hard to understand what exactly happened, and then of course there's the common coding shortcut of declaring everything auto. (What type is this list? I don't know, it's auto all the way down.) Then there's the whole thing about making constructors, but leaving…

I had to write C++ yesterday and hated every second of it, from the clunky header files, to the errors that make no sense, to the can't make a cyclic dependency between classes i.e. class A { B: b} class B { a: A} Long story short - I was to create a wrapper around a Poco::Runnable, so you can use the wrapper as a Poco::Runnable (don't ask why, it's TEH LAW) but without extending it.

You should be able to do that with either references or pointers between classes with a forward declaration. In essence:

  class B;
  class A { B* b;}
  class B { A* a;}

Re: Why I don't spend time with Modern C++ anymore

#52

HFT is a pretty limited and extreme application case. From what I understand - everything is not enough for HFT - network cards, kernel drivers, cables, etc. You have milliseconds (edit: nanoseconds !) to receive, process and push your orders before someone else does it and gets the prize. It's an arms race between technologists for the purpose of making a small number of people rich. I doubt that these requirements…

Consultants wanna consult.

Re: Why I don't spend time with Modern C++ anymore

#53

Earlier quoted context omitted.

I also agree that c++ is getting more and more complex over time. However if you build things from scratch and you cherry pick your language features, C++ can be quite pleasant.

That's the problem - C++ isn't one language, it's at least three generations of languages living together in the same compiler, like an extended family crammed into a tiny apartment. No one has moved out since 1983, and new additions just keep on coming.

We c++ programmers are very welcoming. We have yet to meet a paradigm that we didn't like.

On a more serious note, any old system acquires cruft with time and you don't always have the luxury of throwing away pieces or even restarting from scratch.

Re: Why I don't spend time with Modern C++ anymore

#54
post #48

I know why I don't like C++ anymore, it's just no fun.Its slow to compile, the errors are like 6 lines long full of template and class hierarchy that makes it hard to understand what exactly happened, and then of course there's the common coding shortcut of declaring everything auto. (What type is this list? I don't know, it's auto all the way down.) Then there's the whole thing about making constructors, but leaving…

I had to write C++ yesterday and hated every second of it, from the clunky header files, to the errors that make no sense, to the can't make a cyclic dependency between classes i.e. class A { B: b} class B { a: A} Long story short - I was to create a wrapper around a Poco::Runnable, so you can use the wrapper as a Poco::Runnable (don't ask why, it's TEH LAW) but without extending it.

You can only do that when using pointers or references:

    class B;
    class A {
      B* b;
    }
    class B {
      A* a;
    }
because the compiler can (obviously) not tell how large the instances of the other class are when you have a field of that type. Remember that the class layout has to be fixed at compile time and both instance sizes depend on one another. That's not solvable.

C# does the same, actually:

    struct A {
      B b;
    }
    struct B {
      A a;
    }
will cause the following error:

    test.cs(2,5): error CS0523: Struct member 'A.b' of type 'B' causes a cycle in the struct layout
    test.cs(6,5): error CS0523: Struct member 'B.a' of type 'A' causes a cycle in the struct layout
with classes and references it works, of course:

    class A {
      B b;
    }
    class B {
      A a;
    }

Re: Why I don't spend time with Modern C++ anymore

#56
post #48

I know why I don't like C++ anymore, it's just no fun.Its slow to compile, the errors are like 6 lines long full of template and class hierarchy that makes it hard to understand what exactly happened, and then of course there's the common coding shortcut of declaring everything auto. (What type is this list? I don't know, it's auto all the way down.) Then there's the whole thing about making constructors, but leaving…

I had to write C++ yesterday and hated every second of it, from the clunky header files, to the errors that make no sense, to the can't make a cyclic dependency between classes i.e. class A { B: b} class B { a: A} Long story short - I was to create a wrapper around a Poco::Runnable, so you can use the wrapper as a Poco::Runnable (don't ask why, it's TEH LAW) but without extending it.

Not sure what you're trying to do, but:

    class A; class B; // 'forward declaration' if you want to google
    class A { unique_ptr b; };
    class B { unique_ptr a; };
...generally classes instantiating each other is a sign that your design needs rearranged, but it has its uses when writing graph types.

Re: Why I don't spend time with Modern C++ anymore

#57
In my experience, the opposite of what the author claims is true: modern C++ leads to code that's easier to understand, performs better and is easier to maintain.

As an example, replacing boost::bind with lambdas allowed the compiler to inline functor calls and avoided virtual function calls in a large code base I've been working with, improving performance.

Move semantics also boosted performance. Designing APIs with lambdas in mind allowed us to get rid of tons of callback interfaces, reducing boilerplate and code duplication.

I also found compilation times to be unaffected by using modern C++ features. The main problem is the preprocessor including hundreds of thousands of lines for a single compilation unit. This has been a problem in C and C++ forever and will only be resolved with C++ modules in C++2x (hopefully).

I encourage the author to try pasting some of his code into https://gcc.godbolt.org/ and to look at the generated assembly. Following the C++ core guidelines (http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines) is also a good way to avoid shooting yourself in the foot (which is surprisingly easy with C++, unfortunately).

Re: Why I don't spend time with Modern C++ anymore

#58
post #43
post #24

Ok. Try a different language :)? A single language needed to solve all problems is a fallacy. I don't see FPGA programming ousting c++, but expect higher level languages with strong parallel semantics to gain "market share". You can always call a dedicated process written in optimized c for the hottest components. Compose the rest in go, elixir, or any high level language (lisp). Architectures will naturally gravitat…

> A single language needed to solve all problems is a fallacy. Has that been proven and do we have pointers to any peer reviewed papers on that? Because else its just an old's wives tale. I don't see any logical impossibilities for one language to solve all problems (meaning, to work well for at least 4 domains: OS and drivers a la C, apps/games a la C++, network programming a la Go, Java etc, and scripting a la Pyth…

It's just cultural, monetary, design and community issues

"What difficulties does this proposal face?" "All of them"

Re: Why I don't spend time with Modern C++ anymore

#59

HFT is a pretty limited and extreme application case. From what I understand - everything is not enough for HFT - network cards, kernel drivers, cables, etc. You have milliseconds (edit: nanoseconds !) to receive, process and push your orders before someone else does it and gets the prize. It's an arms race between technologists for the purpose of making a small number of people rich. I doubt that these requirements…

Not milliseconds. Nanoseconds. Competitive tick-to-trade times are on the order of 1000ns or less.

Re: Why I don't spend time with Modern C++ anymore

#60
post #55

Anybody got an idea to which video series of Chandler Carruth he is referring to?

Here's a few:

- "Tuning C++: Benchmarks, and CPUs, and Compilers! Oh My!" https://www.youtube.com/watch?v=nXaxk27zwlk

- "Understanding Compiler Optimization" https://www.youtube.com/watch?v=FnGCDLhaxKU

- "Optimizing the Emergent Structures of C++" https://www.youtube.com/watch?v=eR34r7HOU14

- "Efficiency with Algorithms" https://www.youtube.com/watch?v=fHNmRkzxHWs

The first one is really good if you've never benchmarked anything in a Linux environment. Or if you otherwise want to learn how to investigate how C++ gets turned into machine code.

Post reply on HN