New ask Hacker News story: Ask HN: Declaration of variables in C++ best practices

Ask HN: Declaration of variables in C++ best practices
2 by sigmaprimus | 0 comments on Hacker News.
Hi, I recently decided to read over the C++ tutorials @ learcpp.com and found in their examples that they are declaring and assigning values to variables as they are used. Years ago when I began coding it was common practice to declare all variables(and constants) with comments at the beginning of the script rather than in the middle of the script as they are needed. Is there a good reason why this practice is not encouraged now? Or is it still best practice to declare up top? Maybe they are just doing this for the purpose of the tutorial to make grasping basic concepts easier?

Comments