Software Development / Construction: The Programmer
Software Development / Construction: The Programmer
The Programmer
Mostly, when you see programmers, they arent doing anything. One of the attractive things about programmers is that you cannot tell whether or not they are working simply by looking at them. Very often theyre sitting there seemingly drinking coffee and gossiping, or just staring into space. What the programmer is trying to do is get a handle on all the individual and unrelated ideas that are scampering around in his head. Charles M. Strauss
2/01/2013
2/01/2013
What is Construction?
2/01/2013
Coding=Construction?
Construction is also sometimes known as coding or programming. Coding isnt really the best word because it implies the mechanical translation of a preexisting design into a computer language; Construction is not at all mechanical and involves substantial creativity and judgment. It is better to use programming interchangeably with construction.
Software Engineering in Practical Approach #4 7
The Proportions
2/01/2013
Tasks of Construction
Verifying that the groundwork has been laid so that construction can proceed successfully Determining how your code will be tested Designing and writing classes and routines Creating and naming variables and named constants Selecting control structures and organizing blocks of statements Unit testing, integration testing, and debugging your own code Reviewing other team members low-level designs and code and having them review yours Polishing code by carefully formatting and commenting it Integrating software components that were created separately Tuning code to make it smaller and faster
2/01/2013
The Foundation
11
Without a good problem definition, you might put effort into solving the wrong problem. Be sure you know what youre aiming at before you shoot
Software Engineering in Practical Approach #4 12
2/01/2013
Bad Requirement
Without good requirements, you can have the right general problem but miss the mark on specific aspects of the problem
Software Engineering in Practical Approach #4 13
Bad Architecture
Without good software architecture, you may have the right problem but the wrong solution. It may be impossible to have successful construction.
Software Engineering in Practical Approach #4 14
2/01/2013
Codes Audiences
Your code has two audiences:
The machine thats the target of the compiled version of the code, what will actually get executed. The people, including yourself, who will read it in order to understand it and modify it.
Your code needs to fulfill the requirements, implement the design, and also be readable and easy to understand
Software Engineering in Practical Approach #4 15
16
2/01/2013
2/01/2013
10
2/01/2013
22
11
2/01/2013
12
2/01/2013
White Space
White space is your friend. You wouldnt write a book with no spaces between words, or line breaks between paragraphs, or no chapter divisions. Some suggestions:
Use blank lines to separate groups (just like paragraphs). Within a block align all the statements to the same tab stop (the default tab width is normally four spaces). Use indentation to show the logical structure of each control structure and block. Use spaces around operators. In fact, use spaces around array references and function / method arguments as well. Do not use double indentation with begin-end block boundaries.
Software Engineering in Practical Approach #4 25
Defensive Programming
By defensive programming we mean that your code should protect itself from bad data. The bad data can come from user input via the command line, a graphical text box or form, or a file. Bad data can also come from other routines in your program via input parameters. How do you protect your program from bad data? Validate! Validate! Validate!
Software Engineering in Practical Approach #4 26
13
2/01/2013
Defensive Programming
Check the following:
Check the number and type of command line arguments. Check file operations.
Did the file open? Did the read operation return anything? Did the write operation write anything? Did we reach EOF yet?
Check all values in function/method parameter lists. Are they all the correct type and size? You should always initialize variables and not depend on the system to do the initialization for you
Software Engineering in Practical Approach #4 27
Defensive Programming
Also check the following:
Null pointers (references in Java, C++) Zeros in denominators Wrong type Out of range values
Use assertion. Defensive programming means that using assertions is a great idea if your language supports them. It is good for testing and debugging.
Software Engineering in Practical Approach #4 28
14
2/01/2013
Defensive Programming
int total = countNumberOfUsers(); if (total % 2 == 0) { // total is even } else { // total is odd and non-negative assert(total % 2 == 1); }
Software Engineering in Practical Approach #4 29
Error Handling
The main purpose of error handling is to have your program survive and run correctly for as long as possible. When it gets to a point where your program cannot continue, it needs to report what is wrong as best as it can and then exit gracefully. Exiting is the last resort for error handling. Some programming languages have built-in error reporting systems that will tell you when an error occurs, and leave it up to you to handle it one way or another. These errors that would normally cause your program to die a horrible death are called exceptions.
Software Engineering in Practical Approach #4 30
15
2/01/2013
Programmer s Happiness
I am rarely happier than when spending an entire day programming my computer to perform automatically a task that it would otherwise take me a good ten seconds to do by hand. Douglas Adams
31
Debugging
It is a painful thing to look at your own trouble and know that you yourself and no one else has made it. Sophocles
32
16
2/01/2013
Debugging
Getting your program to work is a process with three parts:
Debugging Reviewing/inspecting Testing
33
Debugging
Debugging is the process of finding the root cause of an error and fixing it. This doesnt mean treating the symptoms of an error by coding around it to make it go away; it means to find the real reason for the error and fixing that piece of code so the error is removed. Debugging is normally done once you finish writing the code and before you do a code review or unit testing.
Software Engineering in Practical Approach #4 34
17
2/01/2013
Reviewing
Reviewing (or inspecting) is the process of reading the code as it sits on the page and looking for errors. The errors can include errors in how youve implemented the design, other kinds of logic errors wrong comments, etc. Reviewing code is an inherently static process because the program isnt running on a computer youre reading it off a screen or a piece of paper. So although reviewing is very good for finding static errors, it cant find dynamic or interaction errors in your code.
35
Testing
Testing, is the process of finding errors in the code, as opposed to fixing them, which is what debugging is all about. Testing occurs, at minimum, at the following three different levels:
Unit testing: Where you test small pieces of your code, notably at the function or method level. Integration testing: Where you put together several modules or classes that relate to each other and test them together. System testing: Where you test the entire program from the user s perspective; this is also called black-box testing, because the tester doesnt know how the code was implemented, all they know is what the requirements are and so theyre testing to see if the code as written implements all the requirements correctly.
Software Engineering in Practical Approach #4 36
18
2/01/2013
19