liveBook · Manning

Expressive power

As explained in The Art of Code

The degree to which a programming language enables ideas to be expressed clearly and concisely without unnecessary syntactic or logical manipulation.

Expressive power is the ability to turn an idea into clear, concise code without twisting syntax or stretching logic to force a solution. It is not mere brevity: code is expressive when its intent is easy to grasp, its flow is natural, and its structure stays close to the problem being solved. section 1.1.4 section 5.0

Judge expressiveness by a combination of signals: low cognitive complexity, little incidental code, readability, closeness to the problem, and safety. Fewer lines help only when they preserve understanding; a compact construct that requires readers to reconstruct hidden steps is cryptic rather than expressive. section 5.1 section 5.3

Remove mechanics from a mapping

A traditional Java switch can bury a simple format-to-message mapping under a mutable variable, repeated assignments, break statements, casts, and a final return. It is also fragile: a missing break can silently overwrite the POCKET message. Prefer a construct that makes the cases and their outcomes direct, provided the team can readily read it. section 5.1.1 section 5.0

Listing 5.1 Traditional Java switch over book formats
public String getPromotionalMessage(Book book) 
  throws UnsupportedBookFormatException {
  String message;
  switch (book.getFormat()) {
    case DIGITAL:
      message = ((DigitalBook) book).getDownloadLink(); 
      break;
    case POCKET:
      message = "Same book, smaller format!";
    case HARDCOVER:
      message = "Old-fashioned book…";
      break;
    default:
      throw new UnsupportedBookFormatException(book.getFormat());
  }
  return message;
}

This switch shows how control-flow plumbing and fall-through risk can obscure an otherwise direct mapping. section 5.1.1

Conciseness has a boundary. A method reference may hide parameters; a lambda can expose them; a for-each loop makes iteration and values fully visible. Likewise, dense Kotlin scope-function chains can compress several transformations until the code’s story becomes hard to follow. Choose the least complicated form that remains clear to its intended readers. section 5.2 section 5.2

Use expressive features when they improve the code’s story:

  • Prefer idioms that improve readability, safety, or closeness to the domain, such as pattern matching, switch expressions, records, data classes, sealed types, pipelines, or named constructors. section 5.2
  • Favor widely understood constructs over clever or advanced shorthand when familiarity would otherwise become a reading cost. section 5.2
  • Balance expressiveness with simplicity and narrative code rather than maximizing brevity in isolation. section 1.1 section 5.3

How The Art of Code covers it

How deep it goes
Defines practical evaluation signals and examines Java and Kotlin tradeoffs, while rejecting a universal shortest-form rule.
Examples
Contrasts Java switches, pattern matching, method references, lambdas, for-each loops, and Kotlin scope-function chains.
What it assumes
Assumes experience reading Java and Kotlin idioms while explaining their readability tradeoffs through concrete alternatives.
What you can do after
Evaluate/understand whether a language feature improves readability, safety, and problem closeness rather than only reducing syntax.
How it connects
Connects expressiveness with cognitive complexity, conciseness, readability, safety, simplicity, narrative code, and domain modeling.

Also explained in

Compare how 10 books explain expressive power →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Art of Code. The section links point to the parts of the book it draws on.