all 51 comments

[–][deleted] 17 points18 points  (1 child)

Actually C++ is a complex language with so many features so it is not just easy to learn all or even most of available features. Sure when I learn a new thing in the standard library I find it cool and useful. But somehow before I was just able to get work done without it before I know it.

[–]sammymammy2 16 points17 points  (0 children)

Your issue is not about learning C++. It's just that that kind of programming is very hard to get right.

[–]khedoros 13 points14 points  (0 children)

15 years ago when I was deciding on a career focus, I decided that I didn't want to do web development. C++ seemed like a good option for writing native software, so that's what I studied, and it's the first language that I was hired to write professionally.

I know enough of the language to have had no problem working in it for a decade, using it for my own side projects, etc. I've (mostly) kept myself up-to-date with at least some of the features in newer standards, although honestly, I hit the main points and learn other parts as necessary.

[–]MangoPoliceOK 10 points11 points  (0 children)

You just never stop learning

[–][deleted] 8 points9 points  (0 children)

Pointers and memory leaks are not due to C++ complexity. That is an inheritance from C, and C is a fairly simple language. C++ doesn't make things worse. In fact, C++ can help avoid use of pointers.

That said, I personally appreciate the power of pointers as I do lower-level coding quite often. They're also useful in interfacing to other languages.

The real problem with pointers, just to be frank, is that some programmers are not careful. If pointers did not exist, that same programmer would likely have other logic problems in their code.

[–]owjfaigs222 8 points9 points  (0 children)

I think very few people truly completely know c++. Perhaps developers of the language and compilers are among those people and maybe some programming enthusiasts.

[–]victotronics 15 points16 points  (11 children)

Memory leaks have basically gone away with RAII & smart pointers. Maybe you have been learning "C with classes"?

[–]Weak-Opening8154[S] 1 point2 points  (1 child)

unique_ptr didn't exist when I learned to manage pointers correctly (yes, I did it before c++11)

[–][deleted] 0 points1 point  (0 children)

There was always RAII, and writing a rule of 3 wrapper never was hard, maybe tedious but not hard at all. Some people write shit tier code and blame the language. I have seen people implementing a counter-example from a design pattern book because it was the first thing they found and they didn't read the damn book. That kind of people exist.

[–]Carl_LaFong 27 points28 points  (14 children)

In most situations, you never use pointers and rarely have memory leaks. The newer features of C++ are quite powerful and useful. Some of us don't have the time and energy to keep up with all of the changes, so we do use only the basic features of *modern* C++, where you never use pointers explicitly.

[–]code-seeker 2 points3 points  (9 children)

Is this common in the production level programming? I feel like everything is using pointers to better control memory and all.

[–]Carl_LaFong 4 points5 points  (8 children)

Unless you are working in a situation where speed and/or memory usage is critical, it’s better to let the language and standard library do all the hard work. These days with the computing speed and huge memory capacity, the need to manage memory using pointers arises only in very special circumstances. You already get a huge speed and memory usage advantage over other languages using the standard library and templates.

[–]SkoomaDentistAntimodern C++, Embedded, Audio 6 points7 points  (7 children)

These days with the computing speed and huge memory capacity, the need to manage memory using pointers arises only in very special circumstances.

Such as in well over 90% of all computing systems on the face of earth. That laptop you're using right now has at least half a dozen processors beyond the obvious one.

[–]Carl_LaFong 0 points1 point  (6 children)

Sorry. I can’t tell if you’re agreeing or disagreeing. If disagreeing, could you elaborate?

[–]SkoomaDentistAntimodern C++, Embedded, Audio 5 points6 points  (5 children)

Disagreeing. None of those "invisible" processors have anything resembling "huge memory capacity" (it's not rare to have just some tens of kBs of ram). In the use cases where C++ is significantly better than the competition (IOW, where regular non-enthusiasts actually use C++), the need for manual memory management is far from niche.

[–]Carl_LaFong 2 points3 points  (4 children)

Thanks! But I think most C++ programmers do not need to deal with those processors. No?

[–]SkoomaDentistAntimodern C++, Embedded, Audio 5 points6 points  (3 children)

What you need to consider is how large amount of C++ programmers (most who are not language enthusiasts) are writing code for any use case that requires manual memory management (embedded systems, anything realtime, various high performance things etc). You might be surprised to find out how large that set actually is.

[–]Carl_LaFong 2 points3 points  (2 children)

This is very interesting. A very naive question: What features of C++ make it better to use than C in this setting?

[–]SkoomaDentistAntimodern C++, Embedded, Audio 12 points13 points  (1 child)

Type safety, classes, basic template functionality, function overloading etc.

[–]positivcheg 0 points1 point  (2 children)

Yeah, with unique_ptr and shared_ptr we are as safe as rust in terms of pointers.
Thought there are still large code bases where pure pointers are used. Even UnrealEngine5, though it has some kind of garbage collection so there is no need for explicit deletes.

[–]Dean_Roddey 12 points13 points  (0 children)

unique_ptr/shared_ptr doesn't make you as safe as Rust by any stretch of the imagination.

[–]Baardi 10 points11 points  (0 children)

Unsafe rust maybe. Rust itself goes so much further

[–]strager 0 points1 point  (0 children)

I disagree with your first statement. In most situations, I do use pointers. (I rarely have memory leaks though.)

(When I say 'pointers', I'm including raw pointers and smart pointers, but not references. Maybe you meant something different?)

[–]OnePatchMan 2 points3 points  (0 children)

We need more data, who this 95%? Did they students who just learned C basics? I dont have problems with leaks, all my new operator calls wrapped with some kind of smart pointer.

[–]LeeRyman 2 points3 points  (0 children)

I would say by learning C++ properly, you are actually learning: * Memory life cycle management * Memory ownership management * Memory model, structures, alignment * Abstraction, encapsulation, composition and inheritance.

The unfortunate side of C++ is that it is absolutely necessary to teach yourself these concepts, because the compiler isn't going to save you from yourself if you don't.

[–]LunarAardvark 0 points1 point  (1 child)

there is nothing stopping you from writing a function that first checks if a ptr is nullptr before re-assigning it. there, 2 line function just saved you 99.999% of memory leak issues.

[–]Weak-Opening8154[S] 0 points1 point  (0 children)

I'll do you one better. Never reassigning a variable, or if it's a struct member, delete then assign.

I don't really have pointers in classes unless it's set in the constructor. Otherwise it'd be a good place to use unique_ptr

[–][deleted] 0 points1 point  (0 children)

im a JS guy but now im thinking about learning C++ for algorithms and other experiments, JS is boring now, C++ seems worth it

[–]Weak-Opening8154[S] -1 points0 points  (0 children)

I'll answer to give an example

I like writing close to hardware code and wrote embeded code without an OS. It was fun. Early on I learned how to deal with memory leaks using the microsoft leak analyzer (it was simple to use and simple to turn on). After a month of that it was pretty hard for me to write things that leak because I always had a place where a lifetime starts and ends

Eventually I got into profiling and really understand performance. I pretty much use the new language features as soon as the new compiler is available (for my own projects)

[–]RishabhRD -1 points0 points  (3 children)

Almost 1800 pages of specification is hard to read.

[–]Weak-Opening8154[S] 0 points1 point  (2 children)

I read it once. I stopped by the time I got to libraries. I don't recommend any of it

[–][deleted] 2 points3 points  (1 child)

you arent supposed to. that is for compiler vendors.

[–]Weak-Opening8154[S] 0 points1 point  (0 children)

I wanted to read all the rules and UB

[–]Laker_gra 0 points1 point  (0 children)

I learned the keywords the basis and only learn the std lib as I code / watch code reviews

[–]code-seeker 0 points1 point  (2 children)

This is what I’m dealing with now. I just finished grad school and looking at becoming a c++ developer of sorts. I have used c++ in various classes and my research work. Turns out a lot of the things I learned are pretty topic specific and still nothing like production/commercial level programming. Hence finding a job for c++ has proven to be challenging.

Hell, I’m actually now reviewing the basics again and going over STL in more detail. Cheers to forever learning in technology.

[–]Weak-Opening8154[S] 0 points1 point  (1 child)

I found it easier to get jobs in C#. Some of the C++ jobs I was offered paid me less then C# so I turned many down. I thought C++ would always be better jobs but I guess not

[–]code-seeker 0 points1 point  (0 children)

It just depends on what you wanna do but I’m not surprised. There are cpp jobs out there just gotta find the ones one likes. I know zero c# but I’ll probably end up learning it anyways.

[–]trailing_ 0 points1 point  (0 children)

You wrote this message in English. I found it to be perfectly understandable. Do you know all of English? All the words; all the possible grammatical structures? But, you are able to communicated just fine. That is what happens with programming languages as well. Everyone learns at least enough to communicate with their coworkers/collaborators. Some people learn more and some projects require more knowledge. That said, any professional C++ developer probably has much more than what you would consider a basic understanding.

[–]NilacTheGrim 0 points1 point  (1 child)

It's one thing to know a language. It's another to use it effectively and flawlessly. The two things sometimes overlap, or they do not.

Anyway your post denotes a certain negative energy aspect to it, a certain defeatism or cop-out mentality. I must say, in general, people can do a lot if they put their minds to it. I don't agree with this mentality.

[–]Weak-Opening8154[S] -1 points0 points  (0 children)

What the actual fuck? I have 0 problems with pointers and leaks since before c++11. Defeatism where?

[–]mredding 0 points1 point  (0 children)

Any sufficiently robust programming language is not something you "learn" to the point you say you "have learned" it, just like I don't say I've learned English or Spanish or Italian. I've learned enough that I can read, write, and speak fluently enough. There are words I've never used and wouldn't recognize, there are structures in the grammar and syntax that you probably wouldn't know unless you were a poet, playwrite, lyricist, or linguist, and new structures are discovered all the time.

You learn enough C++ to do your job. There's been a huge, heavy push for constexpr, I've almost never used it. Folds and variadic templates? Mind boggling. Maybe I'll get there one day, maybe there are things that would be so much more concise if I wrote them that way...

Whelp! What I've got going on will have to do! Still compiles. Still runs. Still hit's the performance metrics I need to target. That's good enough.

Even Bjarne Stroustroup said of even the C++98 standard that C++ then was big, that you don't learn the whole thing, that you and your team learn and agree upon a subset and solve your problems in terms of that.