r/learnprogramming • u/Hot-Adhesiveness8310 • 18d ago
Where should I start learning C++? (planning to switch to Linux)
I want to learn C++ properly. I can already write working code (mostly small Arduino projects), but I know I have gaps in my fundamentals. I'd like to fill them in.
My goal is to build a strong base so it's easier to move to other languages later.
I'm also planning to install Linux on my laptop soon, so I'd like to learn in that environment.
Could you recommend:
the best free resources (courses, books, websites) for someone with my level?
what compiler and editor/IDE to use on Linux?
what topics I should focus on first?
English is not my first language, so sorry for any mistakes. Thanks a lot for your help!
9
u/ConfidentPoem6454 18d ago
Since you can already write working code:
-Wall -Wextra -g -fsanitize=address,undefinedwhile learning. The sanitizers catch the memory mistakes that Arduino code usually lets slide.Topics to focus on first: references vs pointers,
std::vectorandstd::string, classes with constructors and destructors (RAII), thenstd::unique_ptr, and basic CMake for multi-file projects.3
u/Zen-Ism99 18d ago
Website: learncpp.com
Book: Programming: Principles and Practice Using C++ by Stroustrop
IDE: CLion, it’s full featured, free for personal use, and available for macOS, Linux, and Windows
1
u/SigridFischer42 18d ago
Use g++ (part of GCC, usually version 11 or higher on most Linux distros) as your compiler, and try VS Code with the C/C++ extension if you want something beginner-friendly. Focus first on pointers, memory management, and compiling with g++.
1
u/SigmaxAlpha 18d ago
De los IDE que he probado mi favorito es Code::Blocks, es ligero, bastante completo, y gratis. Un favorito personal al para aprender son los libros de Deitel (Harvey M Deitel y Paul J Deitel) tienen un enfoque de 'enseñar haciendo' que es muy bueno para aprender, y puedes hallarlos en varios sitios como pdf, hay de C/C++, java, python...
1
u/redhat_is_my_dad 18d ago
as for editor, there is a high risk of falling into extendable editors (such as neovim, emacs, custom distributions of these and such) rabbithole, i would recommend to just use the one you already know and comfortable with, one day you'll feel like "i just want to spend unreasonable amount of time to learn how to optimize my workflows and completely change my habbits to become more productive" and then i would recommend you to dive deep into this rabbithole, until then – don't even think about it, as it'll be a huge distraction and a waste of time.
1
u/idkfawin32 17d ago
I cannot stress enough how important "The C Programming Language" by Brian Kernighan and Dennis Ritchie is.
It transformed me in many ways when I originally followed it's tutorials back in 2010. You come out of it understanding far better how computers work and it sets you up for success. Obviously you'll have to learn many more things after this and how practices have changed since then, and obviously the many differences C++ has from C, but I still think it's an incredibly important first step.
1
u/Upstairs-Project2756 17d ago
skip CLion and Code::Blocks for now. They hide how the compiler works, which is half the point of learning C++ on Linux. Install VS Code with just the C/C++ extension and learn to use makefiles or cmake manually. If you cannot compile a file from the terminal using g++ before opening an IDE, your understanding of memory and linking will be weak
1
u/mredding 17d ago
Learncpp.com is what everyone recommends, though I can't say for myself; I'm so old I was there when the words were first written, as it were. I always recommend the public library and a book on C++23.
I recommend you install Visual Studio (not Visual Studio: Code or any of the other VS products - Microsoft got REALLY BAD at naming products ~2014). It's as turn-key as we get in the industry. File -> New -> Project. You enter a wizard dialog. Name the project. It will generate a solution file - that's just Microsoft's way of storing configuration, don't worry about it. You want to select a Win32 Console Application. Of all the check-box options, you don't want anything. There should be a check box for an empty or blank project. There's a window called the Solution Explorer, you right click in that and add a new source file. Perhaps you'll call it the traditional "main.cpp". Code your heart out. F5 will save, build, and run.
BEFORE you wipe your drive, I recommend you Install Virtual Box and run Linux in THAT to get started. Any mistakes, and you can just blast the thing and start again. There are ways to take your VM and install it right on the bare metal, so DO treat this thing seriously like your pride and joy, you don't have to sacrifice it when you want to install Linux as your principle OS.
The Unix Way is that everything is a file, and I do mean everything. On Windows, the filesystem is a bunch of disks and data on that disk. But on a unix, all your running processes are files, all your open sockets are files, all your hardware are files; and the filesystem is all of that.
/procisn't data on a disk, it's a virtual branch - it's a view from INSIDE your OS kernel mounted onto the filesystem. EVERYTHING IS A FILE. So it's not like Windows, the filesystem is this big view of the whole running machine, and not everything you see on there is "real", as it were. Two programs can talk to each other by writing to the running process in memory (not the executable program file on the disk), listed under that/proctree. You can do all sorts of amazing things, and you can do it by writing shell scripts (that text command line interface you're soon going to learn about doubles as a script engine).It's worth using the Google AI as a tutor and learning Linux systems. Don't just look at it as a desktop environment you run programs on, the OS is a system of resources for YOU, the programmer. You can learn it in a top-down approach and go as deep as you need. The Unix Way is that you make small programs that do one task very well - a specialist, and you combine those programs together - either by a shell script or platform specific function calls that spawn child programs. If you wanted to go lower than that,
execcomes from a program library that just implements the utility ofexec, and that boils down to some system calls directly to the kernel - you can go all the way down there yourself one day, too, if you wanted.With standard in and standard out, and this filesystem, you can touch the whole world and every corner of your machine. Perhaps ask Google to help you make an example daemon and get it running on systemd - that will be enlightening for you. Then learn DBus and syslog for your programs (please for the love of god don't write your own logger). I really want you to incorporate in your mind that the OS is a PART of YOUR program, and writing C++ and systems software is all about integrating the whole system into the solution. WE don't code in a vacuum, but in an ecosystem of our own making. If you write these huge monoliths, these gigantic black boxes of software, you will have no visibility or control over it but the ad-hoc methods you have to manually reinvent. Poorly. And at first your solution is slow because you're going to start out using the bog standard communication structures given to you, but you can make your software fast. But learn to walk before you run, that gets into a conversation for later.
1
u/Public-Lynx6675 13d ago
Tutorials are fine but there's a point where you have to close Udemy and start writing actual code. C++ makes a lot more sense when you're dealing with compiler errors yourself. Learncpp.com is a great reference and Boot dev can help with the Linux and terminal fundamentals.
-2
u/Due-Result7928 18d ago
learn ai and learn clojure or any functional language. Will make you a far better programmer. Was working for years realtime software in C. It is mostly over outside some niche markets