Paul M. Jones

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

Savant Article in PHP-Mag

My article on Savant has been published in the 01.2005 edition of International PHP Magazine. I subtitled it "How I learned to stop using Smarty and love PHP for template markup" (so what if I love old movies?).

In the Development track, Paul Jones elaborates on how he learned to stop using Smarty and love PHP for template markup. He holds forth on Savant, a lightweight, object-oriented, fast and powerful solution that leverages the power of PHP markup with the convenience of plugins and path management -- all without compiling.


"The Mission" by Dana Priest

Dana Priest is (was?) a reporter for the Washington Post; I understand that she was the military and intelligence reporter for that paper. In "The Mission" she details several recent military missions from Kosovo to Kandahar, gives biographies on military personnel from top General officers to infantry grunts, and describes the daily lives of soldiers and special forces operators while in training and while in the field.

Among other things, she points out that the State Department has (de facto) abdicated to the military much of State's responsibility for creating and communicating foreign policy. Military personnel are used as ambassadors and diplomats, and are given broad authority to accomplish ill-defined non-military goals.

I have heard her speak via C-SPAN and other programs; her stand appears to be that we need a civilian "nation-building" (or "re-building") department to help nations get back on their feet after our military goes in (for whatever reason, from peacekeeping in Bosnia to ouster in Iraq). She believes that the military is not suited for what are essentially civilian tasks: policing, hospital building, water supply, electricity production, economic invigoration, and so on. We must remember that the military is a tool for destruction, and ever more for selective and precise destruction, not for construction. For example, see her chapters on the soldier who murdered an 11-year-old Albanian girl; it is a true story, and while representative of a vanishingly small minority of military personnel, it serves well as analogy as to why military training and culture (which is good and necessary for military purposes) do not translate well into civilian activities under military sponsorship.

I find that I agree with Ms Priest. In a way, her work ties in nicely with Thomas Barnett's NewRuleSets ideas: the military needs to be able to kill people and destroy materiel, but then we need a civilian counterpart corps to rebuild what earlier tyrants have destroyed or prevented from being built in the first place.

Note: The idea of having this rebuilding corps is **not** a way of saying "the US needs to fix what it breaks after invasion" (even though we do). For example, don't tell me that the USA decimated Iraq as a whole, because it's not true; Saddam did more to damage the people of that country in 30 years than we are capable of conceiving. This hypothetical civilian rebuilding corps would help get the people on their feet (after we militarily remove the tyrants who drove the people down) by building or improving existing institutions and organzations and services.


Toward a Secure Compiler for Savant

Savant uses PHP for its template markup, but also supports extneral compilers. Unfortunately, the example compiler in the distro is not that secure.

But! Joshua Eichorn has put together a spiffy PHP code analysis tool called PHPCodeAnalyzer. It takes PHP code, runs the PHP tokenizer on it, and reports back what functions, methods, etc. are present in the code. This could serve as a basis for a secure compiler for Savant, which in turn might be the tipping point for RevJim.

(Reverend, if you're reading, I'd be very happy to hear your comments on this).


Code Tests As Code Tutorials

Early in the development of Savant (back when it was HTML_Template_Dummy) I broke the assign() method without knowing it, then distributed the source to early adopter testers. Of course, they discovered the break right away. Embarrassed, I wrote up a quick series of "visual" test scripts to run on each release. They are not automated; basically, they instantiate Savant and print out the results of various method calls, which I then eyeball to look for problems. While not optimal, and certianly not "best practice," it's good enough most of the time.

However, such "eyeball" tests seem to have an unexpected benefit. I just got a comment from Alex at Sourcelibre saying:

In version 2.3.2, the directory ... Savant2/tests are really usefull. I almost always prefer examples to explanations, and these examples are just perfect.

Well look at that. I wrote up code examples and I didn't even know it. While it's not documentation per se, it appears to add a lot of value to the package.

So now there's at least one more reason to write non-automated tests for your libraries: if the tests are designed to be human readable, not machine readable, then they can serve the purpose of testing **and** tutorial.


Damn Deserters

Via Instapundit, from L. T. Smash:

But let's put your personal considerations aside for the moment. After all, a martyr cares nothing for his own life. That is how you see yourself, isn't it?

When you were planning your dramatic "statement," did you think for a minute about how this would affect your shipmates? You are a fire control technician on the Sea Sparrow surface-to-air missile system. The Navy doesn't have a bunch of spare FCs sitting in cold storage. Your ship is going to the Arabian Gulf, and will have to pass through the "threat arcs" of Iran's Silkworm anti-ship missiles -- and in case you haven't noticed, we're not exactly buddy-buddy with the mullahs these days. The Sea Sparrow is a critical point-defense system for your ship. So your job isn't one that the Navy can afford to shrug off -- somebody else is going to have to do it.

One of two things is going to happen. Either your shipmates are going to have to pull extra shifts to cover for your absence, or -- more likely -- somebody from another ship is going to get emergency orders to take your place in the coming days. Maybe that person is married; maybe he even has kids.

And you pulled this little stunt just in time for Christmas.

When I was in Desert Shield / Desert Storm in 1990, we saw all sorts of this kind of behavior. Kids who signed up into the reserves were called to duty per their contract, and responded with "You mean I have to fight? I thought you were just giving me free money for college!"

They did whatever they could to avoid deploying to Saudi. The level of conscientious objectorship went up significantly in about two weeks, as did the pregnanacy rate among females both at home and in-theater (if you got pregnant, especially on a ship at sea, you got sent home) over the next six months.

Cowards and freeloaders the lot of them. No sense of duty, no sense of honor, no sense of commitment. They were happy to take the goods, but actively avoided returning their service. >:-


Savant 2.3.2 released

Savant sees a new release today, version 2.3.2. It's a bugfix release; the change notes are:

* can now use assign() to assign a null value by name (thanks, Michael Caplan)

* the dateformat plugin now correctly refers to named custom formats (thanks, maxim at inform-link dot co dot uk)

* added tests for named custom dateformat strings

In related news, it seems that Monte Ohrt (or someone using his name) of Smarty fame wanted to take issue with some of my comments about caching over at the house of Reverend Jim. Give Jim some traffic and see for yourself which point of view you agree with; when you're done, be sure to check out his photography work.

Finally, the Savant site has seen quadruple its normal traffic in the past 24 hours. Normally it gets about 1000 hits/day, but right now it's at 4000. Could it be that my new article for PHP Magazine on Savant has been released?

Savant is a template system for PHP that uses PHP itself as the template markup language. Savant has plugins, output filters, customized error handling, and allows you to hook in a compiler object to deal with customized non-PHP template markup. I call it the simple, elegant, and powerful alternative to Smarty.

Update: Looks like SitePoint Tech Times has a link to Savant, which explains the traffic increase. Thanks to Sean from #pear on IRC for the information, and thanks to the SitePoint folks for mentioning the project.

Update 2: At midnight: 6763 hits in 24 hours. Sweet. :-)



DB_Table: Pre-Defined Per-Query Fetchmodes

Ian Eure just provided a patch to DB_Table that is genius in its simplicity. While I have not tested it, the patch looks like it will cause no trouble. In short, in your predefined SQL queries, you can specify that the query should return in DB_FETCHMODE_ASSOC, DB_FETCHMODE_ORDERED, or any other fetchmode. For example:


// predefined query for a list of all rows
$this->sql['list'] = array(
    'select'    => '*',
    'from'      => $this->table,
    'order'     => 'some_column DESC',
    'get'       => 'all',
    'fetchmode' => DB_FETCHMODE_ASSOC
);

// predefined query for a single row
$this->sql['item'] = array(
    'select'    => '*',
    'from'      => $this->table,
    'get'       => 'row',
    'fetchmode' => DB_FETCHMODE_OBJECT,
    'fetchmode_object_class' => 'myDataObjectClass'
);

With that, you can call $dbTable->select('list') and get an array of rows, or call $dbTable->select('item', "id = '9'") and get an object of type myDataObjectClass.

This is only in CVS right now, as I'm trying to add various Oracle restrictions to DB_Table, but it was just too neat to not add in right away. Thanks, Ian Eure.

DB_Table is a PHP class to automatically create RDBMS tables and XHTML forms. It includes a "poor man's" data type abstraction wherein the database is forced to store date and time data in ISO formats, which means you do not need to do date/time magic on your queries before executing them (and you don't need to do magic on the return results, either).


Paying for Performance

The inestimable Rum Smuggler contacted me via private channels to point out Paying for Performance from the Marginal Revolution.

Every three weeks students are tested and if they improve they are paid on the order of $20.  Control groups are also tested.  Early results are very encouraging.  No other reform has anywhere near the bang for the buck as paying the students.

But that's ... that's so **easy**! Instead of paying the monopolist government school bureaucrats more, pay the kids.

Whiny nosy Mrs Grundy sniffs, "Outrageous; they should they learn for the joy of learning." In a perfect world, that's true -- but they must be taught the long-term joy with short-term rewards. If we must coax the thirsty to water with gold, then we will quench their thirst just as surely as if we had browbeaten them toward it with "it's for your own good, you'll thank me later" ... and maybe with more success.


Americans for Fair Tax

Visit the Americans for Fair Tax site right now. It's essentially a 24% national sales tax with a very high "deductible" (effectively, you don't have to pay it if you are at or below poverty level). Here's a thumbnail sketch:

The FairTax is a federal retail sales tax that replaces the entire federal income and Social Security tax systems, including personal, gift, estate, capital gains, alternative minimum, Social Security/Medicare, self-employment, and corporate taxes. The FairTax allows Americans to keep 100 percent of their paychecks (minus any state income taxes), ends corporate taxes and compliance costs hidden in the retail cost of goods and services, and fully funds the federal government while fulfilling the promise of Social Security and Medicare.

But what about the poor? They fare better under the Fair Tax than they do under the current system. Seriously. Read it and sign up.