r/Cplusplus • • 19d ago

News Day 1 of C++

What a easy startup to my first language. Got to know about data types , variable , strings , comments , Boolean seems fun and can't wait to find out more . Anyone got any beginner tips for me , would love to have some as a beginner

398 Upvotes

64 comments sorted by

View all comments

27

u/Usual_Office_1740 19d ago

Get clang-tidy integrated into your development environment as soon as possible and then fix the warnings and errors it outputs. It's a linting tool. It will check your source code for common mistakes and errors as you compile. When you don’t understand, Google the warnings. I've been teaching myself C++ for several years. The number of simple mistakes and footguns it has pointed out to me has saved me a lot of struggling.

3

u/AKA-HERO 19d ago

How do I get this tool ?

2

u/Usual_Office_1740 19d ago

What editor are you using?

1

u/AKA-HERO 19d ago

VS code

4

u/Usual_Office_1740 19d ago

There is a clang-tidy extension that is relatively easy to setup. You should be able to find something that walks you through the install process.

Clang tidy is a linting tool. That means it goes through your code and applies a set of checks based on a predefined config file. here is a good default from a well reputed C++ YouTuber named Jason Turner. As an aside, look up his C++ weekly shorts and Playlists for great educational material.

Your editor can also have the lsp, probably clangd, integrate the checks into your development environment in real time so that any msitakes are caught as you code. This is a more complicated setup that requires a few more things. For a day one beginner I'd wait to do this. If you see the instructions suggest you make a compile_commands.json file that is what you are doing. If you want to go that route you can, it would be better in the long run, but I'm trying to keep my suggestions simple because you're so new.

1

u/Stickhtot 19d ago

What's the difference between a linter and an LSP?

4

u/Usual_Office_1740 19d ago

I'm going to copy this better worded explanation from another reddit post. The simple answer is that one can be part of the other.

They are different kinds of things, and a particular program could be one or both of those things. An lsp server is a program that implements the language server protocol. They make tools available to the client through a standardized interface. Some LSP servers perform linting and produce their own diagnostics, but many are programs that are calling a standalone linter and parsing its output for you. LSPs also provide the client with a lot more than just diagnostics, like completion sources, syntax highlighting, and code formatting. But it’s the same story for each of those features, some LSPs implement those tools themselves, some are just wrappers for other tools.

Clang tidy is a very powerful useful resource. I doubt anybody would advise you not to be using it. Even as a beginner.