More Beautiful Code

693 dollar 1993 Ford Taurus

You can read that and probably have a good idea of what I mean. It isn't the greatest code in the world, but it is declaring an object you can probably picture in your head, rusted bodywork, dented fender, bumper stickers, pale teal paint job and all. You don't need any additional information to determine what class it belongs to, car, and are pretty familiar with its publicly defined APIs: steering wheel, stick or automatic, gas pedal, break.

((693 dollar) (1993 (Ford (Taurus)))) -> a (car)

That's probably along the lines of how you'd likely parse it as some form of syntax tree, to transform it into something more manageable. If you were thinking of it in terms of Smalltalk, this would represent a absolutely horrific extension on the basic numeric classes. If you were to make the modifications to those classes though your code would more likely look something like:

693 dollar: ((1993 Ford) Taurus)

Where dollar: would take an object, and associate it with the value 693. Ford would be a constructor which would generate a Car object with the model year of 1993, and the Taurus method would merely specify the internal make member variable. If one were writing an application that talked about a wide variety of cars in these terms, making these sorts of modifications to the basic Number classes would make some sense.

(a Ford Taurus) vs. (the Ford Taurus)

Take this formulation for example. Let's say we have two global objects called a and the which happen to have the exact same set of methods defined. In both cases, we define a method Ford which will generate an object which will represent something made by Ford. We could similarly add methods to generate Chevy, Bugatti, Jaguar, Bentley, and Triumph, with much the same effect, all producing various on the base Car class of objects. What differs between these two idioms however, is that one uses the indefinite article -- a and the other uses the definite article -- the.

a Ford Taurus -> a pointer to an instance of the class of Ford Taurus objects

In this example, we use the indefinite nature of the word a to indicate that all of its methods return a pointer to an instance variable, of a class determined by the method invocation. In English, the indefinite article indicates that some member of the class is being referred to, not necessarily a specific instance. When I mention, a book, or a car, you are more concerned with that the object I'm talking about fills a given role, rather than which particular object it might be.

the Ford Taurus -> a pointer to a global static singluar instance of Ford Taurus

Other times, we can use the word the to specify a specific object, such as the categorial example, or the example referenced in the current context or scope. Objects representing the Mouse, the Keyboard, and the Screen or even the Page, are all good cadidates for a singular global entity which may referred to in a wide variety of scopes, but contextually are all the same object.

semantics of use > semantics of implementation

How we allow the language we use everyday to inform our design decisions directly determines the maintainability of our code. Or in other words, the semantics of use should take higher precedence over the semantics of implementation. When you read someone's code, the question you will most often ask your self is "what does this code do", not the less relevant "how does this code do it". Information hiding, does not mean we obscure the intent of the programmer behind structure and naming, but rather we allow the reader to focus on the semantics of use, the what. If one is working with a blackbox one is only focused on the what. When you are programming on a framework that you can not change, the how of the framework is immaterial. And if you are designing a framework for other people's consumption, then you owe it to them to think about your APIs on your user's terms.