Cover by Steve McConnell

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

Using Each Variable for Exactly One Purpose

Using Each Variable for Exactly One Purpose

It's possible to use variables for more than one purpose in several subtle ways. You're better off without this kind of subtlety.

Use each variable for one purpose only. It's sometimes tempting to use one variable in two different places for two different activities. Usually, the variable is named inappropriately for one of its uses or a "temporary" variable is used in both cases (with the usual unhelpful name x or temp). Here's an example that shows a temporary variable that's used for two purposes:

Use each variable for one purpose only

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required