Carlos Chacin

Software Engineering Experiences

☕️ Immutables/AutoValue/Lombok 🔥 Which One?

Posted at April 12, 2020 /


In this article, we are going to compare some of the features of the library, Google AutoValue and Project Lombok:

  • Generated the Builder pattern by default?
  • Generated helper methods for, i.e., Optional and List?
  • The number of lines of code to write?
  • Required IDE’s plugins?
  • Are the objects immutable?

The three libraries are based on an annotation processor to generate/modify code for us:

  • Immutable classes
  • equals, hashCode and toString methods
  • other utilities

NOTE: Immutables and AutoValue generate new classes with the processor, and Lombok modifies the bytecode of the original class.

Read more ...

🎩 Immutability in Java 🔥 Made Easy

Posted at April 11, 2020 /


In Effective Java, Joshua Bloch makes the following recommendation:

Classes should be immutable unless there’s a very good reason to make them mutable… If a class cannot be made immutable, limit its mutability as much as possible.

🔩 Immutable Objects

An object is considered immutable if its state cannot change after it is constructed. Maximum reliance on immutable objects is widely accepted as a sound strategy for creating a simple, reliable code. reference

  • Immutable objects are constructed once, in a consistent state, and can be safely shared
    • Will fail if mandatory attributes are missing
    • Cannot be sneakily modified when passed to other code
  • Immutable objects are naturally thread-safe and can therefore be safely shared among threads
    • No excessive copying
    • No excessive synchronization
  • Object definitions are pleasant to write and read
    • No boilerplate setter and getters
    • No ugly IDE-generated hashCode, equals and toString methods that end up being stored in source control. reference
Read more ...

💉 Inyección de Dependencias en Java ☕️

Posted at February 10, 2020 /


Read the English Version here

Java es un lenguaje orientado a objetos con algunos aspectos funcionales incluidos en su núcleo. Al igual que cualquier otro lenguaje orientado a objetos, las clases y los objetos son la base de cualquier funcionalidad que podamos escribir y usar. Las relaciones entre las clases / objetos permiten ampliar y reutilizar la funcionalidad. Sin embargo, la forma en que elegimos construir esas relaciones determina cuán modular, desacoplada y reutilizable es nuestra base de código, no solo en términos de nuestro código de producción sino también en nuestras suites de prueba.

En este artículo, vamos a describir el concepto de Inyección de dependencias en Java y cómo nos ayuda a tener una base de código más modular y desacoplada, lo que nos facilita la vida, incluso para las pruebas, sin la necesidad de ningún contenedor o marco sofisticado.

Read more ...

💉 Dependency Injection in Java ☕️

Posted at November 14, 2019 /


Lee la versión en Español aquí

Java is an object-oriented language with some functional aspects included in its core. Like any other object-oriented language, classes and objects are the foundations of any functionality that we can write and use. The relationships between the classes/objects make it possible to extend and reuse functionality. However, the way that we choose to build those relationships determine how modular, decoupled, and reusable our codebase is, not only in terms of our production code but also in our test suites.

In this article, we are going to describe the concept of Dependency Injection in Java and how it helps us have a more modular and decoupled codebase, which makes our lives easier, even for testing, without the need of any sophisticated container or framework.

Read more ...

Java 8 Type Safe Configuration with default methods

Posted at December 21, 2015 /

There is a common requirement in most of the Java/JavaEE projects related to how differentiate environment configurations like development, test, QA, production, etc. for that reason there are a lot of frameworks or libraries to resolve that:

Even there is a Java Specification Request (JSR) Proposal:

Read more ...