My story about learning C and C++ as a self taught Java programmer (hoping to help someone on the same path)
Posted by Vashh92@reddit | learnprogramming | View on Reddit | 24 comments
Disclaimer: I still consider myself "new" to programming. I'm not an expert by any means. I just want to share my story.
Ever since I started listening to discussions surrounding memory management, I've had a growing interest in C/C++. Several months ago, I began studying open source C++ repositories and trying to put together all the pieces of a mostly complete program.
It was a disaster, honestly. I quickly came to realize that my first impression of programming was overly simplistic and due for a refactor. I depended on the verbose nature of Java more than I thought I did. I took for granted all the things the Java Virtual Machine handled automatically until I was introduced to header files and Cmake. I'd argue this is one of the most important recognitions I've made about programming in general so far. It made me focus more on compiler behavior, pre-compile tasks, and all the madness going on in the terminal rather than just how good I can code, follow exception messages or solve surface level problems.
My advice for new learners of C or C++:
-
Be very patient with it. Take extended breaks (burnout can occur quickly)
-
The coding part will mostly be simple following a tutorial. It's everything else regarding the compiler tasks, headers, proper linking, and so on that will be troubling because it's not common for Java programmers to deal with that.
-
Reading code others wrote in C++ will be madness, but it is necessary for learning. Stay resilient. You'll eventually start following the logic more easily.
-
There are several C/C++ compilers out there. make sure you're choosing the one the project you're looking at expects. It's been an unexpected sticking point for me. People say the compiler won't make any meaningful difference in performance, which can be mistaken as saying the compiler choice doesn't matter at all. It will matter, just not for performance.
-
Cmake is a friend, not a foe. Follow its instructions and download the CMake UI so you can see all the missing data at once. It'll mostly be seen in large projects.
-
Building a project is less about the code itself and more about file linking. Pointing the compiler to all associated files is top priority to learn (in my opinion)
-
C/C++ makes no assumptions about your platform. That's more significant than I first imagined. It's another thing the JVM handles under the hood
If I am misguided about any of this, please let me know. Drop some stories in the comments about your learning experience as well and I'll happily read them
Ppysta@reddit
Rust has manual memory management and good tooling. Bad tooling and a lack of a module system (introduced in C++ only in C++20!) are not inherent to "low-level" programming
Vashh92@reddit (OP)
I believe you, but when you say good/bad tooling, what might be a good example of this? Just for some extra context. That would help me greatly
Ppysta@reddit
compare make/cmake to build projects and dependency managent with cargo for rust. Modern mainstream languages have invested much more on tooling. Cross-compilation is not easy in C++ but it is in zig and go (although go is not with manual memory management), and you can use the zig compiler to also compile C files. Just some examples to say to not confuse bad tooling with what is essential
New-Leader6336@reddit
Interesting perspective. Mine was the opposite. I started as a highschooler in the early 2000's with a college book I found at a garage sale for C++. I started with that as well as C. This kicked my ass thoroughly, but I managed to join a closed source project for an old MMO game emulator. There was another one that was the competitor around 2003 that was open source. We had decided to merge but they made an interesting choice during the merger. This strange language called C#. This was a very early version of it. But I couldn't believe how cool and approachable it made things. I personally loved it. Others hated it and said nothing serious could ever be built with it. But me being new to this, I loved the idea of removing so much complexity behind things like memory management, it was like magic. You could get so much money done by doing less. This decision fractured the team. The C++ diehards refused to work with it and eventually left to continue the C++ version, I stayed on the C# version. Fast forward some years, the C# version was pumping out more and more features while the C++ version couldn't keep up. Eventually the C++ version of this project died out, but the C# project is still alive today (sort of, it's gone stagnant since about 2018 or so). But it's incredible to see how far C# has come over the years. It's what I use in my current job (the little bit of coding an architect does anyway).
I think it's important to know how languages like C/C++ work as they provide a better understanding of what's going on under the hood. But I also think it's better for someone new to start with something more approachable like Java & C#. That's good you decided to delve into it after learning Java. It's all good stuff to know, but certainly not a requirement. If anything, can make you really appreciate everything these higher level languages are doing for you.
Vashh92@reddit (OP)
I personally haven't used C#, but I can tell it's often underestimated in discussions. I'll spare you my impulsive (but positive) thoughts about the "Microsoft Java" discourse and stay focused haha. I had one major question, but I decided to go look it up online first and found my answer 😅
Had to remind myself that garbage collection is in fact optional in C# (comes standard under certain conditions) and c/c++ (through libraries). Anyway, this is a fun perspective. Really cool that you found your entry into programming with such an interesting project. Sounds like I shouldn't be afraid to try game dev in C#
courtesy_patroll@reddit
Why tho?
inbetween-genders@reddit
To have people talk and then they’ll promote some link or something. So many of these the sub and/or Reddit is 🤢 to use. The good thing is I just whatever they are trying to promote to the blocklist.
Vashh92@reddit (OP)
Didn't realize this post would be seen as trying to promote something. Guess I should have thought about this a little more
New-Leader6336@reddit
Ignore them, nothing wrong with sharing your story. I don't see how they could view this as promoting something.
snowyinaba@reddit
it's literally just a post about their story, there isn't anything like "i decided to develop an app and blah blah". i get where you're coming from but this is a genuine post
Vashh92@reddit (OP)
Why not? Haha. What an odd first comment. What are you thinking about?
no_regerts_bob@reddit
If you want to manage memory yourself, c/c++ is going to let you do that much more directly. If you don't know how or don't want to worry it, java does a very good job for you
Vashh92@reddit (OP)
That's the part that I find interesting. I've heard many garbage collectors operates somewhat unpredictably. Is this true? I'd like to know if there's a relatively easy way to compare your skills to the garbage collector (relative to completely remaking your program in the garbage collected language)
no_regerts_bob@reddit
Java GC is very predictable and configurable but it's not super easy to understand without maybe understanding more than your program really needs to know to work. You can make the GC in java log what it's doing and why pretty easily.
Can you do better? Almost certainly yes. Do I care on most of my projects? Nope
Vashh92@reddit (OP)
I'll have to learn how to do that. That's kind of cool
Joe-Arizona@reddit
I’ve been learning C++ for about a year now, programming for almost 3.
C++ for all of its complexity makes sense to me. Compiling with multiple files is definitely not easy but it is logical. Finally figured out how to use raylib with make enough to create my own projects.
I haven’t played with Java much but the idea of a black box like JVM really turns me off to it.
Vashh92@reddit (OP)
Also, thanks for reminding me that I need to look into raylib. I haven't done much UI with C++ yet
Joe-Arizona@reddit
It seemed like the next stop after making a bunch of basic terminal programs. More experienced programmers might have different opinions but raylib seems like a novice friendly but still powerful library to get into GUI/game/graphics programming. The documentation and examples have been easy to digest so far.
Vashh92@reddit (OP)
Glad to hear it. UI in java comes pretty much standard with the JVM. I can make Java UIs all day and do all sorts of stuff with them. The fact that you can just define 3 components just like primitive types, set their coordinates and slap them on the screen is probably insane to a C dev. With the JVM missing, I was wondering if I needed to go digging for the Windows standard UI library or something 😅
Vashh92@reddit (OP)
As I began learning about low level languages, I also began to feel like I was missing out on something important in Java. I was shocked to find out just how much was hidden about how Java operates. I feel like I just entered a whole new world of programming. I still use Java, but I feel way more motivated to try a bunch of things in C and C++
Joe-Arizona@reddit
I started in total beginner tutorial hell with JavaScript and web development. The more I learned about operating systems and CS the less it felt like “real programming.” It all seemed so hand wavey and hides so much from the programmer. Perfectly fine for its purpose but I wanted to know how things actually worked. I learned Python for a little bit but ran into the same thing so I decided to learn C and NASM. It was eye opening to see what is actually happening. Playing with assembly helped a ton with my understanding of linking and compiling.
The lower I’ve gone the better I’ve had an appreciation for programming. C++ feels like a perfect middle ground of low level and high level programming to me so I decided to make it my primary language. It isn’t easy but I love it so far.
quickiler@reddit
As someone who started with C and learning Java. Java felt like magic, i just toss stuffs around and everything are handled automatically. Of course i haven't the ugly side of Java yet but i am enjoying it atm.
Vashh92@reddit (OP)
Yes, Java has been very free-flowing when it comes to just how quickly I can get something started. Having started the opposite way around, learning C and C++ has just been painful without all the guardrails and JVM magic, but also very valuable. I feel like I have a much more mature perspective on Java by learning C. I think my transition to learning C has led me to feel less opinionated about languages. I don't feel any need to argue for or against any particular languages
Rain-And-Coffee@reddit
Two other adjacent languages are GoLang & Rust.
They’re like C/C++ (without classes) and using some of the lessons learned from C++.
GoLang itself is a small language you can pick up pretty fast.