Software Engineering

# Software Engineering

Télécharger la présentation

## Software Engineering

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
##### Presentation Transcript

1. Variables Software Engineering

2. The data literacy test Count 1.0 if you know what the concept means. Count 0.5 if you believe you know what the concept means, but you are not sure. Add the points and check your score.

3. The data literacy test abstract data type heap retroactive synapse array index referential integrity bitmap integer stack boolean variable linked list string B-tree named constant structured variable character variable literal tree container class local variable typedef double precision lookup table union elongated stream member data value chain enumerated type pointer variant floating point private

4. The data literacy test 0-14: beginner. You should not be attending this course. 15-19: intermediate. How would you consider attending more basic courses? 20-24: expert. Welcome to this course. 25-29: genius. You should be teaching this course. 30-32: fraud. You could not even identify some meaningless names that were included in the list...

5. Variable initialisation Initialise each variable as it is declared (re)Initialise each variable close to where it is first used Ideally, declare and initialise each variable close to where it is first used Use final (Java), const (C++), etc. whenever possible, so that programming variables behave similar to mathematical variables

6. Variable initialisation Pay special attention to counters and accumulators Initialise a class's member data in its constructor Check the need for reinitialisation Check input parameters for validity

7. Scoping Localise (i.e. put as close as possible) references to variables Minimise average variable span (span: distance between consecutive references of a variable, in lines): a = 0; span(a) = 2 b = 0; span(b) = 1 c = 0; span(c) = 0 a = b + c;

8. Scoping Minimise “life span” of each variable (life span: total number of lines between first and last reference to a variable) Initialise variables in a loop immediately before the loop Do not assign a value to a variable until just before the value is used

9. Scoping Group related statements with respect to variable referencing Break groups of related statements into separate routines Larger scopes make program easier to write; smaller scopes make program easier to read

10. Using variables Use each variable for one purpose only Avoid hidden meanings (e.g. “Age means age of a person, except when it values -1, in which case it denotes that the person's age is unknown”) Make sure that all declared variables are used

11. Naming variables Names should be expressive and self-contained Names should refer to the problem rather than the solution (e.g. EmployeeData is better than InputRec) Names should not be too long nor too short (between 8 and 20 characters is fine)

12. Naming variables Use conventions for variable names related to specific data types: Loop indices: recordCount, teamIndex Status variables: characterType, recalcNeed Temporary variables: avoid them; if you need them, avoid names like temp or x Boolean variables: done, error, found, success, ok; avoid negative names like notFound

13. Naming variables USE CONVENTIONS

14. Naming variables Abbreviations: Do not abbreviate by removing one character from a word Abbreviate consistently Create names that you can pronounce Avoid combinations that result in misreading or mispronunciation Document short names with translation tables in the code

15. Naming variables Names to avoid: Avoid misleading names or abbreviations Avoid names with similar meanings Avoid variables with different meanings and similar names Avoid names that sound similar Avoid numerals in names, as in file1 and file2 Avoid misspelled words in names Do not differentiate variables solely by capitalisation

16. Naming variables Names to avoid: Avoid multiple natural languages Avoid the names of standard types, variables and routines Avoid names containing hard-to-read characters, e.g. Hard2Read and HardZRead Do not use names that are totally unrelated to what the variables represent