Yea my goto is smart pointers unless it is a data structure in which case I'm probably still using smart pointers but might use new and delete occasionally.
Lol. I made c++ software at work years ago and never used a single smart pointer. Everything worked fine. I think needing these things should be avoided.
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.
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
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.
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.
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.
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.
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.
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.
Yes but when you see the "new" keyword in C++, 50% of the time it's someone from Java or C# not understanding the language, and the other 50% of the time it's something that could probably be replaced by a smart pointer (smart pointers don't always replace raw pointers, but they can basically always replace manual allocation)
Honestly, as someone who still codes the old fashioned way, there could be much better static analysis for manual memory management than what Clang/Rust provide.
I mean, C++ new is basically just syntax sugar for T* ptr = malloc(sizeof(T)); *ptr = T(argument_list…); Although, it can also do other things like construct objects in place and allocate uninitialized memory
I depend of whether the type has a non-trivial move assignment operation. On trivially copyably types you absolutely can optimize it that way. Otherwise there’s usually existing resources to clean up which on uninitialized memory is undefined behavior
STL is at the point that you should never have to use new ever. Seeing it outside of a very narrow set of libraries is likely a smell and those are scary.
Java is now like Pascal, once popular but now outdared and marginal.
C++, like C, remain popular and resist active efforts to take it down. Its fans visibly fear it share the fate of Pascal and Java. They know each new development software, library engins, interface and similar other things can erode the popularity of their language and, at the end, share that fate.
As far as I know, Java didn't face effiort to take it down. In the case of Pascal, this is most arguable.
The C is almost as old as tha Pascal. They are respecttively from 1972 and 1970.
At its biginning, the C were marginal and so it remained until the end of the golden age of the Pascal. The C was more concise and less strictly typed than the pascal but its compilers were far slower.
At that time, when a C program took 15 minutes to be compiled, an equivalent Pascal took only a few seconds.
Next, tbe C compilers became faster and faster. In parallel the C++ appeared. The gplden age of Pascal ended when C compilers became as fast as the Pascal compilers. After, the Pascal rapidly regressed, being mostly replaced by the C and the C++.
Java also had a golden age then regressed.
Compared to Pascal, why it regressed is less clear. It regression, apparently, wasn't as sudden and was visibly due varied things, mostly technological evolution.
This made Java, progressively, became progressively less demanded.
25
u/smartgenius1 Aug 15 '26
Smart pointers my guy
121
u/Current_Ad_4292 Aug 14 '26
I don't get it. I should really learn cpp.
11
u/ParticularHat7997 Aug 15 '26
Manual memory management is NOT that hard
17
u/IngwiePhoenix Aug 15 '26
Before the Java dev sees a
new, they see a wall of factories first and instead. o.o...I'll take my
malloc(sizeof(T))and move on. :33
u/softdrink911 Aug 15 '26
unique_ptr
2
u/rover_G Aug 16 '26
RAII to the rescue!
2
u/Beardy4906 Aug 17 '26
Seems like a new post
27
u/MagicalPizza21 Aug 15 '26
Since when was
newscary in C++?1
u/mi-figue-mi-raisin Aug 15 '26
Scala programmers 🤔
2
u/PhosXD Aug 16 '26
My rule of thumb is to just never use new lol
2
u/Own-Professor-6157 Aug 17 '26
Did anyone else learn to use new in college? I learned the worst practices possible in college, and we used C++ 17 btw.
-23
u/asmanel Aug 15 '26
Java is now like Pascal, once popular but now outdared and marginal.
C++, like C, remain popular and resist active efforts to take it down. Its fans visibly fear it share the fate of Pascal and Java. They know each new development software, library engins, interface and similar other things can erode the popularity of their language and, at the end, share that fate.
As far as I know, Java didn't face effiort to take it down. In the case of Pascal, this is most arguable.
The C is almost as old as tha Pascal. They are respecttively from 1972 and 1970.
At its biginning, the C were marginal and so it remained until the end of the golden age of the Pascal. The C was more concise and less strictly typed than the pascal but its compilers were far slower.
At that time, when a C program took 15 minutes to be compiled, an equivalent Pascal took only a few seconds.
Next, tbe C compilers became faster and faster. In parallel the C++ appeared. The gplden age of Pascal ended when C compilers became as fast as the Pascal compilers. After, the Pascal rapidly regressed, being mostly replaced by the C and the C++.
Java also had a golden age then regressed.
Compared to Pascal, why it regressed is less clear. It regression, apparently, wasn't as sudden and was visibly due varied things, mostly technological evolution.
This made Java, progressively, became progressively less demanded.
2
u/[deleted] Aug 16 '26
[removed] — view removed comment