introduction to programming
Learn about introduction to programming in COS 102. Comprehensive study materials and practice questions.
Study Notes
COS 102COS 102/CSC 120: Computer as a Problem-Solving Tool
Topic 2: Introduction to Programming
Lecture 2 Week 3
Lecturer: Dr. Ufuoma C. Ogude
Department of Computer Sciences, University of Lagos
Outlines of the Course Wk2-7
- Concept of Problem solving
- Introduction to programming
- Concept & properties of Algorithm
- Fundamentals of programming (1): variable/variable naming convention/data types in Python
- Fundamentals of programming (2): operators and expressions
- Fundamentals of programming (3): control structures
Introduction to Programming
Design of Algorithms
A person must translate an algorithm into a computer program. An Algorithm is a sequence of instructions describing how to do a task (or process), which is then translated into Python Programming.
Overview of Programming Language
- A language is a system of communication. Humans communicate in languages like English, German, etc.
- To make computers work, instructions must be stored in a specific language called a Programming Language.
Definition of Programming
- Programming is writing computer code to create a program to solve a problem.
- Programs consist of a series of instructions that tell a computer exactly what to do and how to do it.
- Programs are created to implement algorithms, which can be represented as pseudocode or a flowchart. Programming is the translation of these into a computer program.
- Just as words form a sentence, statements form an instruction in a program.
Generations of Programming Languages
Programming Languages are used to develop new systems and are classified into multiple generations based on increasing power and abstraction.
1st Generation Language (1GL): Machine Languages (ML)
- Use binary coded instructions (zeros and ones).
- Machine dependent.
- Drawbacks: Code cannot be easily exported, difficult to edit and update.
2nd Generation Language (2GL): Assembly Languages (AL)
- Use symbolic coded instructions (some English-like phrases).
- Machine dependent.
- Problem: Requires extensive programming knowledge and is time-consuming for large programs. Not machine independent.
3rd Generation Language (3GL): Higher Level Languages (HLL)
- Similar to spoken languages, use statements close to English with arithmetic notations.
- Machine independent (platform independent).
- Brought programmer-friendly features like loops, conditionals, classes.
- One line of 3GL code can produce many lines of object (machine) code, saving time.
- Requires a Compiler or an Interpreter to convert to machine language.
- Example: JAVA
4th Generation Language (4GL)
- Also known as very high-level languages.
- Designed to be closer to natural human language than other HLLs.
- Accessible to people without formal programming training.
- Allows multiple common operations with a single programmer-entered command.
- Aims to reduce programming effort, software development time, and cost.
- Use developer environments that help generate the code.
- Machine independent.
- Uses a Compiler or an Interpreter.
- Examples: SQL, SPSS, FoxPro, LINC, FOCUS.
5th Generation Language (5GL): Natural Languages
- Represent the next step in programming language development.
- Statements closely resemble human speech.
- Focus on expert systems, computerized knowledge collection, and artificial intelligence (independently smart computer systems).
- Applications: Expert Systems, Vision Systems, Speech/Voice recognition, Handwriting recognition, Robotics (Intelligent robots), Machine Learning & sub-fields (Neural networks, deep-learning).
Summary of Generations
| Generation | Characteristics | Features/Examples | Execution |
|---|---|---|---|
| 1st | Machine Code, Zeros and Ones, Machine dependent | ||
| 2nd | Assembly Language, Used some English-like phrases, Machine dependent | ||
| 3rd | Similar to spoken languages, Machine independent | E.g., JAVA | |
| 4th | Fast development, Use developer environments that help generate code, Machine independent, High Level Language, User friendly, Similar to natural languages, Platform independent, Easy to write/remember/learn/work | Ex: C, C++, Python, Java etc. | Translated into assembly language then machine language. Slow execution, but efficient for developing programs. |
Programming Language (Detailed)
Definition
- A programming language is a set of written symbols that instructs computer hardware to perform specific tasks.
- It consists of a vocabulary and a set of rules (syntax) that a programmer must learn.
- It allows programmers to express data processing symbolically, without machine-specific details.
- Used to create programs that control machine behavior and express algorithms precisely.
- Made up of a series of statements that form instructions for the computer.
Popular Languages
Many programming languages exist, with varying complexity. Some of the most popular include:
- Python
- Java
- C++
- BASIC
- Scratch
How Languages Work / Translation
- Different languages have different conventions (e.g., Python uses lowercase, BASIC often uses uppercase).
- Programming languages are designed for human readability but cannot be run directly by a computer.
- Most programming languages must be translated into machine code before execution.
Fundamentals of Programming
Activities Involved in Programming
- Analysis
- Developing
- Understanding
- Generating algorithms
- Verification of requirements of algorithms (correctness, resource consumption)
- Implementation (coding) of algorithms in a target programming language
Basic Elements of Programming
There are five basic programming elements:
- Input-Output Instruction
- Arithmetic Instruction
- Conditional Instruction
- Looping Instruction
Program & Software Development
Definition of Program
- A Program is a sequence of instructions that a computer follows to solve a problem, written in a computer language.
- Languages are often created to fit particular classes of problems.
- Programs are made up of statements that the programming language understands, each telling the computer to perform a specific task.
Software Development Overview
The process of collecting requirements, analyzing a problem, designing its solution, writing, and maintaining a computer program is called software development.
- Programming is needed to turn ideas or business solutions into reality.
- Small changes can be implemented quickly with a streamlined process.
- Larger changes require a Software Development Life Cycle (SDLC) methodology to guide and manage the process.
Software Development Life Cycle (SDLC)
Definition & Aims
- SDLC is a conceptual model that includes policies and procedures for developing or altering systems throughout their life cycles.
- It applies standard business practices to building software applications.
- The SDLC aims to produce high-quality software that meets or exceeds customer expectations, completes within time and cost estimates, and works effectively in the current and planned IT infrastructure.
Phases of SDLC
SDLC is a systematic approach used by analysts to develop a system.
- Preliminary Analysis (requests reviewed, feasibility analysis document)
- Systems Analysis (understand business/processing needs, system requirements document)
- Systems Design (define solution, convert analysis requirements into design document)
- Programming (coding commences using design documents)
- Testing (ensures code functions according to requirements)
- Implementation (construct, test, train users, install new system, convert from old system)
- Maintenance (keep system healthy and improve, support for reporting, prioritizing, fixing bugs)
The phases are core components recommended for all software development projects.
SDLC Models Overview
- A framework describing activities performed at each stage of a software development project.
- Specify and design steps for software development.
- Also called "Software Development Process Models."
- Each model has a unique series of phases to ensure success.
- Important SDLC life cycle models include: Waterfall Model, RAD Model, Spiral Model, V-Model, Incremental Model, Agile Model, Iterative Model, Big bang Model, Prototype Model.
Waterfall Model
A sequential design process often used in software development processes. Each stage must be completed before the next can begin.
- Requirements: Defines needed information, function, behavior, performance, and interfaces.
- Design: Defines data structures, software architecture, interface representations, and algorithmic details.
- Implementation: Source code, database, user documentation, testing.
Waterfall Strengths
- Easy to understand and use.
- Provides structure for inexperienced staff.
- Milestones are well understood.
- Sets requirements stability.
- Good for management control (plan, staff, track).
- Works well when quality is more important than cost or schedule.
Waterfall Deficiencies
- All requirements must be known upfront.
- Deliverables for each phase are considered frozen, inhibiting flexibility.
- Can give a false impression of progress.
- Does not reflect the problem-solving nature of software development (lack of iterations).
- Integration is a "one big bang" at the end.
- Little opportunity for customer to preview the system until it may be too late.
When to use the Waterfall Model
- Requirements are very well known.
- Product definition is stable.
- Technology is understood.
- New version of an existing product.
- Porting an existing product to a new platform.
V-Shaped SDLC Model
A variant of the Waterfall model that emphasizes the verification and validation of the product, planning testing in parallel with development phases.
V-Shaped Steps
- Project and Requirements Planning: Allocate resources.
- Product Requirements and Specification Analysis: Complete specification of the software system.
- Architecture or High-Level Design: Defines how software functions fulfill the design.
- Detailed Design: Develop algorithms for each architectural component.
- Coding: Transform algorithms into software.
- Unit Testing: Check that each module acts as expected.
- Integration and Testing: Check that modules interconnect correctly.
- System and Acceptance Testing: Check the entire software system in its environment.
- Production, Operation and Maintenance: Provide for enhancement and corrections.
V-Shaped Strengths
- Emphasizes planning for verification and validation early in product development.
- Each deliverable must be testable.
- Project management can track progress by milestones.
- Easy to use.
V-Shaped Weaknesses
- Does not easily handle concurrent events.
- Does not handle iterations or phases.
- Does not easily handle dynamic changes in requirements.
- Does not contain risk analysis activities.
When to use the V-Shaped Model
- Excellent choice for systems requiring high reliability (e.g., hospital patient control applications).
- All requirements are known upfront.
- When it can be modified to handle changing requirements beyond the analysis phase.
- Solution and technology are known.
Structured Evolutionary Prototyping Model
Developers build a prototype during the requirements phase, which is evaluated and refined based on end-user feedback until satisfaction is met, then brought to final product standards.
Structured Evolutionary Prototyping Steps
- A preliminary project plan is developed.
- A partial high-level paper model is created (source for partial requirements).
- A prototype is built with basic and critical attributes (designer builds database, user interface, algorithmic functions).
- The designer demonstrates the prototype, and the user evaluates it for problems and suggests improvements.
- This loop continues until the user is satisfied.
Structured Evolutionary Prototyping Strengths
- Customers can "see" system requirements as they are gathered.
- Developers learn from customers.
- Results in a more accurate end product.
- Unexpected requirements are accommodated.
- Allows for flexible design and development.
- Produces steady, visible signs of progress.
- Interaction with the prototype stimulates awareness of additional needed functionality.
Structured Evolutionary Prototyping Weaknesses
- Tendency to abandon structured program development for "code-and-fix".
- Bad reputation for "quick-and-dirty" methods.
- Overall maintainability may be overlooked.
- The customer may want the prototype delivered as the final product.
- Process may continue forever (scope creep).
When to use Structured Evolutionary Prototyping
- Requirements are unstable or need clarification.
- As the requirements clarification stage of a waterfall model.
- To develop user interfaces.
- For short-lived demonstrations.
- For new, original development.
- With analysis and design portions of object-oriented development.
Rapid Application Model (RAD)
An agile software development methodology that uses minimal planning in favor of rapid prototyping.
- Requirements planning phase: Workshop utilizing structured discussion of business problems.
- User description phase: Automated tools capture information from users.
- Construction phase: Productivity tools (code generators, screen generators, etc.) used within a time-box ("Do until done").
- Cutover phase: Installation of the system, user acceptance testing, and user training.
RAD Strengths
- Reduced cycle time and improved productivity lead to lower costs.
- Time-box approach mitigates cost and schedule risk.
- Customer involvement throughout minimizes risk of not achieving satisfaction.
- Focus moves from documentation to code (WYSIWYG).
- Uses modeling concepts to capture information about business, data, and processes.
RAD Weaknesses
- Accelerated development process must give quick responses to the user.
- Risk of never achieving closure.
- Hard to use with legacy systems.
- Requires a system that can be modularized.
- Developers and customers must be committed to rapid-fire activities in an abbreviated timeframe.
When to use RAD
- Reasonably well-known requirements.
- User involved throughout the life cycle.
- Project can be time-boxed.
- Functionality delivered in increments.
- High performance not required.
- Low technical risks.
- System can be modularized.
Incremental SDLC Model
Constructs a partial implementation of a total system, then slowly adds increased functionality in subsequent releases.
- The incremental model prioritizes requirements and implements them in groups.
- Each subsequent release adds function to the previous one until all designed functionality is implemented.
Incremental Model Strengths
- Develop high-risk or major functions first.
- Each release delivers an operational product.
- Customer can respond to each build.
- Uses "divide and conquer" breakdown of tasks.
- Lowers initial delivery cost.
- Initial product delivery is faster.
- Customers get important functionality early.
- Risk of changing requirements is reduced.
Incremental Model Weaknesses
- Requires good planning and design.
- Requires early definition of a complete and fully functional system to define increments.
- Well-defined module interfaces are required (some developed much earlier than others).
- Total cost of the complete system is not lower.
When to use the Incremental Model
- When risk, funding, schedule, program complexity, or need for early realization of benefits are factors.
- Most requirements are known upfront but expected to evolve over time.
- A need to get basic functionality to the market early.
- On projects with lengthy development schedules.
- On a project with new technology.
Spiral SDLC Model
Adds risk analysis and 4GL RAD prototyping to the Waterfall model. Each cycle involves the same sequence of steps as the waterfall process model.
Spiral Quadrant: Determine objectives, alternatives and constraints
- Objectives: functionality, performance, hardware/software interface, critical success factors.
- Alternatives: build, reuse, buy, sub-contract.
- Constraints: cost, schedule, interface.
Spiral Quadrant: Evaluate alternatives, identify and resolve risks
- Study alternatives relative to objectives and constraints.
- Identify risks (lack of experience, new technology, tight schedules, poor process).
- Resolve risks (evaluate if money could be lost by continuing system development).
Spiral Quadrant: Develop next-level product
- Create a design.
- Review design.
- Develop code.
- Inspect code.
- Test product.
Spiral Quadrant: Plan next phase
- Develop project plan.
- Develop configuration management plan.
- Develop a test plan.
- Develop an installation plan.
Spiral Model Strengths
- Provides early indication of insurmountable risks, without much cost.
- Users see the system early due to rapid prototyping tools.
- Critical high-risk functions are developed first.
- The design does not have to be perfect initially.
- Users can be closely tied to all lifecycle steps.
- Early and frequent feedback from users.
- Cumulative costs assessed frequently.
Spiral Model Weaknesses
- Time spent evaluating risks may be too large for small or low-risk projects.
- Time spent planning, resetting objectives, doing risk analysis and prototyping may be excessive.
- The model is complex.
- Risk assessment expertise is required.
- Spiral may continue indefinitely.
- Developers must be reassigned during non-development phase activities.
- May be hard to define objective, verifiable milestones for readiness to proceed.
When to use Spiral Model
- When creation of a prototype is appropriate.
- When costs and risk evaluation are important.
- For medium to high-risk projects.
- Long-term project commitment is unwise due to potential changes to economic priorities.
- Users are unsure of their needs.
- Requirements are complex.
- New product line.
- Significant changes are expected (research and exploration).
Agile SDLC's
Agile methods speed up or bypass one or more life cycle phases. They are usually less formal, have a reduced scope, and are used for time-critical applications in organizations employing disciplined methods.
Some Agile Methods
- Adaptive Software Development (ASD)
- Feature Driven Development (FDD)
- Crystal Clear
- Dynamic Software Development Method (DSDM)
- Rapid Application Development (RAD)
- Scrum
- Extreme Programming (XP)
- Rational Unified Process (RUP)
Extreme Programming (XP)
- For small-to-medium-sized teams developing software with vague or rapidly changing requirements.
- Coding is the key activity throughout the software project.
- Communication among teammates is done with code.
- Life cycle and behavior of complex objects are defined in test cases (again, in code).
Feature Driven Design (FDD)
- Develop an overall model: Produce class and sequence diagrams from architect meetings with domain experts and developers.
- Build a features list: Identify features supporting requirements, decomposed into Business Activities steps. Features are functions developable in two weeks, expressed in client terms.
- Plan by feature: Development staff plans the development sequence of features.
- Design by feature: Team produces sequence diagrams for selected features.
- Build by feature: Team writes and tests the code.
Dynamic Systems Development Method (DSDM)
Applies a framework for RAD and short time frames, based on the 80/20 rule (majority of requirements can be delivered in a relatively short amount of time).
DSDM Principles
- Active user involvement imperative (Ambassador users).
- DSDM teams empowered to make decisions.
- Focus on frequent product delivery.
- Product acceptance is fitness for business purpose.
- Iterative and incremental development to converge on a solution.
- Requirements initially agreed at a high level.
- All changes made during development are reversible.
- Testing is integrated throughout the life cycle.
- Collaborative and co-operative approach among all stakeholders essential.
DSDM Lifecycle
- Feasibility study
- Business study – prioritized requirements
- Functional model iteration (risk analysis, time-box plan)
- Design and build iteration
- Implementation
Adaptive SDLC
Combines RAD with software engineering best practices.
Adaptive Steps
- Project initialization – determine intent of project.
- Determine the project time-box (estimate duration).
- Determine the optimal number of cycles and time-box for each.
- Write an objective statement for each cycle.
- Assign primary components to each cycle.
- Develop a project task list.
- Review the success of a cycle.
- Plan the next cycle.
Tailored SDLC Models
- No single model fits all projects. If no model fits, pick one that's close and modify it.
- Projects should consider risk; a complete spiral might be too much, so start with a spiral and pare it down.
- For projects delivered in increments with serious reliability issues, combine incremental with the V-shaped model.
- Each team must pick or customize an SDLC model to fit its project.
Quality Assurance
Definition of Quality
Quality is the degree to which the software satisfies stated and implied requirements.
- Absence of system crashes.
- Correspondence between the software and the users' expectations.
- Performance to specified requirements.
Quality must be controlled because it lowers production speed, increases maintenance costs, and can adversely affect business.
Quality Assurance Plan
- The plan for quality assurance activities should be in writing.
- Decide if a separate group should perform quality assurance activities.
- Elements to consider:
- Defect tracing: Keeps track of each defect (source, detection, resolution, how resolved).
- Unit testing: Each individual module is tested.
- Source code tracing: Step through source code line by line.
- Technical reviews: Completed work reviewed by peers.
- Integration testing: Exercise new code in combination with already integrated code.
- System testing: Execution of the software to find defects.
Python Programming Language
- Python is a Scripting programming language known for its simplicity and wide breadth of applications, making it one of the best languages for beginners.
- It is powerful and flexible, using concise and easy-to-learn syntax, enabling programmers to write more complex programs in shorter time.
- Used for everything from Web Development to Scientific Computing.
- Referred to as a "general purpose" language.
- An object-oriented programming language created by Guido Rossum in 1989.
- Ideally designed for rapid prototyping of complex applications.
- Has interfaces to many OS system calls and libraries, extensible to C or C++.
- Many large companies use Python, including NASA, Google, YouTube, BitTorrent.
Further Study
Study the following:
- SDLC Phases
- SDLC Models: Advantages and Disadvantages, and Applications
Next Lecture: Week 4
- Concept & properties of Algorithm
- Role of Algorithm in problem solving process
- Design of Algorithms
- Pseudocode
- Flowcharting