Naming Things

Neil Ernst/

2025-09-04

An example

public void paint (Paint paint) {

    v = v + paint.getV(); //after mixing, sum volume
   //complex color mixing logic 
   // assign new r, b, y values
}

Unhelpful, written for the implementer

public void testPaint() {
     Paint yellow = new Paint(100.0, 0, 50, 0);
     Paint blue = new Paint(100.0, 0,0,50);
     yellow.paint(blue);
     //should get green with 200.0
}

Better - write from interface user point of view

public void betterTestPaint() {
     Paint ourPaint = new Paint(100.0, 0, 50, 0);
     Paint blue = new Paint(100.0, 0,0,50);
     ourPaint.mixin(blue);
     //should get green with 200.0
     assertEquals(200.0, ourPaint.getVolume(), 0.01);
}

Improved class naming

width:200px =====> width:200px

width:700px

One more refactoring

width:700px

//in Paint 
public void mixIn(Paint other) {
    volume = volume + other.getVolume();
    double ratio = other.getVolume()
    pigmentColor = pigmentColor.mixedWith(other.pigmentColor(), ratio);
}
///in PigmentColor
  // many lines of color-mixing logic