Code Formatting Consistency
🎯 Qué significa:
Section titled “🎯 Qué significa:”Mantener el MISMO estilo de código en TODO el proyecto - indentación, espacios, naming, orden, etc.
❌ PROBLEMA - Código inconsistente:
Section titled “❌ PROBLEMA - Código inconsistente:”// ❌ Diferentes estilos en el mismo proyectopublic class UserService{ private String name;
public void processOrder(String email,double amount) { if(email==null){ throw new IllegalArgumentException("Email required"); }
for(int i=0;i<10;i++){ System.out.println( "Processing..." ); } }}
public class OrderService { private String name ;
public void processPayment( String email , double amount ) { if ( email == null ) { throw new IllegalArgumentException( "Email required" ) ; }
for ( int i = 0 ; i < 10 ; i++ ) { System.out.println("Processing..."); } }}
✅ SOLUCIÓN - Código consistente:
Section titled “✅ SOLUCIÓN - Código consistente:”// ✅ Mismo estilo en todo el proyectopublic class UserService { private String name;
public void processOrder(String email, double amount) { if (email == null) { throw new IllegalArgumentException("Email required"); }
for (int i = 0; i < 10; i++) { System.out.println("Processing..."); } }}
public class OrderService { private String name;
public void processPayment(String email, double amount) { if (email == null) { throw new IllegalArgumentException("Email required"); }
for (int i = 0; i < 10; i++) { System.out.println("Processing..."); } }}
🛠️ ASPECTOS DE CONSISTENCY:
Section titled “🛠️ ASPECTOS DE CONSISTENCY:”Indentación
Section titled “Indentación”// ✅ Consistente - 4 espaciospublic class Example { private String name;
public void method() { if (condition) { doSomething(); } }}
Espacios alrededor de operadores
Section titled “Espacios alrededor de operadores”// ✅ Consistenteint result = a + b;if (x == y) { }for (int i = 0; i < 10; i++) { }
Llaves (Braces)
Section titled “Llaves (Braces)”// ✅ Consistente - same linepublic void method() { if (condition) { doSomething(); } else { doOtherThing(); }}
Orden de imports
Section titled “Orden de imports”// ✅ Consistente - orden alfabéticoimport java.util.ArrayList;import java.util.List;
import org.springframework.service.Service;
import com.company.domain.User;
Naming conventions
Section titled “Naming conventions”// ✅ Consistentepublic class UserService { // PascalCase para classes private String userName; // camelCase para variables private static final int MAX_RETRY = 3; // UPPER_CASE para constantes
public void processOrder() { } // camelCase para métodos}
🔧 Herramientas para automatiar:
Section titled “🔧 Herramientas para automatiar:”Google Java Style Guide
Section titled “Google Java Style Guide”- IntelliJ
- Descargue el archivo xml: Archivo Xml
- Ingresar a
Settings
- Seleccione
Editor
- Seleccione
Code Style
- Seleccione Java
- Importe el archivo xml
- Aplique los cambios