Comments and Questions for Chapter 2
Dear Ivor Hortons and readers of the Beginning Visual C++ book,
I have some thoughtful idea after reading halfway through chapter 2. I would like to share with you.
1. In Try It Out ( Exercising Basic Arithmetic) pg69
I realize that the author are not consistent in naming variable convention. You will notice that the author name a long variable
inconsistently i.e. name with and without a '_'
For examples : rollwidth, rolllength, nrolls
Consistent in naning variables will help you coding better and professional. I suggest either use the '_' for long variable or do not use '_' at all.
For example: rollwidth, rolllength, nrolls, stripsperroll, stripsreqd
OR roll_width, roll_length, n_rolls, strips_per_roll, Strips_reqd
In this particular case, using '_' makes your variable more readable and understandable.
2. Incremet and Decrement operators are very confusing topic because the position of the operator. If you do not sure how the position of the operator will affect your code (different C++ compiler and/or different version might give different result), I suggest writing extra lines because your code is clearer and easier to maintain.
Instead of writing : total = count++ +6;
You can write as : total = count + 6;
Fancy code is good but precision is first priority. What is the point of writing buggy fancy code or codes that you can not understand 6 months later.
3. On page 74, the author discusses about Modifying a Variable where we can write "lhs op = rhs" and op is any of the following operators :+ , - , * , /, % , << , >> , &, ^ , >
Can anyone explain how the << , >> , &, > operator work ? Demonstrative code are welcomed.
4. The Comma Operator on page 76 Ex2_06.cpp
can anyone tell me more about the comma operator usage in C++ ?
The example doesnt help much on understanding the comma operator
num4 = (num1 =10, num2=20, num3=30); // num4 get the value 30
which equals to
num4 = 30;
What is the point of using comma operator if we can write a shorter code ?
Thank you for reading.