Paul M. Jones

Don't listen to the crowd, they say "jump."

On Being Right; or, Cassandra Didn't Get Half The Kicking Around She Deserved

First, you will discover that people in general are extremely reluctant to admit error. People will defend an opinion or an action until the end, even if every bit of logic and evidence runs contrary. Sincere apologies and genuine admissions of error and wrongdoing are the rarest things in this world. There is no point at all in demanding apologies or in becoming resentful when they fail to appear. Just move on. Neither should you expect to always be rewarded for being right. On the contrary, people will often resent you and try to take you down.

Via Tucker on the Young Unemployed, David Henderson | EconLog | Library of Economics and Liberty (and the subtitle is via R. A. Heinlein).


5 Years Of PHP-FIG

A nice note from Brett Bieber:

Five years ago today, a group of PHP framework thought leaders came together to discuss interoperability and coordination. We met in a small room, talked our issues out together, agreed and disagreed respectfully.

At the time we were labeling our cause: "PHP Standards and Best Practices for PHP 5.3+ Frameworks and Libraries"

For better or worse, the group has evolved since then, but my hope is for continued success and interoperability.

Congrats to all the members, new and old.

Via the PHP-FIG Google Group.


Stephan Hochdörfer and Action-Domain-Responder

I've been asking for feedback on the Action-Domain-Responder pattern, a refinement of MVC, to discover how it's being used in the wild already, and to solicit criticism of the pattern to find weak points.

The key points of Action-Domain-Responder:

  • Instead of a controller class with many action methods, each Action is its own class (or closure, like with Slim).

  • The Action interacts with the Domain (model), and feeds data to a Responder (view).

  • The Responder is entirely responsible for building the response, including all headers as well as the body of the response. This means that in ADR, the template is not the view; the response is the view.

Stephan Höchdorfer has been using single-Action classes for a while now. Here is my summary of his article:

  • "we are using action classes in our application framework for almost the last decade"

  • "action classes tend to be rather small, typically less than 100 loc for us"

  • "another bonus point for action classes: It is easier to search for a class name than a method name"

  • "Controllers tend to have a lot of dependencies. ... people came up with a few "creative" solutions for this problem, mainly the creation of lazly loaded dependencies"

  • "action classes depend on what they really needed. Typically that's just a few services for a single action. Again that makes the code way easier to understand and easier to test."

  • "Action classes in contrast to controller classes can be reusable."

Those were the highlights for me; you should read the whole essay to find your own: http://blog.bitexpert.de/blog/controller-classes-vs.-action-classes

In addition, please write up your own commands and criticism regarding Action-Domain-Responder, so that I can improve the offering as much as possible.



The Eternal Struggle Between Business and Programmers

The Business and the Programmers want the same thing. They want the same thing: to deliver a more predictable stream of important features that will make the market happy--or, at least, knowing the fickle market, that will risk disappointing them the least.

This. Is. Glorious.

The Business and the Programmers needs to agree on two things, each conceding a key point to the other. The Business needs to agree that the Programmers have heretofore gone more quickly than they really can, that they cannot sustain this pace, and that to do so merely hastens the ultimate decline of the entire product line, and perhaps the company. The Programmers need to agree that the Business has a legitimate need to deliver more features, that everyone’s livelihood depends on this, and that trying to ask for more than the Programmers can deliver forms part of the Business’s “job”, as it were. The market compels them to do this. In this equation, the Programmers have the responsibility to do whatever they can to maximise their ongoing delivery speed, and that includes regular, agreessive refactoring.

Finally, both the Business and the Programmers have to agree that they have wasted too much time arguing about this and need to move forward. They want the same thing! They can have it!

via The Eternal Struggle Between Business and Programmers - The Code Whisperer.


Aura.View and Aura.Html 2.0.0-beta1 Released!

Aura.View 2.0.0-beta1 is a reduced implementation of the v1 View package. ...

The templates can still be include files, but (and this is new) they can also be closures. This means that you can completely avoid the file system for templates if you like. ...

There are no longer any escapers or helpers included, although the package does include a bare-bones HelperRegistry so you can add your own callables as helpers.

...

Aura.Html 2.0.0-beta1 contains a collection of helpers extracted from the v1 Aura.View package. These helpers are completely standalone and are not dependent on any particular view system: instantiate a HelperLocator from the Aura.Html package and you can use the helpers from any PHP code. ...

All of the HTML5 input types are supported. This makes building form elements very easy, especially since the data structure for each element is just an array. Any library that can generate the recognized array structure can be used to feed the form input helpers. ...

In addition, [Aura.Html] includes a powerful escaping mechanism derived from ZendEscaper and modified for conceptual integrity with the rest of Aura. The Aura.Html Escaper exposes static methods to make escaping as non-verbose as possible.

Read the whole thing at http://auraphp.com/blog/2014/05/15/view-html-2beta1/!


Quick Hits: ADR Pattern Progress, MLAPHP Softcover, Aura Notices

Just some short updates today, since last week was so very busy:

1. The "Action-Domain-Responder" (née "Action-Domain-Response") refinement of the MVC pattern has received some positive criticism and attention. In addition to example code updates, I have added responses (heh) to critiques regarding the Resource-Method-Representation pattern, and will soon be adding a response regarding "Entity-Interactor-Boundary" (aka "Entity-Contol-Boundary"). Many thanks to the commenters who recognized that they were already doing something along the lines of ADR; this helps to validate the pattern as something that already occurs "in the wild." If you like the pattern offering, please star it at Github.

2. Modernizing Legacy Applications in PHP is now available for purchase in softcover via Lulu.com.

3. It looks like the next two Aura v2 releases will be Aura.View (the view system, specifically the "reduced" branch) and Aura.Html (the HTML helper collection that can be used by any view system). I've done a lot of work on them in the past few days and they're beginning to feel like they're ready.

Cheers all!



We Are All Scientists

Science is not a degree, or a paying job, or even (as many mistakenly believe, and sadly how it’s too often taught in school) a compendium of accumulated knowledge, but a way of thinking and learning about how the physical world works.

Science is a process: observe a phenomenon, form a theory about why it occurred, test the theory with an experiment or other observation, see it fail (in which case a new theory is required) or continue to believe it until a test of it fails. Anyone who survives in life does it every day.

via PJ Media » We Are All Scientists.


"There's no 'win' and no 'fail', there's only 'make'. If you work, it will lead to something."

RULE ONE: Find a place you trust, and then try trusting it for a while.

RULE TWO: General duties of a student: Pull everything out of your teacher; pull everything out of your fellow students.

RULE THREE: General duties of a teacher: Pull everything out of your students.

RULE FOUR: Consider everything an experiment.

RULE FIVE: Be self-disciplined: this means finding someone wise or smart and choosing to follow them. To be disciplined is to follow in a good way. To be self-disciplined is to follow in a better way.

RULE SIX: Nothing is a mistake. There’s no win and no fail, there’s only make.

RULE SEVEN: The only rule is work. If you work it will lead to something. It’s the people who do all of the work all of the time who eventually catch on to things.

RULE EIGHT: Don’t try to create and analyze at the same time. They’re different processes.

RULE NINE: Be happy whenever you can manage it. Enjoy yourself. It’s lighter than you think.

RULE TEN: We’re breaking all the rules. Even our own rules. And how do we do that? By leaving plenty of room for X quantities.

HINTS: Always be around. Come or go to everything. Always go to classes. Read anything you can get your hands on. Look at movies carefully, often. Save everything. It might come in handy later.

via 10 Rules for Students and Teachers Popularized by John Cage - Open Culture.


Some Rules For Good Naming

This Grumpy Programmer mailing-list essay got me thinking:

There is one point of contention I have with Laravel -- some of the naming conventions that have causes numerous Twitter flame wars and blog posts. I speak, of course, about facades. ... [T]he facade thing is a warning to remain vigilant and do your research into what everyone else calls something. Common vocabulary is critical when it comes time to solve difficult problems.

I completely agree with the emphasis on using a common vocabulary. One issue here is that naming things properly is very, very hard. It is one of the only two hard problems in programming.

Are there any rules (even rules-of-thumb) that can we use to make it easier to pick good names for the classes and concepts in our projects?

What's In A Name?

Above all, a good name makes it obvious what we are describing. It provides clarity by itself without the need for further explanation.

However, because a word can be ambiguous, we have to pick the proper context for the use of a name. Using the right context when picking a name is paramount.

Unfortunately, in programming, there may be overlapping contexts. Giving a name to a domain class or concept can be especially difficult because of this overlap. Do we name an element for what the domain experts call it in their normal day-to-day work, or for its layer in the overall system, or for the pattern of its design?

Not A Novel Context

The first thing we have to remember, then, is that we are not writing a novel in English. Instead, we are writing software instructions. We are writing these instructions in something other than a normal human language. We are writing these instructions for a computer, and simultaneously writing them for human readers of that programming language.

With that in mind, I suggest the following order of priority for picking the proper context for a name:

  1. First is the vocabulary, common idioms, and core resources of the programming language itself. If the language itself, its core classes and methods, or the common expressions of its professional programmers associate particular vocabulary words with a concept, activity, or behavior, we should choose from among those words first when attempting to pick a name.

  2. Second is the vocabulary and common idioms related to previously identified patterns of software design. If there is a software design pattern that matches the concept we are trying to express, its name should be our next-best choice.

  3. Third is the vocabulary, idioms, jargon, and slang related to the domain. If there is no appropriate word from the programming language, and no relevant software design pattern, then falling back to the domain for the naming context is our next priority.

  4. The absolute last context should be words from normal everyday interactions. We use these words only after exhausting the other three contextual options. This is the least-appropriate context for picking a name.

This priority order is probably the opposite of what many would prefer. As human beings, we are more fluent and familiar with the vocabulary of our everyday writing and speech. It took many years of hard work to acquire that vocabulary in the first place, and we are unwilling to do additional hard work to acquire yet another vocabulary that applies more appropriately the context of programming. We would prefer to reuse the words we already know, instead of learning how to apply new words.

Even so, to be good at communicating the concepts of software programming to other programmers, it is incumbent upon us as professionals to expand our vocabulary. We must learn these new terms and their proper use. This is especially difficult with patterns of software development.

Patterns Are Defined By Behavior

When it comes to patterns, we have to remember that the patterns themselves pre-exist their names. The names were applied only after seeing the same patterns over and over again in many different programs. This means that it is the behavior of a construct that determines what its appropriate pattern-related name should be. If we write code like this ...

<?php
class Foo
{
    public function newInstance($bar)
    {
        return new $bar;
    }
}
?>

... and we never mention the word "factory", the code is still representative of the Factory pattern. A rose by any other name may smell as sweet, but if we call it a daisy then nobody will be able to guess that it has thorns. Similarly, a "factory" by any other name still creates and returns objects. Calling the above construct anything other than "factory" (or a factory-related name) removes clarity instead of providing it.

Picking The Closest Pattern

As a related issue, it's not enough to look through pattern definitions and find one that is "close enough." We must find the best one we can that matches the most parts of the concept we are trying to express in a name. This can be a lot of effort.

By analogy, we should not call a "motorcycle" a "bicycle" and expect to be understood fully. Yes, a "motorcycle" matches up with a "bicycle" in important ways: they both have two wheels, we steer and brake with our hands instead of our feet, we sit on a seat above the frame, and so on.

But for all their similarities, they are clearly different things. Better to call a motorcycle by its proper name so that we impart better understanding. Likewise, better to call something a Proxy instead of a Facade when appropriate.

Avoid Claiming A Special Context

When picking a context for a name, it is very tempting to define our own special context that lets us pick a name we prefer, perhaps for marketing or other non-technical reasons. We need to avoid this temptation.

Imagine if General Motors, in its marketing materials, called a "Kia" a "Maserati" and went on to describe its offerings in terms of its so-called Maserati. Such a description would make no sense in the wider world of automobile manufacture. Calling a "Kia" a "Maserati" while "in the context of GM" is symptomatic of the Humpty-Dumpty rationale:

"When I use a word," Humpty Dumpty said, in a rather scornful tone, "it means just what I choose it to mean -- neither more nor less." "The question is," said Alice, "whether you can make words mean so many different things." "The question is," said Humpty Dumpty, "which is to be master -- that's all."

Claiming your own special context adds a layer of unnecessary obfuscation and cognitive friction. It removes clarity in naming.

Summary

In summary, I opine that these are the guidelines we need to keep in mind when picking names:

  • We are writing software instructions, not prose or poetry.

  • Pick from existing names that provide clarity within the appropriate context.

  • The order of priority for the appropriate context is: programming language, software patterns, domain terms, and finally everyday speech.

  • When using a pattern name, find the best match, not one that is merely close-enough.

  • Avoid claiming a special context for names so that you can make them mean what you want, instead of what they mean within a more widely shared context.


UPDATE: Some commenters from the Laravel community are being, shall we say, uncivil in their statements. Comments that are not civil, polite, respectful, and on-topic will be deleted out of hand. I reserve the right to further police comments as I see fit.