Monday, August 27, 2007

Links relating to Curl 5.0 as RIA + CSPD

Client-side persistent data or CSPD may be out of favor in the current "I'm OK, stateless's OK" buzz but I like the 'public library' model: I return a book and the only record of my having borrowed it is my own record. Just try to sell that to the Barnes&Noble / Borders / Amazon / BlockBuster / BestBuy / NetFlix "we've got your number crowd". The more radical option is the 'purchase' card whose record does not belong to a bank or credit card conglomerate: I pick the 'bank' for transactions based on interest rate. Talk about competition! Having data 'client-side' need not mean 'local to this box' but rather, "not on your server". On this model your medical records would not be held by doctor PA's, hospitals or insurers. And your privacy could be in much better hands. Ok, I'll give it a REST ...

But my links to Curl which are not links to cURL are slowly coming alive ... and Curl is CSPD friendly. It has not yet seen that client-side 'store' should be opaque to the server, but it may get there. Not middleware. Call it 'periware' and 'exolayer'.
Buy a book at Borders and then go borrow a book at your library. Now make a return at each (don't cheat and read that new book!) Now ask where your medical records belong ( "we know you are in pain, but we need at least 24 hours notice to have your records sent up." I only had to hear it once.)
Having my records at my beck-and-call does not mean that I can 'access' them. It means that I decide who can access them short of a court order. And when. And where. And that is just my medical records.
The fine print on your savings account book may explain that your money is not always available for withdrawal. And in some countries you pay to have an account and fill out forms to make any withdrawal. PayPal is as foreign to those 'service' banks as is client-side data in the current praise for HTTP.
Many years ago, when TCP/IP turned 15, we were asking when the protocol would be replaced altogether. About the same year as we asked 'Is this the year of Unix?' Perhaps the year that I finally see overhead wires go underground, I will see the system of record no longer be the central system, but the peripheral system. Periware. Exolayer. The Exonet, adumbrated. How apposite.

Friday, August 24, 2007

Rebol dialects and Groovy builders

I am working on a blog post over at eclectic-pencil on DSL (domain-specific languages) in Rebol and Groovy. It is an area that the folks at PDC Prolog got into a few years back and that I first explored using Java + Amzi! Prolog with DCG's in Eclipse. I hope to get a piece up on Groovy and categories as mix-ins in comparison to exploring categories and protocols in Logtalk. In the meantime there is a great deal of activity on the SWI-Prolog mailing list often relating to their Java programming interface. And Plone has a new release just as I wait for Rebol3. And I have a new version of the Curl 5.0 Web SDK to check out. And the MindTouch Deki-Wiki up on VMWare as I watch for the Gemstone/S + Seaside beta. Too much!
My opinion of the out-of-print 'Official Guide' to Rebol 2.3 keeps improving: I wish I could say the same of Manning's 'Groovy In Action' or the APress 'Grails' book. Neither of my favorite bookstores had 'Programming Groovy' on the shelves, which might have been a better choice than the former. Of course there is no book on Logtalk to recommend ... yet.

Sunday, August 12, 2007

Documenting a Curl Surge Lab Interface class

Surge Lab had been marketed as the name for the Curl IDE. The IDE has a feature that you may recognize if you use eclipse or Aptana: you can flip from one perspective to another. But the IDE gives only a glimpse of Curl interaction for the developer because, like Smalltalk Seaside 'halos' on a web page, Curl offers a Ctrl-Right-Click which opens text and graphic inspectors on objects embedded in a 'live' web page.

The ctrl-right-click pop-up menu includes viewing and editing the Curl source, inspecting objects and both 'Start Profiling' and 'Start HTTP Monitoring'. (Curl also offers test-coverage tools for HP's Mercury QTP.)

The inspectors are toolbar driven and almost feel like a Smalltalk object inspector becuase one toolbar item is 'Evaluate' which is just like the JavaScript popup in FireFox developer tools. Unfortunately, the inspectors lack some features of a typical Smalltalk inspector. The first that I would add to be Curl-ish would be a 'select-text-F1' event-handler to get the fine Curl doc viewer to popup.

What I will do this morning is include a Curl snippet of what you might browse in such a popup; it demonstatrates how the doc viewer is driven.

The following snippet is copied from

I:\Curl RTE\Surge\6\ide\editor-interface
EditorInterface.scurl
Snippet:
{doc-next
{purpose
This class defines the interface that an editor must support
to be integrated with Surge Lab.
}
{details
An external editor needs to implement this class, and define
a top-level variable named {monospace surge-lab-editor} which
is an instance of its implementation of this class.
}
}
{define-class public open abstract EditorInterface

{doc-next
{purpose
Initialize the editor.  An interface back to Surge
Lab is provided for the editor.
}
}
{method public open abstract {initialize
surge-lab-interface:SurgeLabInterface
}:void
}

The behavior of the default Curl editor is not my favorite side of Curl at the moment: high-lighting a '{' offers a context popup to view the '{' in a class browser instead of the handy behavior when you add a '}' which is to blink the matching '{' in red.
Adding a '}' and then placing a CR in front has the disconcerting behavior of aligning the '}' with the matching '{'. This is annoying if it is your habit to end a line using a 'do' with an opening brace ( as required by many script interpreters such as Tcl and which is {script-style} for many programmers.)

But the little annoyances in the default editor come to nothing because there is an interface for external editors.

Over at eclectic-pencil I will add a page with a working HTML example of an embedded Curl {example} macro using a TreeControl object. Install the plugin and Ctrl-Right-Click. Cool.

Tuesday, August 7, 2007

GRAILS and Groovy tip

If you try out groovy Grails on Windows as an open-source web application framework, I suggest you install it as a sub-directory of your Groovy directory.
You will want to knwo that your groovy is running fine: in my case I added
set CLASSPATH=I:\groovy-1.0\groovy-1.0.jar;%CLASSPATH%
to my groovy-1.0\bin\groovyConsole.bat I also have three ENV variables defined: GROOVY_HOME, GROOVY_JAR and GRAILS_HOME and both HOME var's are in my path with \bin appended to them.

With that done, you can go into the Grails bin and edit the
grails.bat
I think that there is no point avoiding at least this much:
set CLASSPATH=
because even with my own classpath tool it is just too much grief. Grails does not need your classpath but having one is a problem. The top of my grails.bat now reads
REM set groovy_home=I:\groovy-1.0
REM set GRAILS_HOME=%GROOVY_HOME%\grails-0.5.6
REM set path=%groovy_home%\bin;%grails_home%\bin;%PATH%
REM set GROOVY_JAR=groovy-1.0.jar
set classpath=
To test that things are running start in the grails\bin with
grails help
which should run error-free and list the grails commands. From there you should be OK following the Grails Quick Start steps. Until help comes up error-free, you have an issue.

One last tip: Grails will create your web app root directory in the directory you are in at the time you execute
grails create-app
which in my case is running
I:\groovy-1.0\grails-0.5.6\scripts\CreateApp.groovy
so you do not want to be in .\grails\bin on your command line. If you have not installed the Microsoft Power Toy Open Command Window which launches CMD.exe from any folder in the file explorer, you will want to do so ... whether you are using Grails or Rails without an IDE.

RIFE-Jumpstart

RIFE is such a terrific example of using continuations in a web application framework that it is too bad if giving it a try has glitches from the get-go.
The RIFE-Jumpstart will use Jetty so you will want to go into the Jetty subfolder and edit the jetty.xml such that the port value is something other than 8080. After that you will reach RIFE as something like
http://localhost:28282
You simply must confirm that your OS has the JAVA_HOME env variable set to a JDK. I am using RIFE for Java5 so mine set to
i:\java5\jdk
I tried using my own ClassPath tool from LogiqueWerks to get around this by being sure to hit the right tools.jar and javac.exe but I could not escape
class file has wrong version 49.0, should be 48.0
when launching from the RIFE-JUMPSTART directory with
ant run
This also means that you must have ant in your path.
It is annoying that most HTTP frameworks install without politely asking for an alternative to port 8080. OracleXE and SUN Application Server are the latest to do this to me.
There are some good video podcasts on RIFE - one at Google is about an hour long.
If I add some RIFE pages they will be over at eclectic-pencil.com Useful links include rifers.org and a Confluence link on DWR.

Tuesday, July 31, 2007

Windows and the Tea Shell

The Tea shell for the JVM has been available as version 3.2.2 for some months now.

There is no problem running the shell under Windows if you had Tea 3.1.0 up and running.

The first problem is that 3.2.2 includes no TEA.BAT in the tgz file. Just get the old 3.1.0, extract the bat file and update it to suit your install.

Tea must find a GNU jar for regexp and a Xerces jar for XML parsing. I reference them explicitly in a temp CLASSPATH in that BAT, e.g.,
set CLASSPATH=%TEA_BASE_DIR%;%TEA_BASE_DIR%\xerces-1.4.4.jar;%TEA_BASE_DIR%\gnu-regexp-1.0.8.jar;%CLASSPATH%

Tea is intended to bring multi-paradigm programming to the JVM. It is a java-based functional langauge with extensions for procedures and classes. This is another language intended to be component 'glue'. The selling point is that it is in java.

Other multi-paradigm languages either have their own compiler written in C or are using libraries implemented in C. Tea is java so one positive is that you get javadocs. The tea reference javadoc lists about 20 functions as the language core.

As a functional language Tea is intended to make the use of closures easy: functions are first-class objects as in JavaScript. In many respects the object system is like Smalltalk: members are private; methods are public. Code blocks in {} come with their contexts as closures. Every statement is at least a word which invokes a function. Lists are like Smalltalk collections: they can contain objects of mixed types. Unlike JavaScript, there is no literal notation for functions, but they can be loaded at will from jars or from raw source files using the source word.

Variables are not pre-typed, but they must first be declared with a define. The define word is over-loaded 3-fold: define a variable; declare a variable to have a value; define a variable to be a function as declared. The define word returns what it defines (it, too, is a function.) The set! function is used to re-assign a variable and anonymous functions can be had using the lambda function. Much like Smalltalk's collect: there is a map function to iteratively apply a function to a list. For lists of lists there is the function map-apply. Unassigned vars are returned with the value null. But note this sigil use:
define nativeParser $null

The syntax is very simple. Statements end at end-of-line. Comments start with octothorpe. You get variable values with a prefixed $ sigil. Other scripters will feel comfortable. The type tests use function? string? symbol? int? pair? which is extended to boolean tests as same? not-same? null? and not-null?. Lists use parentheses and, thankfully, no commas.

Lists are very much Scheme, as in
define testPair [cons "first" "last"]
where [car $testPair] gives "first and [cdr $testPair] give "last".
List are built from such pairs; the last pair in the list references a pair where both slots are null. With syntactic sugar our test list can be declared as
define testPair ( "first" "last" )

The Smalltalk procedural style is made possible by using the $ sigil.
For example, if you have a database connection in variable conn then
define sqlStmt [$conn statement]
returns a statement. The difference from Smalltalk can be seen when the query is created: there is no need for a colon, as in
define dataSet [$sqlStmt query "SELECT client_id FROM new_customers"]
but what is different is the use of [...] and not as a code-block { expression }. What is happening, of course, is a command substitution as in Tcl. The {} are used to defer evaluation as in a while loop.

The load function is rather like Jython: it gives access to java classes including Tea functions in those java jars.

But why would you use Tea? One possiblity is that you already know Scheme and Tcl or need a rapid way to work with closures in the JVM. But why not simply use JavaScript? One curiousity is that Tea is promoted as a language for rapid-prototyping, but in Lisbon it has been used for major banking and telco systems. But was it used only as glue code? Not at over a million lines according to Tea's own 'whitepaper'.

One observation: Tea is almost the opposite of Curl and Rebol. It is only now adding GUI and networking. But why add them if this is a scripting language for the JVM? It must be irresistable. Some people spoil their kids; some people spoil something else. And most of us seem to bloat if we are not kept on track ... and reminded that what we leave out can be as important as what we put in.

In Tea you get a hint of what the future holds if we shift away from 'C' and the OS to life with a VM.

Likely Tea will never have the momentum to break into North American markets unless it is embraced by a major player. It does have an advantage over Jython: there is no shifting Python beneath it. Then again, functional may becoming fashionable... even at Microsoft.

If you are a secret Schemer masquerading in Java or someone who can't thrive without a little Tcl, you may want to have some Tea... and lemon? Ah, right. They already added the syntactic sugar ...

PS There is another TEA which is the Tiny Encryption Algorithm and yet another Tea that is a strongly-typed templating language for managing servlets from the Disney TeaServlet project at what was once GO.COM Green tea. Black tea. Chá, anyone?

Monday, July 30, 2007

The Zend of PHP

July 2007 saw the release of the 1.00 'production' release of the Zend Framework. To quote:
The Zend Framework project has developed solutions to solve frequent needs of web application developers, including the following areas:

* Powerful MVC framework
* Database access solution that balances ORM with efficiency and simplicity
* Lucene-compatible search engine
* Advanced I18N support
* Robust authentication/authorization classes and input filtering
* Rich web services client interfaces, including Google Data APIs and StrikeIron
* Many other useful classes to make you as productive as possible
* Thorough and high-quality test suites and documentation
* Open-source development process with an active community provides continuous review and testing


One of the many criticisms of PHP as a scripting language for web development is the lack of enforcement of separation of content from logic. Now Zend proposes an MVC framework for PHP.

MVC (Model-View-Controller) is usually associated with Smalltalk and the thick client even before client-server, let alone the web and RIA. MVC used in conjunction with frameworks such as Struts for J2EE is MVC in name only. The concern is this: keeping domain models and business models from being entangled in presentation issues. The web MVC variant is usually called Model 2 MVC. In Smalltalk, the evolution of MVC to Morphic (from Self) or to M/V without controllers (Cincom Smalltalk Widgetry) is a topic in itself. Dolphin Smalltalk has MVP (Model-View-Presenter) and provides a nice introduction at their Object-Arts site.

PHP starts with a bad rap for not having adequate modularity: it still lacks namespaces. Smalltalk itself is evolving to embrace namespaces and away from classic MVC so we have something curious occurring.

Here is what the Zend Framework appears to offer. I quote:
<qt>
Put simply; models contains your domain specific code such as a user class, views contains your templates, or view scripts as they are called, and controllers contains the files that process data to and from the models and views. Following this simple practice not only introduces a design pattern into your programming arsenal, but also organizes your code in a way that makes it more maintainable than a great many existing PHP applications.
</qt>
What we really have here is the front controller pattern that arose in J2EE in frameworks such as Struts where it is combined with a Command pattern.

In terms of security, PHP with the Zend Framework remains a filtering approach. What is not yet clear to me is how this chaining of filters and validators constitutes a framework. A Framework is not just a library of classes and certainly not a cookbook of recipes. A Framework can usually be understood as providing for the interoperation of services identified with components by enforcing constraints. The constraint might be: this service must be presented as an interface (now you are constrained to implement against a minimal abstraction.)

To have a framework it is not enough to have a class library providing a mechanism which removes ? and & from PHP URL's or adding more filtering.

You may want to check out the Zend Framework site with its webinar and demo wiki application. The site also links to manuals for the API and a developer reference. The latter opens on Access Control Lists; scroll down to find Controllers. What is missing is an overview of the framework such as is readily communicated by the Rails folks promoting Ruby. Having the familiar directory structure in itself does not establish 'convention-over-config'.

Perhaps whether you have 'c-over-c' comes down to 'GUI-shootouts', but that sort of thing does not impress architects concerned about security+maintainability. Saying you are using a 'framework' only goes so far. If what you meant is a library of classes that will be familiar to Struts developers, then why not Java with JavaServer Faces with jars, ears and Maven with the Spring 2.0 framework for security? What ties anyone to PHP in a business setting?

PHP has likley gotten to where it is because it posed no steep learning curve. And then it got a bad case of bloat. What results could be called 'wading through muck' rather than 'slogging uphill'. But when I arrive to perform on a maintenance contract, knowing what the framework was and that it was respected means a whole lot. Knowing what libraries were used gives very little indication of what you are in for.