DCIT104 Lecture 2
DCIT104 Lecture 2
PROGRAMMING
FUNDAMENTALS
College of Education
School of Continuing and Distance Education
2020/2021 – 2022/2023
Session Overview
Just as knowing how a car works "under the hood" has benefits to a car
owner, knowing how a computer works under the hood has benefits to a
programmer. This section provides a very brief introduction.
Google Confidential and Proprietary
zyBooks
Switches
• When people in the 1800s began using electricity for lights and
machines, they created switches to turn objects on and off.
• A switch controls whether or not electricity flows through a wire.
• In the early 1900s, people created special switches that could be
controlled electronically, rather than by a person moving the switch
up or down.
• In an electronically controlled switch, a positive voltage at the
control input allows electricity to flow, while a zero voltage
prevents the flow.
• Such switches were useful, for example, in routing telephone calls.
• Engineers soon realized they could use electronically controlled
switches to perform simple calculations. Google Confidential and Proprietary
zyBooks
Bits
Below are some sample types of instructions that a processor might be able to
execute, where X, Y, Z, and num are each an integer.
The term computer has changed meaning over the years. The term
originally referred to a person that performed computations by hand, akin
to an accountant ("We need to hire a computer.") In the 1940s/1950s, the
term began to refer to large machines like in the earlier photo.
• In the 1970s/1980s, the term expanded to also refer to smaller
home/office computers known as personal computers or PCs
("personal" because the computer wasn't shared among multiple users
like the large ones) and to portable/laptop computers.
• In the 2000s/2010s, the term may also cover other computing devices
like pads, book readers, and smart phones.
• The term computer even refers to computing devices embedded inside
other electronic devices such as medical equipment, automobiles,
aircraft, consumer electronics, military systems, etc.
Google Confidential and Proprietary
zyBooks
The Computer: Early Days
• A disk (aka hard drive) stores files and other data, such as
program files, song/movie files, or office documents.
• Disks are non-volatile, meaning they maintain their contents even
when powered off.
• They do so by orienting magnetic particles in a 0 or 1 position.
• The disk spins under a head that pulses electricity at just the right
times to orient specific particles (you can sometimes hear the disk
spin and the head clicking as the head moves).
• New flash storage devices store 0s and 1s in a non-volatile
memory, rather than disk by tunnelling electrons into special
circuits on the memory's chip and removing them with a "flash" of
electricity that draws the electrons back out. Google Confidential and Proprietary
zyBooks
Memory
In 1978, Brian Kernighan and Dennis Ritchie at AT&T Bell Labs (which
used computers extensively for automatic phone call routing) published a
book describing a new high-level language with the simple name C,
being named after another language called B (whose name came from a
language called BCPL).
• C became the dominant programming language in the 1980s and
1990s.
zyBooks
Swift 1% Google Confidential and Proprietary
Programming Languages vs. Problem Solving
• A chef may write a new recipe in English, but creating a new recipe
involves more than just knowing English.
• Similarly, creating a new program involves more than just knowing
a programming language.
• Programming is largely about problem solving: creating a
methodical solution to a given task.
A person stated a dislike for matching socks after doing laundry, indicating
there were three kinds of socks. A friend suggested just putting the socks in a
drawer and finding a matching pair each morning. The person said that finding a
matching pair could take forever: Pulling out a first sock and then pulling out a
second, placing them back and repeating until the second sock matches the first
could go on many times (5, 10, or more).
The friend provided a better solution approach: Pull out a first sock, then pull
out a second, and repeat (without placing back) until a pair matches. In the
worst case, if three kinds of socks exist, then the fourth sock will match one of
the first three. Google Confidential and Proprietary
zyBooks
Example: Sorting Name Tags
1,000 name tags were printed and sorted by first name into a stack. A person wishes to
instead sort the tags by last name. Two approaches to solving the problem are:
• Solution approach 1: For each tag, insert that tag into the proper location in a new
last-name-sorted stack.
• Solution approach 2: For each tag, place the tag into one of 26 substacks, one for last
names starting with A, one for B, etc. Then, for each substack's tags (like the A
stack), insert that tag into the proper location of a last-name-sorted stack for that
letter. Finally combine the stacks in order (A's stack on top, then B's stack, etc.).
Solution approach 1 will be very hard; finding the correct insertion location in the new
sorted stack will take time once that stack has about 100 or more items. Solution
approach 2 is faster, because initially dividing into the 26 stacks is easy, and then each
stack is relatively small, so insertions are easier to do.
In fact, sorting is a common problem in programming, and the above sorting approach
is similar to a well-known sorting approach called radix sort.
Google Confidential and Proprietary
zyBooks
Why Programming?
• The rankings are based off growth potential, work-life balance, and salary.
2018 Median
Occupation Job Summary Entry-level Education
Pay
Computer and information research scientists
invent and design new approaches to computing
Computer and
technology and find innovative uses for existing Doctoral or professional
Information $111,370
technology. They study and solve complex degree
Research Scientists
problems in computing for business, medicine,
science, and other fields.
Computer network architects design and build
data communication networks, including local
area networks (LANs), wide area networks
Computer Network
(WANs), and intranets. These networks range Bachelor's degree $109,020
Architects
from a small connection between two offices to a
multinational series of globally distributed
communications systems.
Computer programmers write code to create
software programs. They turn the program
Computer
designs created by software developers and Bachelor's degree $84,280
Programmers
engineers into instructions that a computer can Google Confidential and Proprietary
zyBooks follow.
Computing Jobs
Source: bls.gov (includes links to detailed descriptions and outlooks for each occupation)
Google Confidential and Proprietary
zyBooks
Programming and Non-computing Jobs
Gustav majored in business, and got a job in sales operations of a Silicon Valley startup
company. Building on the C++ programming he learned from a college course, he started
tinkering with writing database query programs using "SQL", and discovered he had a
knack for it. His job duties have expanded to include running database reports, and he has
automated dozens of reports via programming, helping people throughout the company be
more productive.
A student cannot watch a piano teacher play and then walk away playing
piano. Writing correct expressions, properly formed if-else branches,
correctly working loops, etc., requires repeated attempts, and, like the new
piano player, lots of mistakes along the way.
Programming also requires a lot of mental energy. No easy steps exist for
how to solve a given problem by writing a program.