This week I
tried Clojure that programing language uses the Java Virtual Machine and it is
a general-purpose language. This language is a dialect of Lisp. Basically what
I did with this language was reading 2 chapters of Clojure that were about the
installation of it and also a little bit about how it works. I checked a page
that is a little tutorial about this language, too.
Additionally
I read about SOLID principles, and Bryan also explained about it. So, what is
SOLID? The meaning of each letter it’s going to be explained in a moment. The
purpose of SOLID is that if we follow these principles we are going to have
applications that are easy to extend and maintain.
Let’s see
what that SOLID means:
S: Single Responsibility Principle
The main
idea with this principle is that classes must have only one reason to change.
O: Open/Closed Principle
The general
idea with it is that a class should be open for extension but closed for any
changes (just bugs)
L: Liskovs Substitution Principle
This is
about heritance. It says that a method takes determined class as an argument;
it must be able to work with any subclass.
I: Interface Segregation Principle
It is about
interfaces, that they should be small, because large interfaces make harder to
extend smaller parts of the system.
D: Dependency Inversion Principle
“It states
that you should let the caller create the dependencies instead of letting the
class itself create the dependencies.”
Beyond
these topics I also keep on with the Clean Code book, this time with chapters 3
and 10 that were about functions and classes respectively, the main things that
I should stand out are:
- Functions should be small
- Blocks within if-else statements, while statements should be a line long
- The indent level of a function should be one or 2.
- Functions should do just one thing; they should tell us a clear story
- A level of abstraction per function.
- Also they mention in this chapter how important the names are
- A function should have the minimum amount of arguments
- Functions do either do something or answer something but not the two at the same time
- We should prefer return exceptions instead of error codes.
- A class should have one responsability
- Also it is important keep classes with higher cohesion.
- Apply the SRP.
Moreover, I
watched 2 videos about test driven development, they were really interesting,
and make clear why do we should apply TDD. In these videos it is remarked the
importance of TDD and the main things are:
- Expressiveness of code is needed in this way comments are not needed.
- Be careful with spaces and indentation.
- We must avoid the code rot, because it makes the code fragile, rigid and stationary
- The people allow code rot because if they clean it they will break it.
- Tests let you clean the code
- TDD speeds development
- We need to have control defects with TDD we can do, then there is no fear of making changes later
- The test set must have a very small runtime
- Uncle Bob mentioned 3 laws of TDD and these are:
- write no production code
except to pass a failing test
- write only enough of a test to demonstrate a
failure
- write only enough production code to pass the
test
- Uncle Bob says that we must write tests before code.
- Writing tests first makes the production code testable
- Also with TDD you obtain a better design
- TDD reduce debug time
- TDD reduce documentation
- TDD allows cleaning the code
- To do well code we have to rework and refine it, it is not going to be perfect the first time.
No hay comentarios:
Publicar un comentario