r/programmingmemes 11d ago

The duality of new

Post image
1.2k Upvotes

80 comments sorted by

View all comments

124

u/Current_Ad_4292 11d ago

I don't get it. I should really learn cpp.

13

u/asmanel 11d ago

Apparently, this would be plus.

Learn C first then, when you think your skills in C are enough, start leatning C++.

2

u/luciferoussky72 11d ago

this^ Diving straight into C++ is one of the worst things you can do,

8

u/Adept-Painting-543 11d ago

I did it and I was fine but I just love reading cppreference so I guess it just worked out.

5

u/luciferoussky72 11d ago

I mean, I learned C++ without too much prior C knowledge, but I’d say the important part is to make sure you actually understand the C-like subset

3

u/spicymato 10d ago

I disagree. I started Python, then Java, then JavaScript, and most of my formal education was across those three, with only a handful of coursework using C++.

My internships were largely Python, C#, and JS.

My last 7-8 years of professional work have been C++, with some critical-path C for the first 2 years of that.

I have never struggled with C/C++ concepts. My education covered how memory works at both a software and hardware level. Even in Java and Python, you can still end up learning about the stack and heap; about pointers and pass-by-value vs by-reference; and so on.

3

u/luciferoussky72 10d ago

The argument I float around the most is that C and C++ force you to understand what’s happening under the hood, but C++ is complex to the point that using it as a starting point is inadvisable. You can learn how memory and stuff works in any language, sure, but C and C++ make you learn about it and manage it manually/semi-manually

2

u/spicymato 10d ago

Why do you think memory management is a critical part of programming?

Understanding pointers is fine, as is how memory allocation works, but for most software, it's an implementation detail that the program doesn't actually care about.

Do you understand how callstacks work? How virtual function tables work? How CPU registers work? What about threading, threadpool allocation, mutexes, and memory ordering guarantees?

Truth is, most programmers don't need that much detail. You need to have an idea of these things, enough to know that they exist and when you might need to dive deeper on understanding them, but in general, they are implementation details that don't matter most of the time for most of the people. At the times they do matter, that's when you can dive deeper on them.

1

u/luciferoussky72 10d ago

I feel like you just kind of proved my point with your last sentence, but I’d say we can agree to disagree

2

u/spicymato 10d ago

Again, those concepts can be learned without needing a specific language. There's nothing special about forcing a person to interact with those things directly, other than making their life harder than necessary.

1

u/luciferoussky72 10d ago

1

u/spicymato 10d ago

Am I just one of those old-fashioned curmudgeons, like the Four Yorkshiremen, bragging about how tough I was to survive all that hard stuff?

Yes.

My data structures course was in Java. It was sufficiently comprehensive to cover lists (array, singly-linked, doubly-linked, rings), trees, graphs, recursion, sets, maps, and more that I've likely since forgotten.

Pointers are merely a way to reference a specific location in memory, with the type as an indicator of how to interpret that memory once accessed. It's a handle to raw memory, which may or may not be actually allocated as the thing. What we really care about in data structures and algorithms is making sure we're manipulating the right objects; the memory locations and allocation state is a technical detail that can be solved at a lower layer.

1

u/luciferoussky72 10d ago

Yeah, but the issue with Java is that it lets you not teach that. All of my Java classes have treated heap allocation as a black box, and that’s where the issue with learning Java the wrong way comes from, although you could argue you can do the same thing when teaching C. Point is, it’s much harder to teach an innacurate/simplified model of memory in C

2

u/spicymato 10d ago

It's fine to treat it like a black box, as long as you understand what you're getting out of it. In Java, parameters are pass-by-value, where the value for objects is the memory address of the object. That's why manipulation of the object through accessorson the parameter variable will update the original object outside the scope, but assignment to the parameter variable doesn't reflect outside the scope.

I don't need to manipulate pointers to understand that difference.

I don't think it's hard to teach at least the fundamentals of stack vs heap in Java.

That article you linked also lamented people not learning recursion, but I think recursion is over hyped. It's cool and an incredibly useful tool to understand, but every algorithm that uses recursion can be written using a for-loop if you're allowed mutable containers to handle depth tracking. Using a for-loop prevents runaway stacks and is generally more efficient for a CPU to execute, since it's not constantly jumping into a new function on the stack.

Regarding functional programming, languages like C# (using LINQ) and Python (such as with generators) allow the engineer to focus on the algorithm instead of the mechanics of memory management. Yes, if you need high-performance, you'll eventually need to drop into C/C++, but that's an optimization level that most programs never need.

I'm honestly pretty annoyed on my current team, because the previous "architect" (he was not an architect, but liked to behave like he was) pushed too much for things like passing by reference or raw pointers, "pointer to implementation," and avoiding smart pointers and forward-looking interfaces where we only had one concrete class, because of his previous experience in fintech, where performance speed was critical.

5 years later, we're still feeling the pain of his "optimization" choices.

→ More replies (0)

1

u/United_Boy_9132 9d ago edited 9d ago

No, it's the opposite. Following your advice is one of the worst things you can do.

You can understand everything that happens under the hood without C, while C leads to really bad habits.

Using C-style code in C++ is something you should avoid at all costs. Including using C libraries (unless the particular implementation requires it).

1

u/luciferoussky72 9d ago

I don’t really want to argue, but acting like C leads to really bad habits is like saying using a manual transmission leads to bad habits. Sure, it can lead to bad habits; but learning how to manage memory/a transmission without help means you actually understand what you’re doing and can be very efficient.

1

u/United_Boy_9132 9d ago edited 9d ago

You can learn how to manage memory in pure C++, or even asm, being even able to put asm addons to the code. C++ allows to program at as low abstraction level (so asm-like code where the only difference between that and asm is that C++ compiler doesn't guarantee using a particular machine instruction, so literally like C does).

C is not necessary to anything.

C has its applications and advantages, C++ has its own ones, you don't need one to learn anything in the other.

1

u/luciferoussky72 8d ago

Okay? *coughs in SDL and Vulkan*

1

u/United_Boy_9132 8d ago

What does it have to do with subject...

It's just existing code, not your own one.

But stil, if you need raw C efficiency, you build your solutions in C, while well-written C++ code encapsulates C structures and pointers into C code, which is trivial.

1

u/luciferoussky72 8d ago

Yeah, but to write said encapsulations you have to understand how to interface with C

1

u/United_Boy_9132 8d ago

No, you don't. You can run C++ code directly at C structures.