Well written C ++ examples

I am currently learning C ++ and want to start reading other source codes to pick up hints. I was wondering if anyone has examples of well-written C ++ that I can take a look at (rather than pick bad habits)

+7
c ++ coding-style
source share
6 answers

As you probably discovered, there are many online sources for C ++ code examples. Stackoverflow, CodeProject, etc. Have source examples. But, of course, they are found throughout the map in terms of quality and educational value.

I think books in this area have still surpassed the Internet. There is no substitute for visiting a bookstore, viewing several volumes, and choosing what you think is readable. They were tested for reading (as opposed to online submissions), so samples are more likely to work and be of high quality.

Although books usually have small snippets of code or a few features, they usually come with a CD or a URL that points to more comprehensive examples.

O'Reilly, Thinking in C ++, Petzold and Wrox (and much more) have good books in C ++.

+7
source share

Boost library? It is generally believed that written C ++ code of the highest quality is written. (Many of them are also more or less unreadable if you yourself are not a C ++ guru)

In general, I would advise you to be careful with this approach. In C ++, the source code will probably not be as informative as in many other languages.

If you see some kind of Python code, you can pretty much consider it correct while it works. If it is written by someone who seems to know what they are doing, you can even assume that it is well written.

In C ++, there are just a lot of nasty traps and subtle exceptions for every rule that you really need to know what you are doing. Switching to what compiles or works, or what you saw in other source code, is dangerous and to a large extent guarantees that you will sooner or later end up with a program that relies on undefined behavior and will work when you least expect it .

If I were you, I would try to stick with books. There are some very well written ones that, in addition to seeing some source code, also teach you the “correct” language. And while you adhere to authoritative authors, you will be convinced that they will not teach you any bad habits or will not render you in an intolerable code.

+4
source share

In my opinion, if you read a good book in C ++ (for example, "Programming language in C ++", "(Optional) effective C ++" or "Exceptional C ++"). You will not only learn good practices, but also need to understand how to write code.

Of course, the patterns in these books are mostly artificial. If you read “real-world applications,” you will always come across snippets of code that are pretty ugly, but sometimes it wasn’t just a pretty clean solution (or a not-so clean solution was more efficient in terms of speed).

Therefore, I do not know whether it is better to start working with real applications, since they can also be very overwhelming due to coding complexity and complexity, while the code examples in the books are compact and clearly laid out.

I think for starters you would be better off reading links such as the books I have listed. If you have to be flexible at some point in the future and have to create ugly code, you at least know that this is ugly code and you are not mistaken in it, “how it should be”;)

+2
source share

Reading through open source software can be very educational if you already have some knowledge of C ++. If you are just starting out, I think Boost libraries will run right above your head. You can start with the WebKit project, which is a great resource. In addition, Google releases a lot of its source code, which is also very VERY clean: Protocol Buffers are a great example. And while you're on it, you can also read their C ++ Style Guide .

Personally, I started to learn C ++, having collected several books and written some complex applications. Keep in mind that learning a language as vast as C ++ takes a lot of time, such as 10 years .

Many years ago I was told that if I ever wanted a career as a C ++ developer, I would definitely have to read Scott Meyers' Effective C ++. This should prevent you from falling into many language traps. If you find that you need something even simpler, start with Kernigan and Richie's C programming language. Be patient and good luck!

+2
source share

If you want the full project to be viewed, I would recommend Ogre3d . This is a well-structured graphics engine with decent documentation, and the source code itself is also good.

0
source share

How about: Programming: principles and practice using C ++ by Bjarne Stroustrup?

0
source share

All Articles