0% found this document useful (0 votes)
4 views

Advanced Coding Skills

The document outlines guidelines for analyzing and translating technical English phrases related to coding and refactoring. It emphasizes the importance of writing clean code, the need for unit tests before refactoring, and best practices such as avoiding magic numbers and using curly braces in if-statements. Additionally, it provides examples and advice on how to improve legacy code for better readability and functionality.

Uploaded by

englishwitherika
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Advanced Coding Skills

The document outlines guidelines for analyzing and translating technical English phrases related to coding and refactoring. It emphasizes the importance of writing clean code, the need for unit tests before refactoring, and best practices such as avoiding magic numbers and using curly braces in if-statements. Additionally, it provides examples and advice on how to improve legacy code for better readability and functionality.

Uploaded by

englishwitherika
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Analista de Sistemas ORT Inglés Técnico

Consignas:

1. Analice e indique referente de 4 (cuatro) de las palabras sustitutas subrayadas.


2. Analice 2 (dos) de las frases verbales subrayadas y resaltadas y provea una
traducción.
3. Traduzca (2) dos de las frases nominales in Italics.
4. Indique si las siguientes afirmaciones son verdaderas (V) o falsas (F). Corrija las
incorrectas.
a. La calidad de los códigos es lo que define a un buen programador. ____
b. Las técnicas presentadas en el artículo sólo servirán para refactorizar un
código viejo. _____
c. Se recomienda comenzar a trabajar con códigos heredados, ya que resultan
más fáciles de abordar. _____
d. 250 es el número mágico que se considera tope. ____

5. Traduzca el párrafo recuadrado

Advanced Coding Skills, Techniques, and Ideas

Good developers are defined by the quality of their codes. In the software industry,
writing good code means saving the money that may be invested in testing,
updating, extending or fixing bugs. In this article, I will show you real-life examples of
some techniques and ideas that will help you to clean up your legacy code and refactor
it to make it more robust and modular. These techniques will not only help you to
refactor your old code but will give you great ideas as to how to write clean code from
now on.

● What is refactoring and why do we need It?

Refactoring refers to techniques and steps that help you to write clean code. This is
important for other developers, who then will be able to read, extend and reuse the code
without the need to edit much. Some examples of refactoring a legacy code and making it
better will be shown next.

● Never refactor a production code that does not have unit tests

My first advice is to not ever start refactoring a legacy code, which does not have proper
unit tests. I guess the reason is obvious: You will end up with broken functionalities that
are difficult to fix because you won’t be able to figure out what’s broken. Therefore, if you
need to refactor it, start with testing it first. Make sure the part you are going to refactor is
covered by the tests.

● Start refactoring from the deepest point of your code


Analista de Sistemas ORT Inglés Técnico

Take a look at the next picture. This is a real project for a hotel management system that I
found on GitHub. This is a real open source project so the closed source can be worse.

Example: refactoring deepest points first

As you can see in this method, there are three levels marked in red. The deepest point
should be the nested if/else statement inside the first if condition. Usually, the deepest
point is focusing on a single logic which makes it easier to refactor.

● Make your methods shorter by dividing them into smaller methods or


configuration files/DB table
Maybe, in this case, it can be extracted to a private method as follows:

● Make your functions shorter

The next deepest point will be fetching the post data and loading the views. Now, take a
look at the method add() after refactoring the other parts. It is much cleaner, readable and
testable.
Analista de Sistemas ORT Inglés Técnico

Example: refactoring deepest points first

● Always use {} within if-statements

Most of the programming languages support one-line if-statements and some


developers use it because it is simple, however, it is not readable and it’s easy to cause
problems since only one empty line can break the condition and start crashing. See the
difference between the two examples:

Example: use curly braces


Analista de Sistemas ORT Inglés Técnico

● Do not use magic numbers or magic strings:

In the next example, you notice if rooms are more than 250, it returns an error message.
In this case, 250 is considered a magic number. If you’re not the developer who wrote it, it
will be hard to figure out what it represents.

Example: fix magic numbers

Example: magic numbers

In order to refactor this method, we can figure out that 250 is the maximum number of
rooms. Therefore, instead of hardcoding it, we can extract it to variable
$maxAvailableRooms. Now, it is more understandable to other developers.

You might also like