Wednesday, 15 January 2020

Chapter 10 // Exercise 5 - Principles & Practice Using C++

In this exercise I am using Visual Studio Community 2017 and the header file "std_lib_facilities.h" which can be found here:

http://www.stroustrup.com/Programming/PPP2code/std_lib_facilities.h

Chapter 10 // Exercise 5

Write the function print_year() mentioned in section 10.11.2.


Oh I detested this exercise. It wasn't necessarily hard; the format just made it very confusing. Also, having a vector, in a vector, in a vector almost blew my brains out. I honestly think he made this more complicated than it needed to be just to make you think. The problem is though that you will probably see code like this "in the wild". 

In the first chapters of this book, Bjarne mentions the importance of avoiding magic numbers. However, if you check out PrimitiveComponent.cpp in Unreal Engine 4.10, you'll find this magical snippet:

 int32 UPrimitiveComponent::CurrentTag = 2147483647 / 4;

On a code review a senior thought I had done this; I didn't, it was already there. I asked my manager why they would do this and he asked me why that number was special; I had no clue. He then informed me it was the largest number you can fit in an int32. However, he was confused as to why they didn't just use MAX_INT or const instead of some ridiculous magic number.

No comments:

Post a Comment