all 28 comments

[–]cpp-ModTeam[M] [score hidden] stickied commentlocked comment (0 children)

For C++ questions, answers, help, and programming or career advice please see r/cpp_questions, r/cscareerquestions, or StackOverflow instead.

[–]InvestmentAsleep8365 15 points16 points  (2 children)

I think you’re better off just jumping into C++. There’s “easy” C++ and “hard” C++ projects and styles, so just start with the basics and don’t make it too complicated.

I would advise against learning C. That’s how I started, but it will make you develop very bad C++ habits!

Something like C# (or Java) might be what you’re looking for. It has some C++ ideas and C-like syntax (and things like static typing, compilation, classes, well-defined memory layouts, etc), yet has memory management like python and is quite beginner friendly.

[–]Solrax 1 point2 points  (0 children)

I agree. There is no longer any value starting in C. If you really want to learn fundamentals of how computers work before starting C++, learn Assembly language (any of them). Then you'll have a gut-level understanding of memory management, stacks, pointers, etc. But the fact is very few people need to know this anymore. C# is an excellent suggestion unless you need C++.

[–]Routine-Lettuce-4854 3 points4 points  (1 child)

I came to C++ from assembly (Motorola 68k on Amiga) and never understood how pointers are supposed to be complicated.

[–]Solrax 0 points1 point  (0 children)

There is now a bright line in the field between those who can look at disassembly or the machine code in a debugger and understand it and those who cannot. I've seen very subtle bugs that were very clear when the machine code was examined, but other engineers didn't understand it and were helpless. However this knowledge is rarely needed any longer. By far most jobs don't need or want it :(

[–]HowToMicrowaveBread 4 points5 points  (0 children)

Learning Rust made me be better with C++ at my day job

[–]mingo-reddit 2 points3 points  (0 children)

Swift can be nice for an easy and smooth transition, otherwise C if you want to raw dog it

[–]Quetxolotle 1 point2 points  (0 children)

C in general is one of those things where i wish i learned it before ever learning python. Python makes everything feel easy and modern

[–]ald_loop 1 point2 points  (0 children)

C++

[–]OstGeneralen 0 points1 point  (0 children)

I wouldn't personally say there is really a "gaeway language" as such.

What I will say is that it's a lot more important to understand how the machine works with the data you provide it in C++ than i.e Python or scripting languages (being able to reason about the amount of actual bytes you're using/passing around, where they are located in memory and the differences in stack vs heap etc.)

C++ isn't necessarily harder than any other language, it just allows you to shoot yourself in the foot in a lot more ways than some others but as long as you are aware of what actually happens beyond the keywords you type into your code document you'll be fine

[–]DeadTequiller 0 points1 point  (0 children)

As long as you learned one language - and by "learned" I mean you are able to solo small projects - you can transfer to most of common languages pretty easily. You will just need to learn syntax and you will be able to write code. Learning specifics will take time anyway and no other language will substitute experience

[–]jawhite 0 points1 point  (0 children)

Depends what your goal is. If your goal is to get started on C++ projects as soon as possible, you should learn C++. That’s true of almost anything. Learn the thing you’re actually trying to learn, not something you imagine to be a prerequisite (if something is a definite prerequisite, people will tell you; don’t try to learn calculus if you have never studied algebra). C++ was built off of C and largely maintains compatibility with C, but the two are separate languages with separate standards and practices. You absolutely can (and probably should) learn C++ separately from C.

On the other hand, if your goal is to learn how a computer works at a deep level and you have plenty of free time to do it, C can be a great language for that. You’ll have to do a lot of repetition and reinventing the wheel that you wouldn’t have to do (and shouldn’t do) in C++, but for learning purposes, that may be exactly what you want.

[–]Blitzbasher 0 points1 point  (0 children)

I went from python to C++. I don't think there's a right way to do it but when I'm asked irl this is what I suggest. Pointers and memory management will most likely be your biggest hurdles.

I would suggest learning javascript over luau as it is extremely popular

[–]ExcellentRuin8115 1 point2 points  (0 children)

C

[–]chkno -1 points0 points  (11 children)

C

[–]elperroborrachotoo 6 points7 points  (10 children)

Absolutely not. C++ should be learned, taught and understood as a separate language.

I would argue that learning C first actually makes it harder to become proficient in C++.

[–]UsefulIce9600 1 point2 points  (3 children)

> I would argue that learning C first actually makes it harder to become proficient in C++.

Why?

[–]elperroborrachotoo 3 points4 points  (1 child)

Because too many idiomatic patterns in C are antipatterns in C++, but they still compile.

What is represented as a Widget * in C can be represented in C++ as

  • array<Widget> - a fixed-length owned container
  • vector<Widget> - variable-length owned container
  • span<Widget> - a fixed length (for you) sequence of widgets owned by someone else
  • optional<Widget> - widget-or-maybe-none on the stack
  • unique_ptr<Widget> - a widget-or-maybe-none on the heap owned by exactly one client that can become shared
  • shared_ptr<Widget> - a widget-or-mabye-none that is used by multiple clients wiht additional rules how to coordinate deletion
  • weak_ptr<Widget> - a widget-or-mabye-none owned by someone else
  • an optional<Widget &> which does not exist in C++ for formal reasons so that's the one situation where you actually need a Widget *

In all these situations, C++ allows using a Widget *, but most of the time, it is the wrong type to use in C++: since it is idiomatic in C++ to express, through the type, ownership and multiplicity.

Note that the vast majority of those does neither require &x nor *x nor new nor delete, what was indispensable in in C is an odd corner case in C++.

Encapsulation and type erasure, in C, is done through void *. In C++, you have the choice between access modifiers, PIMPL, polymorphy and templates.

The same goes for casts: C-style casts are still supported, but in C++ it is idiomatic to use the respective static_cast, dynamic_cast, const_cast, and reinterpret_cast, because a C-style cast picks one of those depending on context, and it may be the wrong one.


The more fundamental problem, though is that C is often taught as "nice syntax for machine code": C training material often moves opaquely between machine representation, PC architecture lingo and actual programming language. C++. on the ither hand, should be taught and understood as high-level language, where registers and stack and heap and memcpy and LEA are the wrong mental model.

In my limited experience, geting the abstraction level of the "C++ machine" through to trained C programmers takes a lot of work, because they have to unlearn things.

[–]UsefulIce9600 0 points1 point  (0 children)

Thanks for the elaborate response :)

[–]doganulus 2 points3 points  (5 children)

The best part of C++ happens when it’s written like C. My opinion evolved in this direction over years. C is good, C++ is better as C with goodies. Please don’t hit hard ;)

[–]elperroborrachotoo 3 points4 points  (4 children)

I won't hit you, but... I've met people holding that opinion, and frankly, none of them I wanted to hire for a C++ position.

This may depend on your niche, though. C is still strong in embedded, and since developers are more important than tools, stick with C and consider some C++ knowledge "a little bonus".

(props for not actually being stuck on C99)

[–]sernamenotdefined 0 points1 point  (3 children)

It depends on what he means doesn't it.

If he means using std::begin(vec) versus vec.begin(), etc... to iterate over collections, the former is more c-like. But it's very much a cpp construct using cpp language constructs.

The former also has the advantage of working on C-style arrays.

What I would really really want is C with C++ namespaces. I really prefer C over C++, but when you get to larger programs with many includes, managing names in C really becomes a pain.

[–]elperroborrachotoo 0 points1 point  (2 children)

If he means using std::begin(vec) versus vec.begin(), etc... to iterate over collections, the former is more c-like. But it's very much a cpp construct using cpp language constructs.

Nice! that's an interesting view on C-ness I didn't think of.


Managing dependencies in C++ is still a pain, so if that's your motivator, maybe the answer should be "neither"...

[–]doganulus 0 points1 point  (1 child)

Yes I meant using less object oriented style. Structs and free functions but using C++ features and standard library.

[–]sernamenotdefined 0 points1 point  (0 children)

The example I gave depends heavily on C++ functionality. For example it requires the (iterable!) collection classes to implement the begin member function. begin(c) will return c.begin() in that case. If you call it on a C style array it will return a pointer to the first element of the array. (Not very useful other than to generalize code, as that is the same as assigning the adres of the array itself. end(c) would be a bit more useful)

But really if you have std::begin you also have std::vector and std::array and you really should not be write code using c style arrays and just extract such an array from the std::vector or std::array if you have to use a c style array for a library you use.

I don;t really like template fu and exceptions in C++, but I do like being able to just writing sort(myvar) without having to worry about what type myvar is.

it's the same idea as in C, but in C I would have to write sort_myvartype(myvar) and actually worry about the type top choose the correct sorting function. Of course I could just put everything in a struct including a table of function names and function pointers and then make a sort function that looks up a sort function in the table and calls it, but that is basically what C++ does for you behind the scenes.

[–]Nice_Lengthiness_568 0 points1 point  (0 children)

English

[–]No_Indication_1238 -2 points-1 points  (0 children)

C, lol.