Librenix
Headlines | Linux | Apps | Coding | BSD | Admin | News
Information for Linux System Administration 

C++ style: How to write clear code

Up
vote
Down

This article is a sample chapter from the book Exceptional C++ Style: 40 New Engineering Puzzles, Programming Problems, and Solutions.
Remove gratuitous complexity. This function adores gratuitous local variables! It contains three examples. First, the variable iDst is initialized to last-first and then used only once; why not just write last-first where it's used and get rid of clutter? Second, the vector iterator vit is created where a subscript was already available and could have been used just as well, and the code would have been clearer. Third, the local variable it gets initialized to the value of a function parameter, after which the function parameter is never used; my personal preference in that case is just to use the function parameter (even if you change its value—that's okay!) instead of introducing another name.
 read more | mail this link | score:6432 | -Ray, April 18, 2005
More Programming articles...

Buy Large Wall Art Prints

coding headlines

Develop your own Raspberry Pi OS

perl1line.txt: A handy Perl script collection

Perl One-Liners Explained: Handy Regular Expressions

String matching in regular expressions

The Bash Case Statement

Build Apps with Android SDK, Eclipse, PhoneGap (Ubuntu 10.10)

 

Firefox sidebar

Site map

Site info

News feed

Features

Login
(to post)

Search

 
Articles are owned by their authors.   © 2000-2012 Ray Yeargin