This presentation is a part of the COP2271C college level course taught at the Florida Polytechnic University located in Lakeland Florida. The purpose of this course is to introduce Freshmen students to both the process of software development and to the Python language.
The course is one semester in length and meets for 2 hours twice a week. The Instructor is Dr. Jim Anderson.
A video of Dr. Anderson using these slides is available on YouTube at:
https://youtu.be/KcFCcCsn6mM
Practical Research 1 Lesson 9 Scope and delimitation.pptx
An Introduction To Software Development - Implementation
1. An Introduction To Software
Development Using Python
Spring Semester, 2015
Class #23:
Implementation
2. So What’s The Goal?
• The goal of any software development effort is to deliver
working software.
• “Implementation” happens when we transform a detailed
design into a valid program.
• This has to do with more than just writing code:
– Tested
– Debugged
– Compiled
– Built into a complete executable product
Image Credit: www.fotosearch.com
3. What Makes A Good
Implementation?
• Readability – can be easily read an understood by other programmers
• Maintainability – code can be easily modified and maintained
• Performance – the code should run as fast as possible
• Traceability – all code needs to be able to be traced back to a user story
• Correctness – the code needs to do what it is supposed to do
• Completeness – all system requirements must be met
Note that each of these requires a trade off. Performance optimization may
decrease the code’s readability and maintainability…
Image Credit: www.dreamstime.com
4. Programming Style &
Coding Guidelines
• Pretty much every software organization will have its own
coding guidelines.
• Guidelines cover such topics as naming, indentation, and
commenting styles. Many development tools can be
programmed to implement these styles.
• Most of these are not very important – it’s just a matter of
getting used to a given style. The goal is to be consistent in
order to help others later on avoid confusion when debugging
or maintaining the code.
Image Credit: www.dreamstime.com
5. Programming Style &
Coding Guidelines
• Guidelines should cover error messages. You want your error
messages to be clear to users but to also contain information
that programmers can use while debugging to find out where
the error message came from.
• Banning parts of a language that have been found to cause
lots of problems is also common (e.g. multiple inheritance).
Depreciated language features are also banned. Code must
compile with no warnings.
• Your goals for maintaining a good coding style are to be
consistent and to try to highlight the meaning of your code.
Image Credit: www.clipartpanda.com
6. Coding Style Recommendations
• Naming: one of the most important issues in
improving readability and maintainability.
– Bad names will require additional comments and may
mislead the reader
– Good names == good understanding
– Use long names for global variables and short names for
local variables
– Consistency is king: use the same word for a given concept
(“patient” not “customer”)
– Multicultural / multi-language teams may have special
challenges
Image Credit: www.clipartpanda.com
7. Coding Style Recommendations
• Separating Words & Capitalization: since
spaces can’t be used to separate words that
make up a variable name, different
programming languages have different
conventions
– C: lowercase with underscores: patient_name
– Java: no separation with capitalization:
patientName
Image Credit: www.clipartpanda.com
8. Coding Style Recommendations
• Indentation & Spacing: adding horizontal space
before a line in order to better reflect the structure
of the code
– Indentation affects both readability and maintainability
– A common style should be defined and all programmers
should follow it.
– The most important issue is consistency
– Most languages have a defacto indentation style that is
defined in the primary language reference
Image Credit: www.clipartpanda.com
9. Coding Style Recommendations
• Function Size: studies have shown that larger
functions are more error prone than smaller
functions
– Being able to look at an entire function at one
time helps with readability and maintainability
– Limit the size of a function to around 50 lines of
code
– This helps a function fit onto a single page
Image Credit: www.clipartbest.com
10. Coding Style Recommendations
• Unique Language Features: Different
languages support different features which
can be misused and need special precautions.
– Example: GOTO and multiple inheritance
– In Python, exceptions handling using TRY
EXCEPTION and FINALLY might be one such
situation.
Image Credit: www.clipartbest.com
11. Comments
• Comments are important
• Comments can help or hurt program readability and
maintainability.
• Two main problem with comments:
– They may distract from the code and make a section more difficult to
read
– They may be wrong
• Comments may become outdated as the code changes.
• Comments may be wrong from the start because they are
never executed/tested.
Image Credit: www.clipartpanda.com
12. 6 Different Types Of Comments
• Repeat of the code – done by new programmers and should be avoided.
These comments waste effort and distract the user
(e.g. “increment index by 1”)
• Explanation of the code – explain what complex code does in human
language. Code that is this complex should probably be rewritten.
• Marker in the code – markers in the code indicate incomplete items,
opportunities for improvement, etc. Must be removed before production.
• Summary of the code – Comments that summarize what the code does
are helpful, but they need to be kept up-to-date
• Description of the code intent – most valuable. They describe what the
code should do, not what it does.
• External references – link code to external entities Image Credit: www.liveattherock.com
13. Comments Are A Trade-Off
• We need to recognize the trade-off that comments represent.
• Comments can help to clarify code and relate it to other
sources.
• They also represent some level of duplication of the code.
• It takes time to both create them and then to maintain them.
• Comment errors can be very hard to both find and correct.
Image Credit: www.fotosearch.com
14. Comment Dangers!
• Comments can be used to justify bad coding practices
• Programmers may be tempted to create code that is too
complicated or too hard to maintain and then add comments
to it instead of rewriting it to better coding standards.
• An alternative: code that is so well written that it documents
itself (“self documenting code”).
• Good goal, but comments still have a place in capturing the
programmer’s intent.
Image Credit: www.clipartof.com
15. Debugging
• Debugging is all about locating and fixing
errors in the code.
• Generally errors are found by testing, but they
can also be reported by users or code
inspections.
• Debugging is a highly iterative process.
Image Credit: www.clker.com
16. 4 Phases In The Debugging Process
• Reproduction: Be able to reproduce the error
in a given configuration. Find out the
conditions that lead to the error by
constructing a minimal test case. Don’t care
about the code.
• May find some cases where code works
correctly.
• Always try to write simpler tests that still fail.
Image Credit: www.clker.com
17. 4 Phases In The Debugging Process
• Localization: Finding the sections of the code
that lead to the error.
• Generally, this is the hardest part to do.
• If the reproduction phase shows a very simple
test case, then this may easier to do.
Image Credit: driverlayer.com
18. 4 Phases In The Debugging Process
• Correction: Changing the code to fix the error.
• If you truly understand what is causing the
error, you have a good chance of being able to
fix it.
• Common mistake – trying to fix the problem
when you don’t know what it is or where it is.
– Leads to random changes
– Results in more errors
Image Credit: www.iconseeker.com
19. 4 Phases In The Debugging Process
• Verification: Making sure that the error is
fixed.
• Make sure that no new errors were introduced
into the code.
• All too often the fix does not fix the problem,
but does cause other problems.
Image Credit: tech-kid.com
20. Two Types Of Errors In Programs
• Syntax Errors
– Found by the complier
– Compiler tells you what their source is
• Logic Errors
– Harder to find
– Need to understand what the code is both trying
to do and is actually doing
Image Credit: www.clker.com
21. Debugging Tools
• Source code comparators – show you what changed
• Extended checkers – find errors with syntax, logic, or
style
• Interactive debuggers – let you step through code
and inspect variables
• Specialty Libraries – provide extra safeguards to
detect and prevent errors
• Profiler Tools - describe pre and post conditions
Image Credit: www.clipartsfree.net
22. Assertions &
Defensive Programming
• Precondition – something that your code
needs in order to create correct results
• Postcondition – a condition that should hold
true after executing your code
• Assertions - statements that check a condition
and product an error if the condition is not
met (e.g. a checking account balance)
Image Credit: www.easyvectors.com
23. Performance Optimization
• Performance for any program is important, but…
• Optimizing for performance almost always affects code maintainability
and readability for the worse.
• Real-time systems are the exception – they are all about performance.
• Programmers often make the mistake of worrying about performance too
early in the development cycle.
– Get the code to work first and make it easy to maintain
– If the performance is unsatisfactory, then you can optimize performance – most times
this won’t be an issue.
– Most code is only executed a few times and does not impact performance
– Only a few pieces of code will have to be optimized for performance
Image Credit: www.istockphoto.com
24. How To Optimize Performance
• Start with a profiler tool
– Runs the program and calculates how much time is spent in each part.
– Helps you to find bottlenecks and to determine what code needs to be
optimized
• Now review and optimize only those modules that will have
an impact on performance
• After making changes, run the profiler again to determine
impact and to ensure changes actually boosted performance.
Image Credit: www.dreamstime.com
25. The Cost Of Optimization
• A cost / benefit analysis should be done before
performing any performance optimization.
• A programmer’s time is more expensive than
computer time – it may be cheaper to just buy faster
hardware.
• You need to weigh the increase in performance
against the decrease in maintainability and the
possibility of introducing errors.
Image Credit: www.clipartpanda.com
26. Refactoring
• Just like a novel can be made better by rewriting parts, so to
can your code be made better by refactoring parts of it.
• Refactoring refers to improving your code style without
altering its behavior.
• Refactoring is one of the most powerful techniques for
producing good code.
• Reasons to refactor:
– Duplicated code
– Excessively large or long functions
– Etc.
Image Credit: publicdomainvectors.org
27. What Do You Do When You
Refactor?
• Turn a code fragment in to a standalone function
with its own name and calls to it.
• Replace the body of a function with a new algorithm
that is clearer and which returns the same results.
• Move an algorithm from one function to another
where it makes more sense
• Divide a function into two functions.
Image Credit: publicdomainvectors.org
29. What We’ll Be Covering Next Time
1. Software Support and
Maintenance
Image Credit: http://merchantblog.thefind.com/2011/01/merchant-newsletter/resolve-to-take-advantage-of-these-5-e-commerce-trends/attachment/crystal-ball-fullsize/
Hinweis der Redaktion
New name for the class
I know what this means
Technical professionals are who get hired
This means much more than just having a narrow vertical knowledge of some subject area.
It means that you know how to produce an outcome that I value.
I’m willing to pay you to do that.