Lunch bytes #1: writing safer (Python) code

9 September 2020 - 12:00-13:00
Blackboard Collaborate
Joe Heffer, David Jones, Will Furnass, University of Sheffield

All of our events may be recorded and shared via the University of Sheffield Kaltura platform so those who cannot attend may still benefit. We will consider your attendance implict consent to this.

What methods and tools can we use to make it easier to write less buggy Python software? At this inaugural event we’ll be exploring this question via three short talks. Each will be ~10 minutes, leaving half an hour for discussion/questions.

Blackboard Collaborate event (participants can join 15 mins before the start of the session).

Google JamBoard for Q&A: note down questions/comments (using JamBoard Sticky Notes) before/during the event.

Type hinting in Python

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.

A Practical Introduction to pytest

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”.

Avoiding ‘side effects’: writing functions that are easier to test

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.

Contact Us

For queries relating to collaborating with the RSE team on projects:

Information and access to JADE II and Bede.

Join our mailing list so as to be notified when we advertise talks and workshops by subscribing to this Google Group.

Queries regarding free research computing support/guidance should be raised via our Code clinic or directed to the University IT helpdesk.