+ 1

Could I get a few simple tips on GOOD C++ coding practice? :)

I've recently finished the C++ course and I'd like to learn what people think are some good things to keep in mind when working with C++

28th Jun 2016, 8:40 AM
Micah Chaffin
Micah Chaffin - avatar
2 ответов
+ 4
* Use descriptive variable names, not just single letters. * Comment. Note why you wrote that code there and not what it does. Comments like i++; // increment i are useless, because you can clearly see that. Write why that is happening. * Functions should only perform a single task and be named accordingly. Functions like printRadomNumber(); should be avoided. Write functions like rollDice(); and printDice();. That way the functions only perform a single specific task and you can call them individually. What if you want to get a random number without printing it? What if you want to print the number again? * Little tip: If you have to write the same code multiple times, you probably can optimize your program.
28th Jun 2016, 8:54 AM
MaxCode
0
What Maxcode said can be summed up in one sentence: express your intent clearly and don't repeat yourself. This results in all the things MaxCode said, like using descriptive variable and function names, comments etc.
29th Jun 2016, 9:03 AM
Stefan
Stefan - avatar