If you have notes for lesson 9, please add them here! Many thanks for the great contributions so far - they’re really appreciated.
A Note on Software Engineering
In the course Deep Learning From the Foundations, there is much to learn about software engineering from the Fastai team.
Software engineering – in a nutshell – is the art of writing and testing efficient, understandable, reliable, reusable, and maintainable code.
Here are a few simple rules to help set you on the road to good software engineering practice.
- Use descriptive variable names. For example, instead of variables named
m, use informative names such as
n_columns; instead of
n_hidden, instead of
Never use single character names for important variables.
Why? Suppose you have a variable named
n, and you find that for some good reason, you need to rename
n_iter. Imagine trying to do a ‘find and replace’ on
n, one of the most commonly used characters in the English language?
- Pass numerical values into functions as keyword arguments.
For example, consider the following line of code:
s = Sampler(small_ds,3,False)
This code is not efficient for the reader, who will likely have no idea of what the values
False represent. To find out, they’ll have to spend extra time examining the code for the
On the other hand, consider an alternative form:
s = Sampler(small_ds,batch_size=3,shuffle=False)
Calling the inputs as keyword arguments gives the reader a good idea of how these values control the behavior of
- Document your code as you write. For each small block of code, provide a clear explanation of its function. Although it does slow you down a bit, documentation that records how your code was built and the decisions that went into its construction will be invaluable to you or anyone else who wants to understand, use, refactor, or repurpose your code at a later time.
Following rules such as these is well worth your while – especially when you come back to your code after a hiatus and try to remember what you did, or when you want to share your code with others.