Beautiful C++: 30 Core Guidelines for Writing Clean, Safe, and Fast Code

id: 812104 VIP Open in MaM

By Kate Gregory, J Guy Davidson

Language: English

Category: Ebook - Computer/Internet

Categories: Computer/Internet

Size: 11.4 MiB epub Files: 1

Uploader: draino

Uploaded At: 2022-03-04 00:31:53

Addison-Wesley Professional; 2022, C++ Programming

Description


Discover the Beauty of Modern C++


" Beautiful C++ presents the C++ Core Guidelines from a developer's point of view with an emphasis on what benefits can be obtained from following the rules and what nightmares can result from ignoring them. For true geeks, it is an easy and entertaining read. For most software developers, it offers something new and useful."

--Bjarne Stroustrup, inventor of C++ and co-editor of the C++ Core Guidelines


Writing great C++ code needn't be difficult. The C++ Core Guidelines can help every C++ developer design and write C++ programs that are exceptionally reliable, efficient, and well-performing. But the Guidelines are so jam-packed with excellent advice that it's hard to know where to start. Start here, with Beautiful C++.

Expert C++ programmers Guy Davidson and Kate Gregory identify 30 Core Guidelines you'll find especially valuable and offer detailed practical knowledge for improving your C++ style. For easy reference, this book is structured to align closely with the official C++ Core Guidelines website.

Throughout, Davidson and Gregory offer useful conceptual insights and expert sample code, illuminate proven ways to use both new and longstanding language features more successfully, and show how to write programs that are more robust and performant by default.



For ease of experimentation, all sample code is available on Compiler Explorer at https://godbolt.org/z/cg30-ch0.0


Table of Contents

Section 1. Bikeshedding is bad

1.1. P.2: Write in ISO Standard C++
1.2. F.51: Where there is a choice, prefer default arguments over overloading
1.3. C.45: Don't define a default constructor that only initializes data members; use in-class member initializers instead
1.4. C.131: Avoid trivial getters and setters
1.5. ES.10: Declare one name (only) per declaration
1.6. NR.2: Don't insist to have only a single return-statement in a function

Section 2. Don't hurt yourself

2.1. P.11: Encapsulate messy constructs, rather than spreading through the code
2.2. I.23: Keep the number of function arguments low
2.3. I.26: If you want a cross-compiler ABI, use a C-style subset
2.4. C.47: Define and initialize member variables in the order of member declaration
2.5. CP.3: Minimize explicit sharing of writable data
2.6. T.120: Use template metaprogramming only when you really need to

Section 3. Stop using that

3.1. I.11: Never transfer ownership by a raw pointer (T*) or reference (T&)
3.2. I.3: Avoid singletons
3.3. C.90: Rely on constructors and assignment operators, not memset and memcpy
3.4. ES.50: Don't cast away const
3.5. E.28: Avoid error handling based on global state (e.g. errno)
3.6. SF.7: Don't write using namespace at global scope in a header file

Section 4. Use this new thing properly

4.1. F.21: To return multiple "out" values, prefer returning a struct or tuple
4.2. Enum.3: Prefer class enums over "plain" enums
4.3. ES.5: Keep scopes small
4.4. Con.5: Use constexpr for values that can be computed at compile time
4.5. T.1: Use templates to raise the level of abstraction of code
4.6. T.10: Specify concepts for all template arguments

Section 5. Write code well by default

5.1. P.4: Ideally, a program should be statically type safe
5.2. P.10: Prefer immutable data to mutable data
5.3. I.30: Encapsulate rule violations
5.4. ES.22: Don't declare a variable until you have a value to initialize it with
5.5. Per.7: Design to enable optimization
5.6. E.6: Use RAII to prevent leaks

Other Torrents

Ebook - Computer/Internet
VIP
Beautiful C++: 30 Core Guidelines for Writing Clean, Safe, and Fast Code
by Kate Gregory, J Davidson
Educational, programming, PDF
pdf | 1 comment
Computer/Internet
1
16.6 MiB
2022-03-06 01:21:36
dlee
35 seeders
0 leechers
170 snatches