LunchBytes talks #1: writing safer (Python) code
From William Furnass on September 14th, 2020
Joe Heffer, Research Data Engineer, IT Services
What on earth is that object?
Make your Python code more readable, for yourself and your collaborators,
reduce risk of incorrect inputs and increase your IDE productivity by
annotating your functions with type hints.
David Jones, Research Software Engineer, RSE team
You can test your Python code with pytest, one of the leading systems for testing Python code. Here I will gently introduce you to pytest with practical examples. As pytest themselves put it pytest “helps you write better programs”.
Will Furnass, Research Software Engineer, RSE team
Everyone who writes code needs to consider if/when/how to encapsulate
code as functions.
But what makes for a good function that you can test/validate? One
strategy is to try to write a proportion of your functions so they don’t
have ‘side effects’,
where a side effect is something like reading/writing a file or
reading/writing data over a network.
By creating functions that only return useful values and don’t perform side effects functions can be much easier to test.
Here we discuss why, when and when not to write functions without side effects.
This talk should be of interest to those who write Python code and code in other languages.