You are on page 1of 38

TU156 Intro to Scientific Programming

Program Design
By TU156 Instructor Team
Department of Computer Science
Faculty of Science & Technology, Thammasat University
Last update: August 2023
Outline
● Steps in program development
● Different approaches to program design
● Thinking like a programmer
● Importance of requirement gathering
● Programming languages
● Program development tools

2
Steps in program development
1. Define the problem
○ Read and reread the problem until completely understand what is required
○ Define inputs, outputs, process (steps to produce required outputs)
2. Outline the solution
○ Break the problem down to smaller tasks or steps
○ Establish solution outline
3. Develop the outline into an algorithm
○ Expand solution outline into an algorithm
○ Describe tasks to be performed and order to perform tasks
4. Test algorithm for correctness
○ Check the instructions in the algorithm
○ Identify major logic errors

3
Steps in program development
5. Code the algorithm into a specific programming language
○ Start to code the program into chosen programming languages
6. Run the program on the computer
○ Perform testing several times until the program is running as required
7. Document and maintain the program
○ Produce program-related documents (charts, algorithms, test results, etc.)
○ Perform changes to be made to the program (maintenance)

4
Designing a program
● Programs must be designed before they are written
● Program development cycle:
○ Design the program
○ Write the code
○ Correct syntax errors
○ Test the program
○ Correct logic errors

● Program design
○ Design is the most important part of the program development cycle
○ It refers to the process of planning, organizing, and structuring a software program to achieve specific goals
efficiently.
○ It consists of the steps a programmer should do before they start coding the program in a specific language.

5
Designing a program
● Understand the task that the program is to perform
○ Work with customer to get a sense what the program is supposed to do
○ Ask questions about program details
○ Create one or more software requirements

● Determine the steps that must be taken to perform the task


○ Break down required task into a series of steps
○ Create an algorithm, listing logical steps that must be taken

6
Importance of proper program design
● Proper program design is the cornerstone of successful software
development.
● Effective program design not only leads to a smoother development process
but also results in software that is easier to understand, maintain, and extend
over time.

7
Different approaches to program design
● There are several approaches to program design, each with its strengths and
weaknesses.

● Procedural Programming:
○ Procedural programming is one of the earliest and most straightforward approaches to program design.
○ The program is divided into a sequence of functions or procedures that manipulate data.
○ Key features of procedural programming include:
■ Modularity: Breaking down the program into smaller, manageable functions makes it easier to read,
understand, and maintain.
■ Top-down design: The program is developed by starting with the main procedure and gradually breaking it
down into smaller procedures.

○ Example: Calculating the factorial of a number using procedural programming.

8
Different approaches to program design
● Event-Driven Programming:
○ Based on the idea that an event or interaction with the outside world can cause a program to change from one
known state to another
○ It is commonly used in graphical user interfaces (GUIs) and real-time applications.
○ It operates by responding to events triggered by user actions or other sources.
○ Key components of event-driven programming include:
■ Event Handlers: Functions that are executed in response to specific events.
■ Event Loop: A continuous loop that waits for events and dispatches them to their respective handlers.

○ Example: Developing a simple GUI application with event-driven programming.

9
Different approaches to program design
● Object-Oriented Programming (OOP):
○ Object-oriented programming is a powerful paradigm that focuses on creating objects that encapsulate data
and behavior.
○ OOP revolves around four main principles:
■ Encapsulation: Bundling data and methods together within a class to hide implementation details and
provide a clean interface to the outside world.
■ Inheritance: Creating new classes based on existing classes to inherit their properties and behaviors,
promoting code reuse.
■ Polymorphism: The ability of objects to be treated as instances of their parent class while still retaining
their specific behavior.
■ Abstraction: Simplifying complex systems by breaking them down into smaller, more manageable objects.

○ Example: Creating a simple banking system using object-oriented programming.

10
Different approaches to program design
● Component-Based Architecture:
○ A program is built by assembling independent and reusable components.
○ Each component focuses on a specific task and communicates with other components through well-defined
interfaces.
○ Key features of component-based architecture include:
■ Reusability: Components can be reused across different projects, saving development time and effort.
■ Maintainability: Modifying or updating specific functionalities becomes easier as components are isolated.

○ Example: Building a website with a component-based frontend framework.

11
Different approaches to program design
● Functional Programming:
○ Functional programming treats computation as the evaluation of mathematical functions and avoids changing
state and mutable data.
○ Key features of functional programming include:
■ Immutability: Data is immutable, meaning once it is created, it cannot be changed, preventing side effects.
■ First-class functions: Functions are treated as first-class citizens, allowing them to be passed as
arguments or returned from other functions.
■ Recursion: Functional programming heavily relies on recursion to solve problems.

○ Example: Implementing a factorial function using functional programming.

12
Thinking like a programmer
● Writing down instructions is the job of the person (or people) who wrote the
software, the programmer
● A program must be written in a language that the computer can follow, the
programming languages

● One of the main differences between talking to a person and programming a


computer is the increased level of precision required to tell a computer how
to do things.
○ With people, it is often possible to give very vague instructions and still get the behavior you want.
○ With computer, it has no common sense. You must be very specific with it. Your instructions must be step by
step, in great detail.

13
Thinking like a programmer
● Teaching a Martian how to make a peanut butter and jelly sandwich
● Step by step instructions:
1. Get a loaf of bread
2. Remove two slides of bread and put them on the counter
3. Get a jar of peanut butter. Put it on the counter, too
4. Get a jar of jelly. Put it next to the peanut butter
5. Get a knife
6. Open the jar of peanut butter
7. Pick up a slice of bread
8. Using the knife, pick up a glop of peanut butter and spread it on the top of the slice of bread

● As long as each of these instructions is one that the Martian knows how to perform, when the
Martian finishes executing this program, the Martian will have a peanut butter and jelly
sandwich.

14
Thinking like a programmer
● If there is an instruction here that the Martian does not understand, that instruction needs to
be rewritten in more detail
● Step by step instructions:
1. Get a loaf of bread
2. Remove two slides of bread and put them on the counter
3. Get a jar of peanut butter. Put it on the counter, too
4. Get a jar of jelly. Put it next to the peanut butter
5. Get a knife
6. Open the jar of peanut butter
7. Pick up a slice of bread
8. Using the knife, pick up a glop of peanut butter and spread it on the top of the slice of bread

a. Insert the knife blade half-way into the jar of peanut butter
b. Remove the knife from the jar of peanut butter at a slight angle so
that some peanut butter is carried out of the jar by the knife

15
Thinking like a programmer
● An instruction that needs further explanation before the Martian (or computer) can execute it
is one that we call high level.
● We can use high level steps in our programs only if we can supply additional instructions to
explain how to actually execute these higher level steps.

● Although we don't know what instructions Martians are likely to understand, a programmer
knows what kinds of instructions are a part of the particular programming language in which
s/he is developing a computer program.

● As a programmer, you will design sequences of steps much like the peanut butter and jelly
sandwich instructions.
○ Asking: What do I do next?

16
Requirements
● Requirements are capabilities and conditions to which the program must
conform
● The purpose of requirements is:
○ To provide developers with a better understanding of the program
○ To define the boundaries of the program
○ To provide basis for planning the technical contents of iterations
○ To provide a basis for estimating cost and time to develop the program
○ To define a user-interface for the system, focusing on the needs and goals of the users

17
Requirement gathering
● This activity is to gather the essential requirements from the customer.
● The team of designers and business analysts will do brainstorming to extract
all the requirements and plan accordingly for the new system to be
developed.
● Some popular questions that this meeting picks up are:
○ Who will use the program?
○ What must be the output data by the program?

18
Importance of requirement gathering
● Requirement gathering involves the systematic collection and analysis of
information to identify and define the needs, objectives, and expectations of
stakeholders.

● Helps ensure stakeholder alignment


○ This can help reduce misunderstandings and disagreements later in the development process
● Reduces the risk of project failure
○ The resulting system will not meet the needs of its users
● Enables more accurate project estimation
○ More accurately estimate the time and resources needed to complete the project

19
Importance of requirement gathering
● Example: Requirements Gathering for a Mobile App
● A company wants to build a mobile app to help customers track their fitness
goals.
● The requirements gathering process might involve:
○ Meeting with stakeholders: The development team would meet with stakeholders from the marketing and
customer service departments to understand the app’s goals and the customer experience they want to
provide.
○ Analyzing user needs: The development team would analyze user needs to identify the key features and
functionality that the app should include. For example, users might need an easy way to track their workouts
and progress, while also receiving personalized recommendations and tips based on their fitness goals.
○ Defining specifications: The development team would use the information gathered from stakeholders and user

20
Requirement gathering techniques
● Brainstorming
● Document Analysis
● Focus Group
● Interface analysis
● Interview
● Observation
● Prototyping
● Requirement workshops
● Survey or questionnaire

21
Programming languages
● Programming language basics
○ A notation for specifying the steps in an algorithm for a digital device

○ Low-level programming languages (e.g., assembly)


■ Close in nature to machine language
○ High-level programming languages (e.g., C++, Java, and Python)
■ Contain a set of instructions corresponding to the algorithm
■ Statement: an instruction in a program
■ Program code (code): set of statements
■ Computer program: code distributed as computer software, desktop applications, web apps, and mobile
apps

○ Other popular programming languages include JavaScript, C, PHP, Swift, C#, Ruby, and Go

22
Programming languages
● Hello World in C++, Java, and Python

23
Programming languages
● Syntax and semantics
○ Syntax is equivalent to the grammar rules of a written language
○ Semantics: the meaning and validity of program statements
○ Programming languages include keywords, a subset of a programming language’s reserved words, which are
reserved for special purposes

24
Programming languages
● Core elements
○ Variables that can be assigned values and structures
○ Arithmetic operators that perform calculations
○ Keywords and built-ins that perform operations (e.g., print, import)
○ Data types that define values and text
○ Branching controls that change the statement execution sequence
○ Repetition controls that repeat a series of statements
○ Syntax rules for constructing valid statements
○ Terminology to describe language components and their functions

25
Programming languages
● Basic structure
○ Programming languages have structural and syntax conventions
○ Comments provide an explanation of the code but are ignored by computers
○ A directive tells the computer how to handle the program, not how to perform an algorithm
○ A statement contains one instruction
○ A code block contains multiple statements that have a specific purpose

26
Compilers and interpreters
● Programs written in high-level languages must be translated into machine language
to be executed

● Compiler: translates high-level language program into separate machine language


program
○ Machine language program can be executed at any time
● Interpreter: translates and executes instructions in high-level language program
○ Interprets one instruction at a time
○ No separate machine language program

● Source code: statements written by programmer


○ Syntax error: prevents code from being translated

27
Compilers and interpreters

https://ecomputernotes.com/what-is-c/difference-between-compiler-and-interpreter

28
Program development tools
● Program development tools are software applications designed to assist
developers in the creation, debugging, testing, and maintenance of software
programs.

● These tools offer a range of functionalities that simplify and automate various
aspects of the development process, allowing programmers to focus on
writing high-quality code.

29
Types of program development tools
● Integrated Development Environments (IDEs):
○ IDEs provide a comprehensive set of tools for software development within a single integrated interface. They
typically include a code editor, compiler, debugger, and other utilities.
○ Examples: Visual Studio, Eclipse, IntelliJ IDEA.

● Code Editors:
○ Code editors are lightweight tools that offer syntax highlighting, code completion, and basic debugging
functionalities.
○ Examples: Visual Studio Code, Sublime Text, Atom.

● Version Control Systems (VCS):


○ VCS helps manage changes to source code over time, allowing developers to collaborate effectively and track
code history.
○ Examples: Git, SVN (Subversion).

30
Coding tools
Program editors
● Coding tools allow you to express an algorithm using a programming
language's vocabulary
● Visual platforms may allow you to arrange visual elements that represent
statements
● Text editor: a program that can produce plain ASCII text but offers no
features designed to help programmers
● Code editor: a text editor specially designed for entering high-level
programming code
● Word processing programs add hidden symbols that do not belong in source
code

31
Coding tools
● Visual Studio code editor

32
How program development tools enhance
productivity?
● Faster Development: IDEs and code editors offer features like code completion and snippets,
speeding up the coding process.
● Code Quality: Linters and formatters enforce coding standards, reducing bugs and enhancing code
readability.
● Collaboration: Version Control Systems enable seamless collaboration among developers working
on the same project.
● Efficiency: Build automation tools simplify the build process and reduce manual errors.
● Bug Detection: Debugging tools help identify and fix issues during development, leading to more
robust software.
● Testing Automation: Testing frameworks ensure code reliability by automating the testing
process.

33
IDEs and SDKs
● Integrated development environments (IDEs)
○ An application that includes all of the tools needed to code, compile, link, and debug a program
○ Many support some level of visual programming
○ Examples: Visual Studio, Xcode, Eclipse, Netbeans, and PyCharm
○ Online IDE (or web IDE) examples: repl.it, codeanywhere, Ideone, and AWS Cloud9

34
IDEs and SDKs
● Software development kits (SDKs)
○ Tool set for developing platform-specific software
○ An SDK includes preprogrammed code libraries, code samples, documentation, and other utilities
○ May be wrapped in an IDE that provides coding, compiling, and debugging tools
○ Examples: Java Development Kit for Android apps, iOS SDK, Windows SDK, and Facebook SDK

35
Hands-On Activity
● Form pairs or small groups.
● As a group, choose an IDE compatible with Python that you would like to experiment
with.

● Input the Python Hello World! program from the module into the IDE and observe
how this looks and works.

● Try Google Colab


● https://colab.research.google.com/
● Colab, or "Colaboratory", allows you to write and execute Python in your browser, with
● Zero configuration required
● Access to GPUs free of charge
● Easy sharing

36 Lecture x: Title
Activity
● Code written in a high-level language must be converted into _____ consisting of machine
language instructions before the program will run on a digital device.

● A(n) _____ translates code written in one programming language, known as source code, into
object code in another language.

● Software called a(n) _____ converts bytecode into machine code as a program executes.

● A(n) _____ error occurs as a result of issues such as misspelled or incorrectly capitalized
keywords, unpaired brackets, incorrect indentation, or incorrect method parameters.

37 Lecture x: Title
END

38

You might also like