Programming 101–6. abstractions I

Tom Deneire
7 min readOct 12, 2024
Photo by AltumCode on Unsplash

Disclaimer: the Programming 101 series was originally written to be published as a short book. However, since I never got round to finishing it, I’m publishing the chapters here as individual blog posts…

Now that you are fully immerged in the art of computer programming, let me share a little secret with you. Programming might seem hard work, but in many ways, it is, in fact, the art of laziness! In other words, many programming concepts or techniques were born out of practical necessity (think back to the first compilers!) or even convenience! After all, that’s what computer are for, right, to make our lives easier?

Functions

Let’s go back to our email example. What we had there was a piece of code that reconstructed names from email addresses. Regardless of whether this is a good idea, it is obvious that it would be quite tedious to repeat the same code over and over again, should we need to do the same for a long list of email addresses.

What we need is a function that we can reuse for every item in the list:

emails = ["john.doe@gmail.com", "jane.doe@gmail.com"]

def email_to_name(email):
name = email.split("@")[0]
first = name.split(".")[0]
last = name.split(".")[1]
display_form = last.capitalize() + ", " + first.capitalize()
return display_form

for…

--

--

Tom Deneire
Tom Deneire

Written by Tom Deneire

Software engineer, technical writer, IT burnout coach @ https://tomdeneire.be/confident_coding

No responses yet