|
NetKernel News Volume 4 Issue 18
July 19th 2013
Repository Updates
There are no updates this week. Everyone's gone to the beach.
Tips n Tricks - Rewrite Pattern, Active Grammar
I had the pleasure this week of spending some time with Gary Sole at Findlaw.com. During the course of this work a couple of tricks I used were new to Gary. So maybe they'll also be new to you.
How to use the Mapper as a Request Rewriter
Those of you who remember back to NK3 will recall that the module provided a <rewrite> tag that would use a regex pattern to allow arbirtrary request identifier rewriting. With NK4/5 we introduced the general standard module and with it we provided the built-in <mapper> endpoint.
The mapper is much more general and, since it supports declarative grammars mapped to declarative requests, it is much less error prone than write-once read-never regex rewrites.
We implemented it as an overlay so that the mapping had a clear spacial target scope into which the new declarative request would be issued. This keeps the architecture clean and prevents the recursive complexities that used to appear in the old days, with the consequent double escaping hell that could arise.
However, Gary had a use case that simply wanted a basic rewrite, and lamented that the old NK3 <rewrite> wasn't there anymore. Fortunately, I was able to show a simple pattern which is 100% equivalent to the <rewrite> but with the advantages of the clean declarative style.
To rewrite a request, simply use the mapper using the declarative request's argument substitution syntax [[arg:foo]] to "cut and paste" the grammar-matched parts of the first identifier into the second.
<mapper>
<config>
<endpoint>
<grammar>
<simple>res:/{root:(foo|baa)}/{service}/{path}</simple>
</grammar>
<request>
<identifier>res:/[[arg:service]]/[[arg:path]]</identifier>
</request>
</endpoint>
</config>
<space />
</mapper>
</rootspace>
Keeping the target <space> empty means that the request is mapped (rewritten) and immediately starts resolving in the same rootspace as the original request. If you need more than one rewrite, add more mappings to the mapper.
Here I've shown a <simple> grammar, since that was the use-case Gary had. But of course you can use any grammar all the way up to the full expressive power of a standard grammar - which, with its <interleave> and <option>, provides a power-rewrite far beyond the reach of the old rewrite's regex.
Active Grammar with Overloaded Base Identifier
Another thing that turned up is this...
<accessor>
<grammar>
<active>
<identifier>active:FooLegacy</identifier>
<identifier>active:FooNew</identifier>
<identifier>active:FooNewest</identifier>
<argument name="operand" />
</active>
</grammar>
<class>my.org.SomeAccessor</class>
</accessor>
</rootspace>
The active grammar allows you to specify multiple base identifiers on a single grammar. So, for example, you can maintain an old version, retaining its legacy identity, whilst also offering a new version.
Handling modes can be done inside the accessor by looking at the value of the "activeType" argument...
String base=context.getThisRequest().getArgumentValue("activeType");
With the example grammar above, the base string would be one of "FooLegacy", "FooNew" or "FooNewest".
On Empiricism - Part 2
Last week's story was a thinly veiled parable. It was an attempt to present a reflected view of a real historical progression. The progression away from Empricism. A convulsion which the intellectual world was shocked into making during the first half of the twentieth century.
Ultimately, I want this to provide a context in which to consider our world of Information Technology. But, as you will see, its vital for our conversation to have a general sense of the Progression from Empiricism.
This is my, admittedly, personalized perspective...
17th and 18th Century
Empiricism really got going at the turn of the 17th and 18th centuries, although the ground work was laid a century earlier with the Copernican revolution, Galileo, and the advance of Science as a formalized process of exploring and rationalising our interactions with the world.
Towards the end of the 17th century it was beginning to seem like every area of endeavour could be rationalised and, with enough understanding of the process, be described by a prescriptive set of rules.
The world appeared to run like clockwork.
Even the stars were uniform, predictable, and it was a booming business to build elaborate clockwork orrery, in order, literally, to encapsulate the workings of the universe in clockwork.
The icing on the Empirical cake was delivered by Isaac Newton.
Newton is best known for his unifying explanation of the motion of the planets with the discovery and formal description of the Theory of Gravity. Today, we kind of take this for granted, but this idea was brand new - it unified, simplified and revolutionised everything. It was shockingly elegant.
It was also beautifully in step with the Empirical description of the world.
Here was a set of equations upon which it appeared the whole world revolved. Fire a canonball at such and such a speed, and such and such an angle, and it will land at such and such a point. (Ballistics and modern warfare got one hell of a kickstart from Newton).
There are great men, and there are Great Men. Newton goes in the second bracket.
People don't generally appreciate that Newton was not a one trick pony. He didn't just smash apart our world view with gravity. He did it twice. He developed and presented the first Theory of Light and Optics.
Before Newton, people didn't really know what light was. For example, it was an acceptable belief that it was something which was emitted from the eye.
Newton showed that light is a wave. That it can be separated into its spectrum and that individual colours are indivisible. He showed that light waves would interfere to make predictable and precise patterns (like ripples on a pond). He showed how light could be harnessed and turned into a precision tool.
Newton was adding cherries to the icing on the Empirical cake.
Light, gravity (not to mention he and Liebnitz's discovery of calculus) were obviously the precise, predictable, orderly rules. Everything else followed and any problem could be solved by a suitable mechanised approach.
19th and turn of the 20th Century
If the 18th century was marked by the discovery and refinement of the empirical rules that underpinned the universe, the 19th century showed the consequences that must inevitably follow...
Water powered mills, gave way to steam powered mills which led to industrial manufacture, which led to unimaginable acceleration of productivity, which led to wealth, which funded empires, which changed every corner of the world.
The industrial revolution was the triumph of Empiricism.
Machines of manufacture were precision empirical engines. Anything that could be made, could be made by machine. It was entirely obvious that the world and everything in it followed predictable, mechanical rules.
Now, step forward to the turn of the 20th Century...
The outstanding intellectual force of the age was David Hilbert. The German mathematician. Anyone who was anyone looked up to Hilbert as the definitive mind of his generation.
Hilbert, was surely a genius. In a stunning proclamation to mark the start of the new century, he set out a triumphant set of challenges to the mathematicians of the 20th Century. Today, some of these challenges have been met, but as a testament to his vision, many still remain to be resolved.
In the first article, I was being historically cruel to Hilbert. I set up the clockwork mayor in a way so as to tease him.
The reason being, that, nestling innocently amongst his challenges, was the mother of all Empirical visions.
Hilbert conjectured that mathematics itself would yield to the inevitable march of Empricism. He proposed that the formal methods of deductive mathematical reasoning could be implemented as an empirical process. In short, that mathematics would be mechanised.
I should not have been so cruel. For Hilbert was sitting atop the pinnacle of human achievement that was the 19th century. We cannot blame him and his peers for wanting more of the same. He was reflecting everyone's world view: "The world is clockwork. Soon every secret of the universe will be laid bare and nothing will be beyond our reach."
The idea that mathematics (the basis of all the sciences) was a closed empirical world was immensely powerful and attractive. That there were no holes, that everything that could be expressed could be proven (or disproven) was the ultimate triumph of Empiricism. It came to be known as "Completeness". A complete formal process that underpinned everything.
Complete clockwork.
Things start to get weird
It would be historically convenient to say that things then started to get weird.
No doubt you can anticipate some of the story that follows, but, in fact, before Hilbert's proclamation, things had already started to get weird.
In the 1870's Cantor gave the mathematical world its first dose of serious weirdness with his introduction of Set Theory.
Today we learn about Sets in junior school and we don't really get the point. "What use is a stupid Venn Diagram", we think.
The reason that we are introduced to sets is that we now understand that they provide the axiomatic basis for mathematics, even for numbers themselves.
When Cantor introduced the 19th Century mathematical community to Sets, all they saw were problems. Huge, nasty, frightening problems.
You see its easy to think about a set of two apples, or a set of three balls. But things start to go weird when you say "The set of whole numbers".
Things go really weird when you consider the "set of all things that are not apples".
If we think of this physically then we can sort of get our heads round it. But if we think of it strictly mathematically, the "set of all things that are not apples" must surely have itself as a member since it is a mathematical entity that is not an apple. But how can a set include itself?
However, things get really really weird when you start to try to classify how "big" a set is - its cardinality. How big is the set of Integers? Well its infinite right? What about the set of all rational numbers? Also infinite right? So they're the same size, yes? No they are not.
It turns out, and this was so weird it provoked a very strong reaction, there are different sizes (or rather "degrees") of infinity.
But this wasn't the only weirdness.
When you are required to consider infinitely large sets you start to discover that there are statements that are simultaneously true and false. We call these Paradoxes.
The more you consider sets the more you're likely to stumble into a paradox.
We all know about Bertrand Russell's Barber Paradox - the barber in the town shaves all the men who do not shave themselves. Who shaves the barber? (This is a variation of the paradox of the "set of non-apples" containing itself). Richard's paradox is worth a look too, since, relevant to ROC, it is a paradox of identity and representation.
The mother of all set theory paradoxes was an infinitely large hole that Cantor fell into - Cantor's paradox, the gist of which is that there are an infinitely large number of infinities!
Health Warning: Take care with set theory and infinity. Cantor eventually lost his mind. There's a recursive limit to our brains that you start to sense when you think too hard about this stuff. It bodes well to step back from the edge when you feel you're getting too close.
To his credit, and by way of apology for my assassination attempt, Hilbert was a strong defender and advocate of Cantor and Set Theory. However its inherent weirdness didn't prevent Hilbert wanting to lead the Empirical charge into the 20th Century. "Assuredly, the weirdness in Set Theory can only indicate that we have not found the formal empirical rules that must lie beneath...".
And so, with the world on the brink of collapse, we shall pause. Next time we'll see the world fall apart entirely, we'll see a new foundation emerge and we'll find that moving from Empiricism created an even larger vista of opportunity for 20th century prosperity. (And we'll finally get around to some Information Technology)...
Have a great weekend. Enjoy the summer.
Comments
Please feel free to comment on the NetKernel Forum
Follow on Twitter:
@pjr1060 for day-to-day NK/ROC updates
@netkernel for announcements
@tab1060 for the hard-core stuff
To subscribe for news and alerts
Join the NetKernel Portal to get news, announcements and extra features.