Clear Code
  • Introduction
    • About This Book
    • Timeline
    • Software Killers
    • Billion Dollar Mistakes
    • Clear Code Overview
    • Clear Code Rules
  • Data Processing
    • Separate Data Collection And Processing
    • Create Data Models
    • Separate Use Cases
    • Data Should Be Immutable
  • Examples
    • Separate Use Cases With Data Model
  • Maintenance Cost
    • Consider the Maintenance Cost
    • The Software Exists In Time
    • Don't Feed the Monsters
  • OOP
    • Separate Data And Procedures
    • Do Not Use Inheritance
    • When To Avoid Inheritance?
    • What Is The Problem With Abstract Frameworks?
  • VARIOUS
    • The Real Single Responsibility Principle
    • The problem with Clean Code's name
    • How To Handle Warnings
    • Do Not Create Constant Collection Classes
  • Externals
    • Links
    • Quotes
    • Funny
  • Technology
    • Git Tutorials
  • Clean Code
    • Clean Code Introduction
      • Origin & Overview
      • Advanced
      • Typical Issues
    • Clean Code Outline
      • Why Clean Code?
      • Clean Code
      • Clean Code Approaches
      • Specification & Design
      • Duplication
      • Refinement & Refactoring
      • Conventions
      • Names
      • Types
      • Methods
      • Nulls and Validity Checks
      • Comments
      • Dead Code
      • Error Handling
      • Classes
      • Code Formatting
      • Unit Tests
      • Special Cases
      • Object Oriented Programming
      • General Code Smells
    • Clean Code Links
    • Clean Code TOC
    • Effective Java TOC
Powered by GitBook
On this page
  • Rules
  • Vertical
  • Horizontal
  • Blocks
  • Good practices

Was this helpful?

  1. Clean Code
  2. Clean Code Outline

Code Formatting

Rules

  • Increases readability and expressiveness

  • Put close to each other what belongs together

Vertical

  • Member variable declarations at the top of the class

  • Local variable declarations prior to their usage - not at the top of the block

  • Use empty lines - but only one

  • Write in order of execution and calls

  • Write similar methods close to each other

Horizontal

  • Limit line length - 100-120 characters

  • The reader should not scroll to the right

  • Use white space

  • Use correct indentation

  • Do not use tabular formatting

Blocks

  • Always put braces

  • Always put braces for empty blocks too

Good practices

  • Agree on formatting in project

  • Use your IDE's capabilities - default is often good

  • Break long expressions into more lines

  • Do not deviate too much from Java Code Conventions (Sun, 1997)

Last updated 5 years ago

Was this helpful?