Por que a abstração é a chave para o código simples

Why abstraction is the key to simple code

Abstraction is essential for balance.

Imagem em destaque

The Zen of Python aphorism “explicit is better than implicit” and we understand that abstraction only occupies a smaller space in software development. Along these lines, it's best to put everything in the code to be as clear as possible. However, this seems like an oversimplification. In fact, the next aphorism on the Zen of Python list is “simple is better than complex”.

So how do the two live with each other? If you expressed everything, you would end up with a huge code that would be impossible to work on. On the other hand, oversimplification can lead to too many assumptions, which can leave the code beyond understandable (except for two individuals: you and God, and sometimes not even you). Given this scenario, everything starts to become clearer: simplifying the code is fundamental, but in the right way. Abstraction is essential to achieve this balance – as long as you know the best contexts to use it.

What is abstraction in software development?

When you hear the term “abstraction,” you probably think of something that isn't physical, like an idea. While this is part of what “abstraction” means in the development world, we need to add something to fully understand it. This has to do with “abstraction” as action, that is, considering something from a theoretical perspective and separated from something else.

So, if we combine these two parts, it is possible to obtain a more precise definition: in software development, abstraction is a way of simplifying an idea or action. Therefore, the task is to consider an element of our development and look for ways to express it in a simpler way.

A real-life example will certainly help you understand this: when you type print (“Hello, world”) in the console, you know you will see a “Hello, world”. printed on the screen. It's something very basic and that's why it's the first thing you learn as a developer when learning a new language. But despite all its simplicity, could you explain how this simple command ends up printing this message? What is the “magic” that makes this happen?

Chances are you don't have the answer, but that's okay. Why would you want to know that? You just need to know that if you use the print function, you will get a specific output (in this case, “Hello, world.”). As such, this program is an abstraction. It is a single line of code that provides expected output while “hiding” its inner workings. You just need to know what to enter to anticipate the result.

This function (all functions, in fact) hides all the complexity and allows you to use it in a simpler way. In addition to functions, other abstractions are very common in software development: libraries, database management systems, REST APIs, and more. Without these abstractions, developing software would be a Herculean task because it would be necessary to work with complex lines of code.

Abstraction as a key to simple code

If abstraction in software development allows developers to perform complex tasks in simple ways, you might think there's not much more to be said: abstraction makes code simple. While this is true, it is important to understand something else. Abstraction is not something that has already been done – it is constantly evolving. In other words, every time you code, you can create your abstractions. And you definitely should, because it can help you develop better apps and much simpler code.

Why? Because using abstractions the right way will make code more readable, maintainable, and scalable. This is done by hiding the details that ultimately don't matter for the use at hand and providing only the parts that are relevant to that specific context. In other words, abstraction means less code, which in turn means a more manageable product.

There's nothing to scoff at, especially when software means thousands of lines of code. Using abstractions is useful because it allows you to be more economical with what you write. What's more important - they allow you to free yourself from hard dependencies on your current elements, which means you can change those elements at any time in the future and only need to refactor the abstraction itself, not every line of code touched for what you changed.

So using abstractions means your code is simpler by being shorter and more readable, but it also means it will be simpler to manage in the future. This is something any developer should aspire to, as all products will eventually be updated, upgraded, and maintained. Abstractions make it easier to provide a longer lifespan for every product you develop.

A necessary mindset shift

Modern programming involves abstractions. In fact, we could say that modern applications are created on top of an infinite number of abstractions and no one could argue. That's why it's so essential that you learn when to use them. This can make your development work simpler and manage increasing complexity with better oversight.

If you're already developing products, you're already using abstractions, even if you don't think about it. What you need to do now is to put aside this unconscious use and make a mental shift, adopting abstractions as another tool in your set. By doing this, you will be able to identify better instances where abstractions can make a difference, thus creating better products and increasing your productivity.

Conteúdo Relacionado

O Rails 8 sempre foi um divisor de águas...
A GenAI está transformando a força de trabalho com...
Entenda o papel fundamental dos testes unitários na validação...
Aprenda como os testes de carga garantem que seu...
Aprofunde-se nas funções complementares dos testes positivos e negativos...
Vídeos deep fake ao vivo cada vez mais sofisticados...
Entenda a metodologia por trás dos testes de estresse...
Descubra a imprevisibilidade dos testes ad hoc e seu...
A nomeação de Nacho De Marco para o Fast...
Aprenda como os processos baseados em IA aprimoram o...
A web está em constante evolução, e com ela,...
A Inteligência Artificial (IA) tem sido um tema cada...
Você já se sentiu frustrado com a complexidade de...
O OpenStack é uma plataforma de computação em nuvem...
Você já se sentiu frustrado com a criação de...
A era digital trouxe uma transformação profunda na forma...
Nos dias atuais, a presença digital é fundamental para...
Introdução Quando se trata de desenvolvimento de software, a...
Como desenvolvedor Dart, você provavelmente já se deparou com...
Back to blog

Leave a comment

Please note, comments need to be approved before they are published.