Best Practices for Variable Usage: Naming, Initialization, and Use, Slides of C Sharp Programming

Best practices for using variables effectively in programming, including the importance of using clear and descriptive names, initializing variables properly, and limiting the scope and persistence of variables. It covers topics such as naming conventions, variable names, enum names, and variable initialization and use.

Typology: Slides

2012/2013

Uploaded on 09/27/2013

vikrant
vikrant 🇮🇳

4.4

(9)

119 documents

1 / 8

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Best Practices for
Variables
docsity.com
pf3
pf4
pf5
pf8

Partial preview of the text

Download Best Practices for Variable Usage: Naming, Initialization, and Use and more Slides C Sharp Programming in PDF only on Docsity!

Best Practices for

Variables

Introduction

 Don’t use implicitly declared variables (VB allows this – C# does not)  Do use naming conventions  Remove unused variables  Use all variables that you declare

Variable Names (1)

 Variables should “accurately” and “fully” describe the entity  Don’t use obscure abbreviations  1 character variable names are OK for scratch values  i,j,k are common  Put modifier at the end of names (not the beginning)  Total, Sub, Average, Max

Variable Names (2)

 Use opposites precisely  Avoid the use of the word flag  Use boolean names  done / error / found / success  The name should imply true or false

Variable Initialization

 Declare and initialize variables together  A variable’s declaration and first use should be together (or close)  Use constants where possible  Don’t use literal values

Variable Use

 Use variables for a single purpose  Don’t reuse counters and accumulators  If you do, tell the reader  Minimize scope visibility  Use local variables over global variables where possible  Minimize persistence  Avoid names with hidden meanings