Your app is not alone
You build a football app. It must run on a phone. It must talk to a server far away. It must read scores from another company. It may run on a computer in the cloud, which you rent for a short time.
Real software always works with other things. This lesson shows how to join them.
Key words
| Word | What it means | Example |
|---|---|---|
| Existing application | A program your software must work with. | A spreadsheet, a bank system |
| Operating system | The main software that runs programs and controls the hardware. | Windows, Android, Linux |
| Cloud platform | Computers you rent over the internet and pay for as you use them. | AWS, Azure |
| Traditional platform | Computers you buy and run yourself in your own building. | |
| Driver | Software that lets an operating system talk to one device. | |
| Network | Computers joined together so they can send data to each other. | |
| Protocol | A set of rules for how two computers talk. | HTTP |
| Infrastructure as code | Servers described in a file that a tool builds. | |
| Container | A sealed box with a program and all it needs. |
The cells students fill in are left blank in this preview.
Cloud or traditional?
| Cloud platform | Traditional platform | |
|---|---|---|
| Where | In a data centre owned by a company | In your own room or building |
| Cost | Pay small amounts as you use it | Pay a lot at the start to buy machines |
| Grow | Add more in minutes | Order, wait, install |
| Control | The company looks after the hardware | You look after everything |
| Good for | A new app with unknown users | Data that must stay in your building |
The cells students fill in are left blank in this preview.
Check: which platform fits?
Have a go
Check: which platform fits?
3 questionsOperating systems and devices
Your code runs on an operating system. Windows, macOS, Linux, Android and iOS do things in different ways. File paths, permissions and programs are not the same on each.
A phone has a camera, GPS (it finds where you are) and sensors (parts that measure things, such as movement). A driver lets the system use each one. To use a device, ask the operating system. Do not talk to the hardware yourself.
Working with specific devices
| Device | What you can use | What to check first |
|---|---|---|
| Phone | Camera, GPS, touch, sensors | Did the user give permission? |
| Laptop | Keyboard, mouse, files | Which operating system? Which screen size? |
| Smart watch | Heart rate, small screen | Is there battery for it? |
| Games console | Controller, TV screen | Does the maker allow your software? |
The cells students fill in are left blank in this preview.
Check: using devices
Have a go
Check: using devices
3 questionsAsk the operating system about itself
import os
import platform
print("System:", platform.system())
print("Separator in paths:", os.sep)
print("Joined path:", os.path.join("data", "scores.txt"))
# os.path.join uses the right separator on any system.
# That is how code works on many systems.
Make a free account to save your work and track your progress.
Talking over a network
A network joins computers. Your app sends a request. A server sends back a response.
Both sides follow a protocol, a set of rules. The web uses HTTP. Your app often talks to an existing application the same way, such as a club's ticket system.
A network can be slow or break. Good code expects this. It waits a limited time, tries again and shows a clear message.
A request over a network
sequenceDiagram
participant App as Your app
participant Net as Network
participant Server as Scores server
App->>Net: Request: latest scores
Net->>Server: Request arrives
Server-->>Net: Response: scores
Net-->>App: Response arrives
Note over App,Server: If no response comes, the app tries again or shows a message
Match the word
Have a go
Loading…
Your answers are marked here and are not kept. A college account keeps every student’s marks.
Infrastructure as code
Building servers by hand is slow. People make mistakes. Nobody remembers every click.
Infrastructure as code means you write the servers you want in a file. A tool reads the file and builds them. The file goes in version control (a tool that keeps every version of your files), so you can see every change. Run it twice and you get the same result.
A file that describes servers
# This is only data. A tool reads it and makes it true.
desired = {
"web": "small",
"database": "large",
}
current = {"web": "small", "old-test": "small"}
for name in desired:
if name not in current:
print("Create", name)
for name in current:
if name not in desired:
print("Delete", name)
Make a free account to save your work and track your progress.
Containers in one idea
A container holds your program and everything it needs. It runs the same on your laptop and on a server.
Many containers can share one machine. Each is kept apart from the others. You will use containers in the deployment lessons.
Plan the changes a tool makes
This is how a tool for infrastructure as code works. It compares the servers you want with the servers you have. Then it lists the actions. Finish plan and summary. Press Run Tests.
def plan(desired, current):
# desired and current are dictionaries: server name -> size, like {"web": "small"}.
# Give back a list of actions, as pairs, in this order:
# first every ("create", name) for a name only in desired,
# then every ("update", name) for a name in both with a different size,
# then every ("delete", name) for a name only in current.
# Inside each group, sort the names A to Z.
return None
def summary(actions):
# Give back text like: 1 to create, 2 to update, 0 to delete
return None
Make a free account to save your work, or press Start lab to work through the whole lesson.
Exit quiz
Have a go