![]() ![]() ![]() ![]() What a load of extra work! (And what a load.) For most programming, I strongly recommend bringing in the entire std namespace, thus eliminating the need to use the std:: prefix with cin, cout, etc. Technically, common data-stream objects cin and cout are members of the std namespace, requiring you to write code like this: std::cout << "Hello." << std::endl One of the most elegant tricks is the following, a slick way of saying “Do something N times:” while (n-) #6: Do Use using Statement, Especially with Smaller Shortcuts are dangerous for beginners but sometimes nice for programmers who know what they’re doing. The following looks innocent and would compile and run just fine if C++ were more like BASIC: if (a = b)Ĭout (10)) #5: Don’t Use Non-Boolean Conditions (Except with Care)ĭesigned originally to help write operating systems, the C language was meant to give programmers freedomnot only to manipulate data at a machine-code level (through the use of pointers) but also to write shortcuts. This one is elementary, although it might have baffled Sherlock Holmes. #1: Don’t Confuse Assign (=) with Test-for-Equality These guidelines are in no particular order (sorry David Letterman), except that the earlier items are addressed more to mistakes that beginners have trouble with. What follows are 10 of the more important things to keep in mind if you want to write polished, professional C++ code that is easy to maintain and less likely to need debuggingso I am actually more exacting here in this article than I sometimes am in my book, C++ Without Fear, Second Edition. But let’s face itwith C++, there’s always something to learn. This isn’t a tutorial on C++ but a guide for those in the middle of learning it. I can give you at least a few of those much-needed (excuse the term) pointers. I wish someone back then had steered me around the most obvious potholes it might have saved me hundreds of frustrating hours. My first introduction to the C family of languages was decades ago (yes, I know this dates me horribly). C++ Without Fear: A Beginner's Guide That Makes You Feel Smart, 2nd Edition ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |