concept abstraction in category python

appears as: bstractions, abstraction, bstraction, Abstraction, n abstraction, The abstraction, Abstractions
Math for Programmers: 3D graphics, machine learning, and simulations with Python

This is an excerpt from Manning's book Math for Programmers: 3D graphics, machine learning, and simulations with Python.

1.3.3                   Building abstractions with functions

In programming, the process I just described is called abstraction. For example, when you get tired of repeated counting, you create the abstraction of addition. When you get tired of doing repeated addition, you create the abstraction of multiplication, and so on.

Of all the ways that you can make abstractions in programming, the most important one to carry over to math is the function. A function in Python is a way of repeating some task that can take one or more inputs or that can produce an output. For example,

Practices of the Python Pro

This is an excerpt from Manning's book Practices of the Python Pro.

3.1. What is abstraction?

When you hear the word abstract, what do you think of? Usually a Jackson Pollock painting or a Calder sculpture runs through my mind. Abstract art is marked by a freedom from concrete form, often only suggestive of a specific subject. Abstraction, then, would be the process of taking something concrete and stripping it of specifics. When speaking about abstraction in software, this is exactly right!

3.1.2. Abstraction is like an onion

You saw in figure 3.2 that each step in a workflow generally represents some lower-level code. Some of those steps, though, such as determining the grammatical structure of a sentence, are quite involved. Complex code like this will often benefit from layers of abstraction; low-level utilities support small behaviors, which in turn support more involved behaviors. Because of this, writing and reading code in large systems is often like peeling an onion, revealing smaller, more tightly packed pieces of code underneath (figure 3.3).

Figure 3.3. Abstraction works in layers of complexity.
Listing 10.8. Decoupling layers of abstraction with interfaces
class AddBookmarkCommand(Command):                                            #1
    def execute(self, data, timestamp=None):
        data['date_added'] = timestamp or datetime.utcnow().isoformat()
        db.add('bookmarks', data)
        return True, None                                                     #2

class ListBookmarksCommand(Command):                                          #3
    def __init__(self, order_by='date_added'):
        self.order_by = order_by

    def execute(self, data=None):
        return True, db.select('bookmarks', order_by=self.order_by).fetchall()#4
Get Programming: Learn to code with Python

This is an excerpt from Manning's book Get Programming: Learn to code with Python.

In programming, abstraction aims to present ideas at a high level. It’s the process of documenting what a piece of code does, with three key bits of information: inputs, the task, and outputs. You’ve seen black boxes represented using this information.

Abstraction in code eliminates the details of how the code for a task/module is implemented; instead of looking at the code for a module, you look at its documentation. To document the module, you use a special type of code comment, called a docstring. A docstring contains the following information:

In lesson 20, you saw that dividing larger tasks into modules can help you to think about problems. The process of breaking up the task leads to two important ideas: modularity and abstraction. Modularity is having smaller (more or less independent) problems to tackle, one by one. Abstraction is being able to think about the modules themselves at a higher level, without worrying about the details of implementing each. You already do this a lot in your day-to-day life; for example, you can use a car without knowing how to build one.