1

The cover of the book The Practice of Programming lists programming principles:

  • Simplicity
  • Clarity
  • Generality

Intuitively I understand generality as preferring to solve the general problem rather than the specific form in which the problem presents itself. For example a sort function should be able to sort anything that is comparable instead of just ints. However, that seems like a contrived example.

What are some better examples of generality?

  • What do you find contrived about sorting a Comparable? It's an extremely good illustration of the valuable principle that a method which limits itself to using only some of the functionality of an argument should strive to make that limitation transparent by declaring the most general interface. I literally cannot think of a good reason not to do that. – Kilian Foth Feb 7 at 18:18
  • @KilianFoth I mean contrived because we rarely need to implement sort ourselves. I'm hoping for more real-life practical examples. – StackedCrooked Feb 7 at 18:18
  • @StackedCrooked: why does a good example has to be one which you have to implement by yourself? A generic sort function in your favorite framework is something you just use, and the fact you can use it for all different kinds of data types demonstrates its generality. – Doc Brown Feb 7 at 21:13
  • 2
    ... note also you question is a "list-of-things" question, which is typically seen as too broad by our community. – Doc Brown Feb 7 at 21:17
  • The whole reason why you rarely need to implement sort yourself is because there already exists a general sort function. – Jörg W Mittag Feb 7 at 23:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.