Intro to programming

Software systems

The world today is filled with devices whose behaviour is controlled by sequences of preprogrammed electronic instructions, or programs.

In many cases the user or administrator of the device can pick and choose which specific programs are installed on the device and when those programs are used:

In other cases most of the key programs come with the device, and the user just makes some minor customization choices or very specific additions:

In many cases the programs are highly specialized to control a specific device, and might never be altered during the life of the device. There are millions of different types of controller surrounding us, most of which we never notice until they break down:

On top of that, there are a great many widespread and interlocking network systems that we rely on daily - all controlled by collections of programs:

For the most part, we lump all these different controlling programs together under a broad category called software.

Software development

As mentioned above, each of these controlling programs consists of a set of electronic instructions whose goal is to make a physical device behave the way the user wants/requires/expects.

Note the emphasis there - before we can create an appropriate piece of software we must clearly understand exactly what the user wants/requires/expects from that software.

Often the task of creating the software and ensuring it works correctly is a slow and expensive process (anything from one person working for a few hours to thousands of people working for several years). If we don't understand what the user wants, we won't create appropriate software, and huge amounts of time (and money) will have been wasted.

As a result, the software development process usually looks something like this:

  1. Identify the user requirements for the system: this often involves a series of client interviews, system proposals, and revisions until the designer is certain they understand exactly what the client wants (and is prepared to pay for!)
  2. Design a solution: here the designer determines how to best meet the client requirements using a mix of hardware and software, purchased (off-the-shelf) software and custom-designed components, and outlines the actions the software will need to perform
  3. Implement the solution: here the programmer takes the design and uses it to creates, tests, and debugs the final product and ensure it meets the requirements specified in step 1.

At this point the software is ready for installation on the device and for use by the customer.

For complex software systems that will be in use for many years there is a final, much longer, phase: maintenance. This involves making any changes required to the system over the years:

In fact, of all the time and money spent developing software worldwide, more than half is spent on maintaining old software.

Consider the following analogy, comparing software development and house construction:

Phase House Construction Software Development
Analysis and modeling The client gets the idea that they'd like to build a new house, and probably has some initial thoughts on what they'd like. They hire an architect to carry out the formal design process.

The architect guides the client through the process, asking them questions to determine exactly what they would like, showing them sketches and discussing options (where on the property should the house go, how large should it be, what direction should it face, where should rooms, windows, and doors go and how large should they be, what will be the size and shape of each room, etc).

A major part of the architect's role is to ensure the clients are aware of the options and implications of each choice, while still ensuring the legality and safety of the final result.

By the end of this phase the architect has likely developed a set of formal floorplans, sketches, and descriptions of each aspect of the house.

The client gets the idea that they need new software to carry out some task, and probably has some initial thoughts on what they'd like. They hire a systems analyst to carry out the formal design process.

The analyst guides the client through the process, asking them questions to determine exactly what they would like, showing them sketches and discussing options (what features and functionality is needed, what information needs to be stored, where does it come from and how is it used, what tasks does the software need to perform in order to help the user achieve their goals, what should the screens look like, etc).

A major part of the analyst's role is to ensure the clients are aware of the options and implications of each choice, while still ensuring the legality and safety of the final result.

By the end of this phase the architect has likely developed a set of formal requirements, sketches, and descriptions of each aspect of the product.

Design The architect develops a set of blueprints for the house, using the floorplans, sketches, and descriptions as a guideline.

The design must go far deeper than in the analysis phase, because it must also provide all the information necessary for the contractor to actually build the house. The designer will obtain advice from specialists as needed to ensure the design is in fact practical and legal.

During this phase, the architect is likely to run across some issues or questions that require the clients to make additional choices, and the clients may also make some last minute changes or requests.

At the end of this phase, a complete set of blueprints are finalized to precisely define the house that must be built. These are typically inspected carefully to ensure correctness. The contractor will then be able to work from these blueprints while needing minimal interaction with the architect.

The software designers develop a formal solution for the product, using the requirements, sketches, and descriptions as a guideline.

The design must go far deeper than in the analysis phase, because it must also provide all the information necessary for the software developers to actually build the product. The designer will obtain advice from specialists as needed to ensure the design is in fact practical and legal.

During this phase, the designers are likely to run across some issues or questions that require the clients to make additional choices, and the clients may also make some last minute changes or requests.

At the end of the phase, a complete set of design documents are finalized to precisely describe how the product will be built. These are typically inspected carefully to ensure correctness. The software design team will then be able to work from the design documents while needing minimal interaction with the designers or analysts.

Implementation (Construction) The contractor plans and oversees the construction of the house, hiring various experts (framers, roofers, plumbers, electricians, painters, etc) at appropriate times to build each component and to ensure that they conform to the design provided.

Again there may be issues that arise during construction that require further choices by the clients, and the clients may request additional changes as they see the product taking shape. Once construction has begun, however, it is difficult to make major changes without essentially starting the design all over again.

Most aspects of construction will need to be formally inspected and approved before the house can legally be occupied, and the clients/architects will also do their own inspections before taking possession. There are often many tiny defects and corrections that need to be made at this stage.

Even after taking possession, there is often a short interval (weeks or months) during which the client may discover other blemishes or errors left over from the construction process, and most contractors will take steps to correct these.

The project manager plans and oversees the implementation of the product, hiring various programming experts (database programmers, network programmers, interface experts, etc.) at appropriate times to implement each component of the product and to ensure that they conform to the design provided.

Again there may be issues that arise during construction that require further choices by the clients, and the clients may request additional changes as they see the product taking shape. Once coding has begun, however, it is difficult to make major changes without essentially starting the design all over again.

Most aspects of coding will need to be formally inspected and approved before the product is installed for use, and the clients and their representatives will also do their own inspections before accepting the product as completed. There are often many tiny defects and corrections that need to be made at this stage.

Even after the product is accepted and installed, there is often a short interval (possibly up to a year) during which the client may discover other defects or errors from the implementation process, and most software developers will take steps to correct these.

Maintenance Over the years, the owners may sell the house to others who wish to make some changes, or they may need to fix or change different parts of the house for a variety of reasons:
  • changing regulations/laws may force the client to make changes (e.g. it may become more costly to get insurance unless they certain safeguards that weren't a requirement back when they built the house)
  • the client may need to change aspects of the house to accomodate other new product they want to incorporate (e.g. they may decide to install a hot tub, which in turn requires them to upgrade part of the electrical system and plumbing system)
  • the client may find some aspects of the layout are actually inconvenient or impractical, and decide to change them (e.g. they may not like the way the kitchen is laid out)
  • after a time the client may simply want to change things for the sake of a change

For the most part, these changes will require the owners to hire professionals to carry out the changes, as they are rarely regarded as the responsibility of the original contractor.

Over the years, the clients may want or need to make alterations to the product for a variety of reasons:
  • changing regulations/laws may force the client to make changes (e.g. changing tax laws require changes to tax software)
  • the client may need to change aspects of the product to accomodate other new product they want to incorporate (e.g. they may decide change operating systems or platforms, and the original product may not have been designed with the new system in mind)
  • the client may find some aspects of the product are actually inconvenient or impractical, and decide to change them (e.g. they may not like the way certain screens or menus are organized)
  • after a time the client may think of new features they would like added to improve their experience

For the most part, these changes will require the owners to hire professionals to carry out the changes, as they are rarely regarded as the responsibility of the original developers.

Software development teams and environments

As mentioned earlier, there is a huge range in the type and size of software systems.

Some software can be developed from start to finish by one person in a few hours, other software systems may require thousands of people working for several years before completion.

A software developer may find themselves working alone on a project, or as part of a team of developers (anywhere from 3-20 people), or as part of one team out of many working on a project. (Teams of 4-8 are the current industry norm.)

A developer (or team) might be working independently to create a product they then plan to sell to as many people as possible, or they might be hired by a company to produce such a product (which that company would then sell), or they might be hired by a company to design or modify software specifically for use by that company (e.g. designing and developing a payroll system for a municipality).

In each different type and size of project the developers will face different problems in terms of organization and communication in addition to the core problem of actual developing the desired system - each different team composition has its own strengths and weaknesses, and each different type of relationship between the client and developer raises different difficulties in identifying and meeting system requirements.

Large projects

Complex projects (such as high end computer games) can run for several years and cost tens of millions of dollars to develop.

Computer science in general

The field of computer science has to address all the different problems associated with such a diverse collection of elements. A few of the broad areas of computer science are listed below, there are many, many others.

This course in particular

In this course we will cover the basics of software development, using one operating system (Unix) and one programming language (C++).

We will focus on small scale projects, appropriate for a single individual to complete in a short time period (weeks or a few months).

This course should provide you with the knowledge necessary to write or modify small programs, but more importantly it should provide you with an understanding of the issues surrounding the development and use of computer software. This knowledge can be invaluable any time you become associated with a software development project - as a client, manager, user, or developer.


Small scale programming management

By programming in the small we mean programs written quickly, usually by a single individual, and for which low design and documentation standards are acceptable.

By design or circumstance, many projects during a student's academic years seem to fall into this category.

This is usually only the case if the software has a short expected life span (several months or less), does not perform any critical functions, and is only going to be used by the developer or by a tolerant experienced user.

For programming in the small, many developers traditionally produce little (if any) documentation beyond the commenting in the code and (perhaps) a short user manual or help facility.

There are still a number of methods we may use to produce quality code (these will become even more important in later semesters when you start working on team projects).

Small project planning and organization

There are two common approaches to small, informal projects:

In the first case, there is an exact goal for the software capabilities, and we work on the software until that target is met.

In the second case, we have a set of goals and qualities, but a fixed time frame, so we attain as many of the goals and as high quality as possible in the allotted time.

A rough breakdown of the time spent on small projects is likely to look something like this:

Throughout your computing coursework you encounter ways to effectively identify and record product requirements, carry out design and implementation, conduct appropriate verification and validation, and adequately plan and document software.

Many of the techniques discussed will be "overkill" for small projects. In this opening section, we will discuss some of the common design ideas that should be followed even on the smallest of programs.

Perhaps the most important rule of thumb is to write down everything. Keep a written record of

It is probably also worth keeping multiple versions of the source code: often you will introduce bugs or other problems into the code, and having a copy of a previous version to back up to can save a great deal of time and effort "rediscovering" the right way to do things.

Problem solving and software development


Software Engineering

Software life cycle

- the stages a typical piece of software goes through, from initial conception to obsolescence
  1. Analysis - specifying exactly what the problem is and what are the requirements for an acceptable solution
  2. Design - developing a detailed solution to the problem
  3. Coding - turning the design into a working program
  4. Testing/verification - ensuring the software is correct
  5. Maintenance - fixing, enhancing, adapting the software
  6. Obsolescence - abandoning a program which is no longer effectively maintainable

Problem solving process

Program development

Maintenance of programs will not be heavily emphasized in this course (though it will be very important in later courses) so our main development concerns will be
  1. Analysing the problem we're given
  2. Developing a solution technique (algorithm)
  3. Documenting the program/technique
  4. Translating (implementing) the technique into code
  5. Compiling and running the program
  6. Testing the results with appropriate data
Steps 3 through 6 will be repeated until the program handles all the test cases correctly

Incremental development

When implementing, compiling, and testing
DO THIS AND SAVE YOURSELF
HIDEOUS NIGHTMARES
  1. first get a skeleton (outline) solution for the problem
  2. get it implemented, running, and tested
  3. flesh out one more part of the program
  4. get it implemented, running, and tested
  5. repeat steps 3 and 4 until the whole thing is done
If you design and code the whole thing in one fell swoop then try to compile/debug it you may find the problems overwhelming

Design and analysis

Top-down design

Many problems are too large to immediately grasp and solve all the details, top-down design tries to address this issue Experience will make you more and more adept at this division process

Algorithms

Once you've divided a problem into its logical sub-problems, and thought out a solution to each, we can turn this into an algorithm

Top-down design examples

Metric conversion

Metric conversion - design
First get a high level breakdown of the problem: Then supply more detail for the steps requiring it, e.g.

Checkbook balancing

A customer wants a program to help calculate a checkbook balance after a transaction Analysis:
Checkbook balancing - Design
Design - top level Design - second level Possible third level for step 3.2: