Why is every bit of legacy C++ written so fucking poorly

Why is every bit of legacy C++ written so fucking poorly.

We inherited a bunch of C++ written in 2004 and it literally had a 7000 line function in it.

Kill me Jow Forums.

Attached: 1534388588146.jpg (1024x576, 148K)

How do you write non-horrible C++ other than just writing C?

>it has a long function
What's the more important measure is the deepest level of indentation (deepest nested block) and the lengths of code >4 nested blocks deep.
And ideally you'd measure the distinguishable functional pieces that exist but it's too subjective.
A long functions isn't bad at all on its own.
In 2004 you really couldn't.

It's bad. This isn't a joke: we counted 11 nested for loops before we quit counting.

baste

>Before we quit counting
Familia you should've kept going out of shower morbidity.

Don't promise to take over projects that are above your level, Reyansh.

>We inherited a bunch of C++ written in 2004 and it literally had a 7000 line function in it.

...But I fixed it. Now we have 700 ten line functions called func1 thru func700 that take as arguments all the local variables in the original function. This is so much better :^)

>being this retarded

>other than just writing C?
That's literally the most common way of writing horrible C++.

Because most legacy C++ was written by people with C mindset, usually before OOP became as widespread as it is today, and before people started understanding how to use OOP (i.e. with knowledge of the average C fag who thinks that OOP is about making huge class hierarchies and then cries that C++ is shit).
Also, legacy code was made without C++11 and newer, so you see atrocities like new and delete all over the place.

>7000 line function
How the fuck do you even do that shit?

do_stuff()

7000 lines is an awful lot of stuff.

>7000 line function
I hope you are joking. Worst thing I saw was ~900 lines function in java.

>11 nested for loops
That seems really extreme user. You sure you're not exaggerating here?

do you know how big a 7000 line function is?

Yes. And you're suggesting you've got someone nesting 11 for loops in there.

*user is suggesting

I have a 20,000 line program with a function stack at least 50 functions deep
Imagine unrolling all of that into just ONE function and seeing deep your tabs went

>A long functions isn't bad at all on its own

Attached: file.jpg (645x729, 46K)

Boomers.

Not him but I did see some comparable shit in legacy code as well, so that sounds plausible.

>atrocities like new and delete all over the place.
Python dev detected.

user, if we take your program as representative and assume stack size would decrease linearly he'd have a for loop calling the rest of the stack two out of three functions with no collapsing (implicit in there being a deep callstack).

It's an exceptionally poorly written program. The fact that it's all in one function (imagine just 11 steps of indentation only in the for loops, ignoring other blocks) makes it even harder to believe.

Even if it were broken up into functions perfectly it would be horrible. I don't believe it's written by a human. It's either flattened as a joke or it's auto-generated.

t. never understood unique_ptr

C++ really should have changed name starting from the C++11 standard. It's effectively a different language.
Before that, C++ really was shit and overall caused more problems than it solved with respect to C, but the latest standards have greatly improved the language, to the point that most of the complaints about its old standards have been solved. I went from shitting on Sepples to kinda liking it.
Unfortunately, we are stuck with lots of legacy C++, which is a way different beast.
The advice "good C++ should be similar to C" really does not apply from C++11 onward. Good modern C++ is way different from good C.

You pretty much never have to use new and delete yourself in C++.

what is so fucking different about C++ after 2011 that it's an entire new language
I use it a little and I keep hearing you fucks say this and I'm not convinced

I've had to deal with plenty of legacy code aswell.
Mainly C code. Written without declare anywhere and function call inlining paranoia. Plenty of repetition for basic things like specialized atoi (expressed known length).
But the programmer wasn't a complete moron as op would suggest their predecessor was. It's not inherently bad aside from the lack of reuse and I have different code organization preferences.
I don't usually think to measure LOC but I know some line numbers were up in the 5ks.

>user, if we take your program as representative and assume stack size would decrease linearly he'd have a for loop calling the rest of the stack two out of three functions with no collapsing (implicit in there being a deep callstack).
What?
I'm saying if I unrolled my entire program into 1 function it'd have just as many indentation levels
probably over 20
and don't underestimate old programmers ability to write awful code

>as many indentation levels
But not as many for loops. It's not about the indentation primarily.
It's the massive amount of for loops.

First things I can think of:
>move semantics
>smart pointers that actually work (unique_ptr, shared_ptr and weak_ptr), thanks to move semantics. c++17 also finally removed auto_ptr
>uniform initialization
>auto variables
>trailing return types (allowing you to deduce return types from arguments, such as auto f (T a, T b) -> decltype(a + b)
>guaranteed copy elision during initialization and when returning temporary objects, allowing you to return by value without creating additional copies, avoiding out parameters and therefore making your interface simpler
>user-defined literals, such as string literals
>improved concurrency (better, easy to use thread library, atomic library, locks, condition variables, etc.)
>lambda expressions, convenient for nested functions and a bit of functional programming if you need it
>Actual, strongly typed enums (enum class), which effectively avoid name clashes
>variadic templates
>range-based for loops, they almost feel like python

And many more. Later standards have some other nice features as well. Of course, none of these is game-changing on its own. But when combined together, it effectively makes the language quite different.
C++03 and older was missing all this shit.

Is all this useful?

Depending on the context, yes. I have used all these features myself somewhat more than occasionally.
However, you are not required to use any of them if they aren't useful for your case.

>when you need a 4K monitor just to fit the indentation

Just rewrite it you fucking mong.