CMSC 345 Programming 1 Topics n n n

  • Slides: 17
Download presentation
CMSC 345 Programming 1

CMSC 345 Programming 1

Topics n n n Work Breakdown Coding Standards Defensive Programming Structured Programming Documentation 2

Topics n n n Work Breakdown Coding Standards Defensive Programming Structured Programming Documentation 2

Work Breakdown n n Be positive that all component (e. g. , objects, functions)

Work Breakdown n n Be positive that all component (e. g. , objects, functions) interfaces are crystal clear to all team members Based on these interfaces, divide the work into independent, manageable pieces among team members One team member in charge of configuration management and change control wrt interfaces; no changes w/o his/her approval One team member in charge of code checkin/checkout and file directory structure One team member in charge of integration planning, keeping abreast of any changes in interfaces and/or source code files (above) 3

Work Breakdown (con’t) n n n One team member charge of tracking that everyone

Work Breakdown (con’t) n n n One team member charge of tracking that everyone is doing what they’re supposed to do and is on schedule; should be in daily contact with all team members One team member in charge of “master copy” of SRS and keeps track of changes, informing others of changes One team member in charge of “master copy” of SDD and keeps track of changes, informing others of changes 4

Coding Standards n n Everybody’s got them - a very real-world thing They help

Coding Standards n n Everybody’s got them - a very real-world thing They help you organize your thoughts and avoid mistakes They let you focus on the problem You must organize, format, and document your code to make it easy for others to understand 5

Coding Standards Problems Without Them n n Computer programs are generally more difficult to

Coding Standards Problems Without Them n n Computer programs are generally more difficult to read than to write (even one's own code is often difficult to read after it hasn't been looked at for a while). Software that is not internally or externally documented tends to be thrown-away or rewritten after the person that has written it leaves the organization (it is often thrownaway even if it is documented). 6

Coding Standards Problems w/o Them (con’t) n n It is often more difficult to

Coding Standards Problems w/o Them (con’t) n n It is often more difficult to reuse software someone else has written than to rewrite it your self because it is hard to figure out how it works. In practice, debugging often takes the place of understanding how programs work (ie. , if we all understood perfectly how our own code worked we would not need to debug it to find out why it is not doing what we think it should). 7

Your Coding Standards n Establish team coding standards immediately and document them n n

Your Coding Standards n Establish team coding standards immediately and document them n n n file header comments function and/or object commenting coding and commenting styles identifier naming conventions Later code inspections will check for this as well as correctness Makes easier to debug/maintain, particularly by others – not the original author nor even original team members 8

Defensive Programming - General n n Check validity of all input parameters (e. g.

Defensive Programming - General n n Check validity of all input parameters (e. g. , within range, non-null) Check validity of all returned values (i. e. , from called subroutines) Repeatedly check validity of all external and internal data structures or data files Segregate this code so can easily be commented out during performance tuning (if tuning is necesssary) 9

Defensive Programming Validate All User Inputs n n Expect the unexpected - and be

Defensive Programming Validate All User Inputs n n Expect the unexpected - and be able to recover! Respond to bogus inputs with useful diagnostics when possible, and explain what would be valid input in each case When there is a default value, indicate in the prompt and accept blank input to defer to the default value When there is a choice among a small number of simple values, list all of them in prompt 10

Defensive Programming User Outputs n n n Clearly explain all user output along with

Defensive Programming User Outputs n n n Clearly explain all user output along with the output value(s) Provide options for at least two levels of verbose and terse output modes (also applicable to prompts) Probably also testing/debug mode (for use by test drivers or scripts) If the user has to “wait”, give a periodic visual cue that the program is busy working (rather than hung) When possible, trap fatal errors and give diagnostics (including how to recover and who to report bug to) 11

Structured Programming n Regardless of the programming language, each program component involves at least

Structured Programming n Regardless of the programming language, each program component involves at least n n n Control Structures Algorithms Data Structures 12

Control Structures n n Keep them as top-down as possible - no “spaghetti code”

Control Structures n n Keep them as top-down as possible - no “spaghetti code” Are a good clue as to when a comment is needed 13

Algorithms n n Keep them as generic as possible (for reuse within same program

Algorithms n n Keep them as generic as possible (for reuse within same program or with later program(s)) Fast code is overrated and has cost (it’s complex!) n n n Takes more time to write to test for users to understand to modify and debug Execution time is only a small part of the cost equation. Balance execution time with design quality and customer requirements DO NOT sacrifice CLARITY and CORRECTNESS for speed 14

Documentation n Internal Documentation n External Documentation 15

Documentation n Internal Documentation n External Documentation 15

Internal Documentation n n n Intended for a programmer-type reader File header comments Component

Internal Documentation n n n Intended for a programmer-type reader File header comments Component (e. g. , objects, functions) header comments Component body comments Local data documentation Meaningful variable names Formatting 16

External Documentation n n Intended for non-programmer-types (maybe those who never read code) Describe

External Documentation n n Intended for non-programmer-types (maybe those who never read code) Describe the problem addressed by the component; when invoked; why needed Describe the algorithms – rationale, formulas, boundaries, special conditions Describe the data – component level data flow 17