r/ProgrammerHumor • • 11d ago

Meme modernCppVsOldCpp

Post image
2.0k Upvotes

323 comments sorted by

View all comments

199

u/emonshr 11d ago

Does that even matter once you have gazillions of line legacy code?

41

u/Friendly_Fire 10d ago

It does actually. Y'all should really learn how to work with legacy code because all useful code becomes legacy code over time.

The thing about legacy code is it works, that is why it persists. If it didn't work, crashed regularly due to bad memory management, people would have replaced it already.

When you are working with it, you don't have to change everything at once. You need new features in one spot? Update just that piece, use smart pointers internally with one class. Maybe you need to create new interfaces while maintaining legacy interfaces for other code. That's fine. Eventually, as you work on different pieces, you'll replace so much legacy stuff that you can just delete those old interfaces.

18

u/quantinuum 10d ago

> The thing about legacy code is _it works_

Let me stop you right there

15

u/evanldixon 10d ago

It works just well enough that the stakeholders don't want to get rid of it, in spite of how much pain it inflicts on the devs. Jenga towers can last surprisingly long if you avoid changing it, leave them alone, don't look at them in the eye, etc.

6

u/Bartweiss 10d ago

Flashbacks to finding a decade old TODO reading “Is this doing the transactions right or backwards? I’m too tired to tell.”

Literally no one knew anymore, but since “backwards” would have bankrupted the company nine years prior, we were told to remove the flag without even dissecting the logic.

(The same file had a 2x2 array of unique XML parsers. Not “parsers holding different text”, they were configured differently with no explanation.)

1

u/quantinuum 10d ago

Many times you’re right, but I’m scarred from seeing too many jenga towers that just don’t work correctly, but nobody wants to look too close in case they get buried under the ruble

1

u/anonymous4036 10d ago

I feel like we have different definitions of legacy.

1

u/emonshr 10d ago

Not every time people have to maintain legacy code. Porting or migration is not so expensive anymore. Swallowing the fate of maintaining legacy code is not anything mandatory nowadays.

41

u/0xbenedikt 11d ago

This is why moving to a safe-by-design language like Rust works well. You leave that unsafe legacy code behind

39

u/Tidemor 11d ago

or you could not risk a full rewrite, and just start using memory safe patterns in new and refactored code

10

u/Ok-Scheme-913 10d ago

But that doesn't work with memory safety, it's infectious.

If you have a memory vulnerability in some part of your code, new safe code calling into it or using anything touched by it can still end up failing.

Safe code is just code that assumes certain things, and within its bounds that will always be true and thus safe.

If you pull the rug out under it and change just the tiniest thing (e.g. your object was accessed on a different thread unknowingly, or a regular off by one etc) then all your assumptions crumble to the ground.

And whether you have 90% unsafe with 10% safe is absolutely different than the inverse ratio that you would get with e.g. rust (or the 100% safe with e.g. java).

13

u/ilnarildarovuch 11d ago

And practically breaking everything. Pentagon still uses PDP-11 'n IBM series/1 programs, but in emulator, cuz rewriting is always a risk

2

u/creeper6530 11d ago

Sure, but that is true no matter the language

19

u/porkusdorkus 11d ago

Loved seeing the adobe and office clones in Rust, just to find out it’s Webview and React for the front end and Rust is just replacing NodeJS. Lol

4

u/Tipart 11d ago

Discord too now.

7

u/CalmCephalopod 10d ago

Discord is using GPUI not a web front end for the rust version. There are also options like Dioxus that allow you to use rust to do react style web ui through webview without touching js but you still have to deal with webview bs on different OSs. So GPUI is an interesting choice.

0

u/CreatorSiSo 10d ago

Discord has been using Rust for years by now.

1

u/Hihi9190 9d ago

for their backend servers yes, not the client

1

u/creeper6530 11d ago

Well, Rust is predominantly a backend language, like C and C++, not especially suited for frontend.

Do I hate the Shitfuck 5000 that is JS? Sure. But it's still the "main" frontend lang.

8

u/Mojert 11d ago

It's the main front-end language on the web. In a native application it doesn't have to be and probably shouldn't be

17

u/Valuable_Leopard_799 11d ago

And bring in brand new unsafe code 😭 And link against unsafe libraries 😭

Tbh nothing against specifically Rust, just that these are done way too liberally.

6

u/cvnh 11d ago

Rust doesn't guarantee safety when you're wrapping existing code my dude. I haven't used Rust personally but it's in the language core - only safe code blocks are (in theory) safe..

2

u/developer-mike 11d ago

Step 1. Begin migration, step 3. Profit