EdgarsMelnalksnis / TXTfileGame

Create a track for car in .txt file and drive in console
1 stars 0 forks source link

fix spacing #4

Open krisjans opened 5 years ago

krisjans commented 5 years ago

https://github.com/EdgarsMelnalksnis/TXTfileGame/blob/ac62fa5bf0acc4795105936efc5e8b9f2efb249b/track.h#L60-L67

use spaces to make expression more readable

krisjans commented 5 years ago
for (k = 0; k < 41; k++) 
{ 
     if (laukums[k][r] == '@' | laukums[k][r] == '$') 
         cout << " ";    //@ un $ vietaa izvada atstarpi 
     else if (k == f1.getKolonna() & r == f1.getRinda()) 
         cout << "o"; 
     else 
         cout << laukums[k][r]; 
krisjans commented 5 years ago

There should be spaces around operators (+, -, =, ==, >, <, etc) - this makes expressions easier to read;

krisjans commented 5 years ago

And after fixing spaces in code sample in previous commit - i spotted a bug: "|" is bit-wise OR. "||" is logic OR.

if (laukums[k][r] == '@' | laukums[k][r] == '$')

Cleaner way of this expression is

if ((laukums[k][r] == '@') || (laukums[k][r] == '$'))

Extra parentheses helps to clearly separate logic operations (instead of relaying on operator precedence (https://en.cppreference.com/w/cpp/language/operator_precedence) and makes code easier to read.

Same abouit & and &&.