Reading for lazy people*.

Clean Code

A Handbook of Agile Software Craftmanship

*people who lie they have no time for reading

Robert C.  Martin wants YOU to write CLEAN code

Chapter 1.

Meaningful names

Use Intention-Revealing Names

const d; // elapsed time in days

const elapsedTimeInDays;
const daysSinceCreation;

Avoid Disinformation

const accountList;
const accounts;

only when it's actually List structure.

const XYZControllerForEfficientHandlingOfString;
const XYZControllerForEfficientStorageOfString;
int a = 1;
if ( O === l)
    a = 01;
else 
    l = 01;

Use Pronounceable Names

class DtaRcrd102 {
    statis genymdhms;
    statis modymdhms;
}

Use Searchable Names

for (const j = 0; i < 42; j++) {
    sum += (t[j] * 4) / 5;
}

Interfaces and Implementations

IShapeFactory -> ShapeFactory
ShapeFactoryImp / CShapeFactory

Avoid Mental Mapping

Smart people sometimes like to show off their smarts by demonstrating their mental juggling abilities.

Example

const r*;

*the lower-case version of URL with host and scheme removed

Class Names

Prefer noun and noun phrases like

Customer, WikiPage, Account, AddressParser

Avoid words like

Calculate, Visit, Parse

Method Names

Prefer verb and verb phrases like

postPayment, deletePage,  set*, get*, is*

Don't Be Cute

eatMyShorts() === abort()

Don't Pun

Follow the "one word per concept" rule.

Use CS Names.

Don't Add Gratuitous Context

"Gas Station Deluxe"

const GSDAccountAddress;

Chapter 2.1*

Functions

*chapter 2.2 should probably be next time

Small!

Rule 2

SMALLER!

Pro Tip:

Try to write code on small screen (like 13-15') with 20pt font.

Do One Thing

FUNCTIONS SHOULD DO ONE THING.

 

THEY SHOULD DO IT WELL.

 

THEY SHOULD DO IT ONLY.

To be continued...

Next episodes

  • Functions 2.2
  • Comments
  • Formatting
  • Objects and Data Structures
  • Classes
  • and many many more...

Stay tuned

and

make code clean again

Let's make code clean again pt.1

By Mark Orel

Let's make code clean again pt.1

  • 2,540