Libraries, Frameworks and SDKs
Level 4 · Other people's code
Code you reuse so you do not have to write it. How a library and a framework differ, what an SDK holds, and what each one costs you.
Course contentsLesson 7 of 13
Level 1 · The editor
Level 2 · Checking and fixing code
Level 3 · Trying code out
Level 4 · Other people's code
Level 5 · Building the project
After this lesson you can
- Tell a library from a framework
- Say what an SDK is for
- Count the cost of a new dependency
11 mincovers 4 glossary entries
Worth reading first: REPL, Notebooks and DevTools
Library or framework: who calls whom
A library is code someone else wrote for one job, like reading dates. You call it when you want. A framework is a ready-made base for a whole app, like Django, first out in 2005. It calls your code when it needs it. The one line to remember: you call a library, and a framework calls you.
With a library, your code stays in charge. Python's random library picks a random item when you ask it to, and does nothing until then. You can use one function from it and ignore the rest.
A framework sets the shape of the app. It decides where each kind of code goes and when it runs. You fill in the gaps it leaves, such as what a page shows. Django and React are well-known frameworks. You trade some freedom for a lot of work done for you.
An SDK, short for software development kit, is a box of tools for building on one service or device. It holds libraries, sample code and guides. A payment company hands out an SDK so an app can take payments in a few lines. A phone maker hands one out so people can build apps for its phones.
Each library, framework or SDK you add is a dependency. That means outside code your project needs to work. Each one can need others in turn, so adding one can pull in dozens. A project keeps a list of them, with the version of each.
A dependency saves you work today and costs you a little forever. It is more code to download, to update and to trust. If it breaks, or someone finds a hole in it, every project that uses it is at risk.
The common mistake is adding a big package for a tiny job. Before you add one, ask three things. Could you write it in ten lines? Is someone still looking after it? How many other projects use it?
import random
print(random.choice(["red", "blue", "green"]))Worked example
Emma skips a package
Emma needs to pad a number with zeros, like 7 into 007. A package for it would add 1 more dependency to her shop's 140.
She finds the language already has it built in, as one short function. She uses that, and her list stays at 140.
The words for this lesson4
Check yourself
How is a library not the same as a framework?
Finished this lesson?
Marking it complete also marks its 4 glossary entries learned, which updates your roadmap and your saved page. 0 are already marked.