Tag: books

Entries for tag "books", ordered from most recent. Entry count: 7.

Warning! Some information on this page is older than 6 years now. I keep it for reference, but it probably doesn't reflect my current knowledge and beliefs.

Pages: 1

# Book review: C++ Initialization Story

Mar 2023

Courtesy its author Bartłomiej Filipek (author of cppstories.com website), I was given an opportunity to read a book “C++ Initialization Story". Below you will find my review.

How many ways are there to initialize a variable in C++? I can think of at least the following:

int i1;
int i2; i2 = 123;
int i3 = 123;
int i4(); // function declaration not a variable
int i5(123);
int i6 = int(123);
int i7{};
int i8 = {};
int i9 = int{};
int iA{123};
int iB = {123};
int iC = int{123};

Do you know the difference between them? Which variable stays uinitialized, which is initialized with a value 0 or 123? What if I used a custom type instead of the basic int? How many copies of the object would be created? What if that type was a class having some custom constructors? Which constructor would get called? What if it was a std::vector or some other container?

Question like this is the foundation of this book, but topics covered by it are much wider. This book is a relatively big one. On 279 pages, the author treats the topic of "initialization" as an opportunity to describe various concepts of C++ language. Modern versions of the language standard are covered, up to C++23, but features that require new versions are explicitly marked as such. The book is not about some exotic quirks and tricks that can be done by stretching the language to its limits, but it is about concepts that are fundamental in any C++ program.

Initialization of local variables, as shown in the code above, is just the subject of the first chapter. Then initialization of "non-static data members" is described, which basically means variables inside structures and classes. Constructors obviously play the major role here, so their syntax and behavior is also described in details here. When talking about constructors, description of assignment operators and destructors follows naturally. Of course, these language constructs are described also in light of move semantics introduced by C++11. For example, did you know that std::vector<T> on resize will be able to use move constructor of your type T instead of performing a copy only when the move constructor is marked as noexcept?

Another topic related to initialization is an automatic deduction of types: auto keyword and template arguments. Special kinds of variables - static and thread_local are also described. The book also teaches new language constructs added for convenient variable initialization, like structured binding, designated initializers, or static inline. If you only used the old version if C++ so far, do you know that following syntax is now possible? Do you know what it means?

auto[iter, inserted] = mySet.insert(10);

Point p {
    .x = 10.0,
    .y = 20.0

class C {
    static inline int classCounter = 0;

When it comes to the difficulty level of the book, I would call it intermediate. Only some knowledge of C++ is required. Author explains every topic covered from very basics and shows simple code samples. The book additionally features a quiz in the middle and at the end, as well as a chapter with "techniques and use cases". For example, did you know that the most robust and efficient way to initialize a class with a string is to pass it by... value?

struct StringWrapper {
    std::string str_;
    StringWrapper(std::string str) : str_{std::move(str)} { }

For a long time I've been skeptical about new language standards like C++11, C++14, C++17, C++20. C++ is a tough language already, so every fresh addition only adds more complexity to it. It used to remind me of some elaborated, tricky Boost-style templates. But now, the more I use new features of the language (at least in my personal code), the more I like it. I always liked RAII and unique_ptr, but now with move semantics, return value optimization, std::optional, std::variant, and many other additions to the language small and big, it all starts to fit together. Code is clean, concise, readable, safe (no explicit new or delete!), and efficient at the same time. I now think that it is not an inherent feature of C++ to be verbose (with tons of boilerplate code required) and unsafe (with memory access violation errors easy to make), it is the old-fashioned approach of treating is as "C with classes". I hope that over time more and more developers, especially those who make key decisions in software projects, will also notice that and will allow using modern C++.

The book can be bought as ebook on leanpub.com, as well as in printed version on Amazon. I can strongly recommend it - it is really good! See also my reviews of previous book by this author: "C++17 in Detail" and "C++ Lambda Story".

Comments | #books #c++ Share

# Book Review: C++ Lambda Story

Jan 2021

C++ Lambda Story book

Courtesy its author Bartłomiej Filipek, I was given an opportunity to read a new book “C++ Lambda Story”. Here is my review.

A book with 149 pages would be too short to teach entire C++, even in its basics, but this one is about a specific topic, just one feature of the language – lambda expressions. For this, it may seem like even too many, depending on how deeply the author goes into the details. To find out, I read the book over 3 evenings.

The book starts from the very beginning – the description of the problem in C++98/03, where lambdas were not available in the language, so we had to write functors - structs or classes with overloaded operator(). Then he moves on to describing lambdas as introduced in C++11, their syntax and all the features. Every feature described is accompanied by a short and clear example. These examples also have links to the same code available in online compilers like Wandbox, Compiler Explorer, or Coliru.

In the next chapters, the author describes what has been added to lambdas in new language revisions – C++14, C++17, C++20, and how other new features introduced to the language interact with lambdas – e.g. consteval and concepts from C++20.

Not only features of lambda expressions are described but also some quirks that every programmer should know. What if a lambda outlives the scope where it was created? What may happen when it is called on multiple threads in parallel? The book answers all these questions, illustrating each with a short, yet complete example.

Sometimes the author describes tricks that may seem too sophisticated. It turns out you can make a recursive call of your lambda, despite not directly supported, by defining a helper generic lambda inside your lambda. You can also derive your class from the implicit class defined by a lambda, or many of them, to have your operator() overloaded for different parameter types.

Your tolerance to such tricks depends on whether you are a proponent of “modern C++” and using all its features, or you prefer simple code, more like “C with classes”. Nonetheless, lambda expressions by themselves are a great language feature, useful in many cases. The book mentions some of these cases, as it ends with a chapter “Top Five Advantages of C++ Lambda Expressions”.

Overall, I like the book a lot. It describes this specific topic of lambda expressions in C++ comprehensively, but still in a concise and clear way. I recommend it to every C++ programmer. Because it is not very long, you shouldn’t hesitate with reading it like it was a new project you need to find time for. You should rather treat it like an additional, valuable learning resource, as if you read several blog articles or watched some YouTube videos about a topic of your interest.

You can buy the book on Leanpub. I also recommend visiting authors blog: C++ Stories (new blog converted from bfilipek.com). See also my review of his previous book: “C++17 in Detail”. There is a discount for “C++ Lambda Story” ($5.99 instead of $8.99) here, as well as for both books ($19.99 instead of $23.99) here - valid until the end of February 2021.

Comments | #books #c++ Share

# Book review: C++17 in Detail

Oct 2019

Courtesy its author Bartłomiej Filipek, I was given an opportunity to read a new book "C++17 in Detail". Here is my review:

When I am about to read or decide whether to buy a book, I first look at two things. These are not the looks of the cover or the description on the back. Instead, I check the table of contents and the number of pages. It gives me a good overview of the topics covered and the estimation of chances they are sufficiently covered. "C++17 in Detail" with its 361 pages looks good as for a book describing what's new in C++17 standard, considering the additions to the standard are not as extensive as they were in C++11. The author is undoubtedly an expert in this field, as seen from entries on his Bartek's coding blog.

Author claims to describe all the significant additions to the language. However, this is not a dull, difficult to read documentation of the new language elements, like you can find on cppreference.com. Instead, the book describes each of them by giving some background and rationale, and showing real-life examples. It makes them easy to understand and to appreciate their usefulness. Each addition to the standard is also accompanied with a reference to the official documents by C++ standard committee and a table showing which versions of the most popular C++ compilers (GCC, Clang, Microsoft Visual C++) support it. Spoiler: They already support almost all of them :)

The book doesn't teach everything from scratch. That would be impossible in that number of pages, considering how big and complex C++ is. It assumes the reader already knows the language quite well, including some features from C++11 like unique_ptr or r-value reference + move semantics. It explains however few topics needed for the book in more details, like the concept of "reduce" and "scan" parallel algorithms, which C++17 adds to the standard library.

The contents of the book is grouped into 3 parts. Part 1 describes additions to the C++ language itself, including init statement for if and switch (e.g. if(int i = Calculate(); i > 0) ...), additions to templates like if constexpr, and attributes like [[nodiscard]], [[maybe_unused]]. Part 2 describes what has been added to its standard library, including std::optional, variant, any, string_view, filesystem. Finally, part 3 shows more extensive code examples that combine multiple new C++ features to refactor existing code into more clean and more efficient one. The author also mentions what parts of the language have been deprecated or removed in the new standard (like auto_ptr).

To summarize, I recommend this book to any C++ developer. It's a good one, and it lets you stay up-to-date with the language standard. You will learn all new features of the language and its standard library from it in a more pleasing way than by reading documents from the C++ committee. Even if you won't be able to use these new features in your current project because your old compiler not upgraded for many years or the coding standard imposed by your team lead doesn't let you, I think it's worth learning those things. Who knows if you won't be asked about them on your next job interview?

You can buy printed version of the book on Amazon.com and electronic version on Leanpub. Bartek, the author of the book, also agreed to give all of the readers of my blog a nice discount - 30%. It's valid till the end of October, and to use it just visit this link.

Comments | #C++ #books Share

# DirectX 11.1 Game Programming - Contest Winners

Sep 2013

Congratulations to lightning, WhiteLightning and Francis.C for winning digital copies of "DirectX 11.1 Game Programming", the book I had recently reviewed.

Comments | #books #competitions Share

# Book Review: DirectX 11.1 Game Programming

Sep 2013

"DirectX 11.1 Game Programming" is a new book published by Packt Publishing, written by Pooya Eimandar. It introduces new features of DirectX 11.1 and some other technologies available for game developers when writing Metro-style apps for Windows 8. The book uses C++/CX - a new language based on C++, with the syntax somewhat similar to C++/CLI (the language is extended by managed pointer operator ^). But while C++/CLI is a .NET language (like C#), C++/CX is compiled to native code and the ^ pointer is just a convenient syntax for reference-counting smart pointer to a COM object. Math is done with DirectXMath library (the successor of XNA Math).

Each of the chapters describes several loosely coupled topics. Their flattened list looks like this:

I have mixed feelings about this book. Contrary to what title suggests and what the author claims inside ("By the end of this chapter, we are going to have a multithreaded game engine"), you obviously cannot learn game programming by reading just 146 pages. Especially as the book covers so many different topics. It looks like the author wanted to include everything what's fresh and sexy in Microsoft Windows 8 API-s. As a result, each example is kind of "Hello World" - the simplest possible application of the described technology.

But at the same time, the book is also not teaching 3D games programming from the start. It explains some selected basic concepts in more details (e.g. describes what vertex shader does, shows how rotation matrices look like, how to use constant, vertex and index buffer or shows a diagram of the graphics pipeline - 3 times actually :) but generally you should already know C++ and preferably DirectX 10/11 to make use of the knowledge from this book. It is more like an overview of "What's New" in Windows 8, DirectX 11-11.1 and new Visual Studio.

I think the biggest value of this book is the attached source code. Each chapter is accompanied by a complete C++/CX project that shows an application of the described technology and the text in the book is an overview of this code. So if you already know some game programming in C++ and DirectX 10/11, this book can be a good tutorial which will help you to start using latest Microsoft technologies and develop Windows 8 Metro-style games. Preface says "This book will help you easily create your own framework and build your first game for Metro Style all by yourself in order to publish it on the Windows Store." and that is true.

But whether this is worth doing, that's another question. Surely you can use DX 11 on 9- or 10-compatible hardware, using Feature Level, but you cannot use most of what this book describes below Windows 8, and many of these things also without buying Visual Studio Professional or higher. According to Steam Hardware & Software Survey: Auguest 2013, while 64.78% of gamers already have DirectX 11 capable system and GPU, only 15.41% of them have Windows 8 installed (and it's already a year since its release).

Now it's time for a contest. Packt has proposed to offer 3 digital copies of the book. All you need to do is head on over to the book page, look through the product description of the book and then drop a line via the comments below this post to let us know what interests you the most about this book. 3 best comments win!!! Deadline: The contest will close in 1 weeks time. Winners will be contacted by email, so be sure to use your real email address when you comment.

Comments | #books #competitions #reviews #directx Share

# HLSL Development Cookbook - Contest Winners

Aug 2013

Congratulations to Tommy, czoper and Mark for winning digital copies of HLSL Development Cookbook, the book I had just reviewed.

HLSL Development Cookbook

Comments | #competitions #books Share

# Book Review: HLSL Development Cookbook

Aug 2013

I've been given a chance to read a book HLSL Development Cookbook published recently by Packt Publishing. Below you can find my review. Packt has proposed to offer 3 digital copies of the book. Keep reading to find out how you can win a copy.

The book has 224 pages. Its author - Doron Feinstein - works as Senior Graphics Programmer in Rockstar Games. The book is about implementing various rendering techniques in HLSL using DirectX 11. It uses new features of this API, e.g. geometry shaders, compute shaders, UAV, tesselation etc. It presents very professional approach and does not over-simply anything for educational purposes (for example, the author uses linear space for color computations, explains HDR rendering and passes reciprocal value as constant where appropriate as multiplication is faster than division).

The book assumes that reader already knows DirectX API and is able to code a framework that loads meshes, textures, constant buffers and all the stuff and pass it to GPU rendering. He should also already know the concept of shaders and the HLSL syntax, not to mention math/geometry basics of 3D graphics (like properties of dot product or transformation matrix). So this is definitely not a book for complete beginners who want to learn game programming from scratch. It does not even give complete shaders to just copy-paste into your engine, but fragments (functions) that are interesting in some technique. Which I think is good, because where per-pixel parameters of your material come from (like albedo color, normal vector, specular intensity and exponent) - whether from texture, a constant or some computations - is up to you and the book focuses on what to do with it without boring, multipage code listings.

Subsequent chapters cover following topics:

  1. Forward lighting: Describes straightforward implementation of different types of lights - hemispheric ambient light, directional light, point light, spot light and capsule light (with explanation of Lambert law for diffuse, and Blinn-Phong model of specular), as well as texture projection from point light and spot light.
  2. Deferred Shading: Introduces concept of deferred lighting (requires rendering geometry 2 times) versus deferred shading (requires rendering geometry 1 time, used in this book). Mentions different ways of storing nomals in GBuffer and of course reconstructing world-space position from Z-buffer depth. Shows implementation of same types of lights in the deferred way.
  3. Shadow Mapping: Covers shadows from spot lights and point lights, PCF (Percentage-Closer Filtering), Cascaded Shadow Maps for directional light, PCF with varying prenumbra size and visualizing shadow maps with silhouettes highlighting.
  4. Postprocessing: Describes HDR Rendering (calculates average luminance for tone mapping in compute shader) with exposure adaptation, Bloom, DOF (Depth of Field) and Bokeh (all done on GPU).
  5. Screen-space effects: Describes SSAO (Screen Space Ambient Occlusion), lens flare (using occlusion query and predicate query), reflections and sun rays, all done as screen-space effects.
  6. Environment effects: Describes dynamic decals (as an example of using stream out feature to generate mesh on GPU), distance/height-based fog and rain (as simple example of stateful particle system colliding with scene geometry, calculated entirely on GPU).

That's not a "gems"-style book with every chapter being a separate article written by different author. But each chapter is a complete "recipe" for a rendering technique, whether an implementation of particular type of light or some other visual effect. Each one of them is divided into sections:

As you can see, described topics are not some sophisticated and specialized effects like rendering foam on an ocean coast or crowd on a stadium, but fundamental techniques needed by every engine. Just as the book says: "Lighting and postprocessing are two of the most important fields in 3D rendering."

Summary: This book is not intended for complete beginners, but if only it fits the knowledge you already have and the knowledge you currently seek, I think this it can be a great step on you path of learning game/graphics programming.

Now here is how you can have a chance to win eBook copy of this book: All you need to do is head on over to the book page, look through the product description of the book and then drop a line via the comments below this post to let us know what interests you the most about this book. 3 best comments win!!! Deadline: The contest will close in 1 weeks time. Winners will be contacted by email (before the end of this month), so be sure to use your real email address when you comment.

Comments | #books #competitions #reviews Share

Pages: 1

[Download] [Dropbox] [pub] [Mirror] [Privacy policy]
Copyright © 2004-2024