After spending a year or so on the self-taught path to programming with Python, I hit the reset button and started over by taking a course in Intensive Program Design. After just a few weeks, I picked up a load of important lessons in the fundamentals of writing software that I never cared to learn before. In a way, I finally learned enough to learn how to learn to program, which is a skill that I did not know I needed.

In this story, I memorialize part of what I’ve learned so far, partly so I don’t forget, but also, to share a few tips on how to understand abstraction and why it is important.

Lesson 1 — You already know abstractions, no sweat

Ever use a built-in function like sum() to add a list of numbers or len() to get the length of an object in Python? If so, you already know what an abstraction is, that is, a function that hides how it does what it does so you can get on with your life.

For instance, with a simple example below, we can see how sum() hides how it adds a list of numbers by manually creating a loop that does the same job.

## how to add a list of numbers, two ways
lst_of_numbers = [2,3,5]

## example of using a built-in function as an abstraction
sum_with_abstraction = sum(lst_of_numbers)
print('With Built-in Function:', sum_with_abstraction)
## example of getting sum without a built-in function
sum_with_loop = 0
for i in lst_of_numbers:
  sum_with_loop += i
print('Without Built-in Function:', sum_with_loop)
## Output
## >>> With Built-in Function: 10
## >>> Without Built-in Function: 10

Lesson 1 Conclusion: So what’s the big deal about recognizing built-in functions as a form of abstraction?

Most importantly— do not be intimidated when someone throws the word abstraction around because you already know what it is. Further, it’s worth recognizing a built-in function exists for most of your programming needs and probably performs better than building something from scratch. However, what to do about other tasks without a ready-to-go function?

#programming #functional-programming #python #beginner #abstraction

Get a Grip on Programming With Abstractions
1.05 GEEK