I love E4X

As a reality check of my proposal for skins in Helma 2 , I so far came up with the following prototype. The idea seems to work quite nicely already with current builds of Helma 2. I thought E4X could make implementing these kinds of mocha objects very easy, but I was surprised that it really turned out that way in practice.

function handle_get() {
    // first prototype for the next incarnation of mocha objects
    
    // the render function, providing the magic
    var render = function(view) {
        // loop
        var toLoop = view..*.(@loop.toSource() != '<></>');
        for (var item in toLoop) {
            var dataName = toLoop[item].@loop.toString();
            delete toLoop[item].@loop;
            var data = eval(dataName);
            var stamp = toLoop[item].toString();
            for (var i in data) {
                var stencil = stamp.replace(
                    eval("/%% "+dataName+"\\$\\.(.+) %%/g"),
                    '{ '+dataName+'['+i+'].$1 }'
                );
                stencil = stencil.replace(
                    eval('/"'+dataName+'\\$/g'),
                    '"'+dataName+'['+i+']'
                );
                stencil = stencil.replace(
                    eval('/"%% (.*)\\$'+dataName+'(.*) %%"/g'),
                    '{ $1'+i+'$2 }'
                );
                toLoop.parent().insertChildBefore(
                    toLoop[item],
                    eval(stencil)
                );
            }
            delete toLoop[item].parent().*[toLoop[item].childIndex()];
        }
       
        // lookup
        var toLookup = view..*.(@lookup.toSource() != '<></>');
        for (var item in toLookup) {
            delete toLookup[item].@lookup;
            var lookedup = '('+toLookup[item].children()[0]+')';
            toLookup[item].setChildren(lookedup);
        }
   
        // check
        var toCheck = view..*.(@check.toSource() != '<></>');
        for (var item in toCheck) {
            if (eval(toCheck[item].@check.toString()))
                delete toCheck[item].@check;
            else
                toCheck[item] = '';
        }
        return view;
    }
   
    // an example skin
    var myview = <table border="1">
        <tr check="topics">
            <th lookup="true">Topic Name</th>
            <th lookup="true">Comment Count</th>
        </tr>
        <tr loop="topics" class="%% 'rowcolor'+ ($topics % 2) %%">
            <td>%% topics$.name %%</td>
            <td check="topics$.count == 0" lookup="true">
                No comments yet</td>
            <td check="topics$.count == 1" lookup="true">
                %% topics$.count %% comment</td>
            <td check="topics$.count > 1" lookup="true">
                %% topics$.count %% comments</td>
        </tr>
        <tr check="!topics">
            <td colspan="2" align="center" lookup="true">
                This list is empty</td>
        </tr>
    </table>;
   
    // the example data
    var topics = [
        {name : 'Peter', count : 0},
        {name : 'Wolf', count : 2},
        {name : 'John', count : 1},
        {name : 'Andy', count : 8}
    ];
   
    // rendering the list
    var listtable = render(myview.copy());

    // rendering the empty table
    topics = null;
    var emptytable = render(myview.copy());
   
    // assembling the page
    var page = <html><body>{ listtable }<hr/>{ emptytable }</body></html>;
   
    // writing the page source to the reponse buffer
    res.contentType = "text/html";
    res.write(page.toSource());
}

Resulting in the following output:

(Topic Name) (Comment Count)
Peter (No comments yet)
Wolf (2 comments)
John (1 comment)
Andy (8 comments)

(This list is empty)


  19.12.2005, 10:28

Tutorial D, Industrial D and the relational model

From this interview with Chris Date :

[...] But the trouble with the relational model is, it's never been implemented--at least, not in commercial form, not properly, and certainly not fully. So while it's true that there have been a couple of developments in the marketplace over the past few years that I do quite like, I like them primarily because I see them as attempts to implement pieces of the relational model that should have been implemented years ago but weren't. I refer here to (a) "business rules" and (b) "object/relational DBMSs." I'll take them one at a time.

  • Business rules: Business rule systems are a good idea, but they certainly aren't a new idea. Without going into a lot of detail, business rule systems can be seen as systems that attempt to implement the integrity piece of the relational model (which today's mainstream SQL products still--over 35 years after the model was first described!--so signally fail to do).
  • Object/relational DBMSs: To a first approximation, "object/relational" just means the domains over which relations are defined can be of arbitrary complexity. As a consequence, we can have attributes of relations--or columns of tables, if you prefer--that contain geometric points, or polygons, or X rays, or XML documents, or fingerprints, or arrays, or lists, or relations, or any other kinds of values you can think of. But this idea too was always part of the relational model! The idea that the relational model could handle only rather simple kinds of data (like numbers, and strings, and dates, and times) is a huge misconception, and always was. In fact, the term object/relational, as such, is just a piece of marketing hype ... As far as I'm concerned, an object/relational system done right would simply be a relational system done right, nothing more and nothing less.

[...] The next thing I want to say is that, while the relational model is certainly the foundation for "doing databases right," it's only the foundation. There are various ways we can build on top of the relational model, and various attempts have been made to do such a thing over the past 25 years or so. Here are a couple of examples:

  • Higher-level interfaces: It was never the intention that every user should have to wrestle with the complexities of something like SQL (or even the complexities, such as they are, of the relational algebra). I always rather liked the visual interfaces provided by Query-By-Example and the "visual programming" front-ends to Ingres, for instance. And there are many other attractive front-ends that simplify the business of building applications on top of a relational (or at least SQL) DBMS. 4GLs too can be regarded as a higher-level interface--but I was never very impressed by 4GLs as such, in part because they never seemed to be precisely defined anywhere; the idea might have been OK, but without a formal definition of the semantics of the language some very expensive mistakes can be (and were) made. Natural-language systems are another example; I still have an open mind about these, but I don't think anyone could claim they've been a huge success as yet.
  • Special-purpose applications: I think the right way to view things like OLAP and data mining is as special-purpose applications that run on top of the DBMS. I mean, I don't think these things should be part of the core DBMS (I could be wrong). Either way, however, I do want to complain about the CUBE stuff in SQL, which takes one of the worst aspects of SQL--its support for nulls--and "exploits" it to make it even worse. But that's a particular hobbyhorse of mine ... I think I'd better stop right here.

19.12.2005, 0:01
 


Stop bashing Java

Jürg, making the case for Java beyond J2EE :

"...there were alternatives around since years (e.g. Helma , which is surprisingly similar to Rails in a few fields), and often the people who now blame J2EE for not having been efficient were simply to lazy to really look for alternatives earlier on."

"I think it might be time to stop bashing Java and enjoy the fact that there are actually ways of working with it or any language available in its growing little universe that are enjoyable, not bound to Sun licenses, very flexible, fast and resource-saving."

18.12.2005, 20:16


E4X Mocha Objects

The next generation of Mocha Objects might evolve in a direction that would look something like the following, tying in tighter with the hard-coding environment of Helma:

./Site/list.view.control

// function at Site.prototype.views.list.control(that)

    if (this.topics.count()) {

        that.topics = {};

        for (var topic in this.topics) {

            that.topics.name = this.topics[topic].name;

            that.topics.count = this.topics[topic].comments.count();

        }

    }

./Site/list.view

<table border="1">

        <tr if="topics">

            <th lookup="true">Topic Name</th>

            <th lookup="true">Comment Count</th>

        </tr>

        <tr for="topics" class="rowcolor{ $topics % 2 }">

            <td>{ topics$.name }</td>

            <td if="!topics$.count" lookup="true">

                No comments yet</td>

            <td if="topics$.count == 1" lookup="true">

                { topics$.count } comment</td>

            <td if="topics$.count > 1" lookup="true">

                { topics$.count } comments</td>

        </tr>

        <tr if="!topics">

            <td colspan="2" align="center" lookup="true">

                This list is empty</td>

        </tr>

    </table>

./Site/list.control

// function at Site.prototype.controls.list

    var content = {

        main : this.views.list.render()

    };

    var page = Page.views.default.render(content);

    return page;

this.views.list.control() is invoked when the list view is rendered. When it is invoked, "that" is the object which was passed as parameter of the render() method or otherwise an empty/default object. "that" is the object that will be used as the Javascript context when rendering the view.

Views would be E4X Javascript XML objects. When Helma would render these views, it would parse them for "lookup", "if" and "for" attributes and then evaluate them in the context of "that".

When parsing the "for" attributes, Helma would loop through the indicated object (topics) with "for(var $topics in topics)" and repeat the specified element (the table row) with topics$ == topics[$topics]

When parsing the "lookup" attributes, Helma would check if a lookup handler function exists and if so would apply it to the element's content.

this.controls.list would be the function that is called in order to handle the request, similar to todays this.list_action.

9.12.2005, 9:02

 


Logging and other antimatters

Javascript logging from log4j to log4js.

GCC on MacOS X with GCJ .

W3C has chartered a Web APIs Working Group .

There is no danger from antimatter. There are of course other dangers on the CERN site, as in any laboratory:  high voltage power in certain areas, deep pits to fall in, etc.

Wikis, weblogs and microlearning, learning from microformats: The theory of Vanilla .

24.11.2005, 7:02


Stronger types in Javascript 2

From Brendan Eich's JS2 design notes

Goals:

  1. Support programming in the large with stronger types and naming.
  2. Enable bootstrapping , self-hosting , and reflection .
  3. Backward compatibility apart from a few simplifying changes.

 Non-Goals:

  1. To become more like any other language (including Java!).
  2. To be more easily optimized than the current language.

Type operators and type annotations

Type annotations are optional. To support strict options that require every declaration to be annotated, * may be used for ⊤ (the top type), e.g. var v is * , which is equivalent to var v . Note that * is used differently for E4X, but its meaning as ⊤ is unambiguous in type operator and annotation right operand contexts.

In a nutshell, is t annotations insist on type t and defend against null and undefined (no more "foo has no properties" errors; with static analysis, an error that can't be avoided at runtime can even be reported at compile time). as t annotations enforce ( is t )-or-null invariance. And to t annotations convert according to cleaner, class-extensible rules.

[...]

Given types, you can assert (is), coerce (as), or convert (to). Conversion alone is not enough, since it either leaves null unconverted, which is a "foo has no properties" hazard that one should be able to assert against with an annotated declaration; or conversion changes, e.g., null to String "null", which may be acceptable with dynamic types only (Edition 3 and earlier), but which is wrong with asserting and coercing annotations such as "var str is String" and "var strOrNull as String".

Since "to" converts rather than asserts or coerces, it is not sufficient as the only kind of type annotation.

Hence the symmetry between the type operators and annotations. Failing to provide an annotation for a type operator gratuitously forces programmers to hand-code constraints, instead of letting the type system do the work.

10.11.2005, 17:32


Javascript Diagnosis & Testing

Some interesting additions that were made to the AjaxPatterns page:

Diagnosis

  • Logging Instrument your Javascript with log messages.
  • Debugging Diagnose problems with a Javascript debugger.
  • DOM Inspection Use a DOM Inspection Tool to explore the dynamic DOM state.
  • Traffic Sniffing Diagnose problems by sniffing Web Remoting traffic.

Testing

  • Simulation Service Develop the browser application against "fake" web services that simulate the actual services used in production.
  • Browser-Side Test Create automated tests of browser-side Javascript components.
  • Service Test Build up automated tests of web services, using HTTP clients to interact with the server as the browser normally would.
  • System Test Build automated tests to simulate user behaviour and verify the results.
10.11.2005, 16:25

Homo Oxymora

" Artificial artificial intelligence " and " why the future doesn't need us ".

"[...] a well-known problem with the design and use of technology, and one that is clearly related to Murphy's law - "Anything that can go wrong, will." (Actually, this is Finagle's law, which in itself shows that Finagle was right.)"

5.11.2005, 17:57


>>> Yeah, why not Javascript?

> Moving beyond Java
> Spidermonkey Javascript 1.5 finally final
> Helma Trivia
> Finding Java Packages
> JSEclipse Javascript plug-in for Eclipse
> Catching up to Continuations
> Mighty and Beastie Licenses
> Tasting the OpenMocha Console
> "Who am I?", asks Helma
> Savety vs Freedom and other recent ramblings
> Mont-Soleil Open Air Lineup
> Rhinola - Mocha reduced to the minimum
> OpenMocha 0.6 available for download
> E4X presentation by Brendan Eich
> What is Mocha?
> Do you remember Gopher?
> The current.tv disappointment
> OpenMocha Project Roadmap
> MochiKit Javascript Library
> Getting your feet wet with OpenMocha
> People flocking to see global warming
> Rails vs Struts vs Mocha
> The JavaScript Manifesto
> OpenMocha is ready for a spin
> The limits of harmonization
> Le Conseil fédéral au Mont-Soleil
> Amiga History Guide
> The people must lead the executive, control the legislature and be the military
> Copyback License
> Looking at FreeBSD 6 and Beyond
> Qualified Minority Veto
> The Doom of Representative Democracy
> Violence in a real democracy
> Concordance and Subsidiarity
> Wrapping Aspects around Mocha Objects?
> Future of Javascript Roadmap
> Baby steps towards Javascript heaven
> Mac OS X spreading like wildfire
> Trois petits filous à Faoug
> Jackrabbit JSR 170
> Rich components for HTML 5
> More Java Harmony
> Mac goes Intel
> Google goes Rumantsch
> Oxymoronic Swiss-EU relations
> Rico and Prototype Javascript libraries
> Paul Klee - An intangible man and artist
> Incrementalism in the Mozilla roadmap
> Mocha multi-threading
> Moving towards OpenMocha
> Google goes Portal
> What Bush doesn't get
> Unique and limited window of opportunity
> Persisting Client-side Errors to your Server
> Dive Into Greasemonkey
> Brown bears knock on Switzerland's door
> The experience to make what people want
> "Just" use HTTP
> Yes, what is gather?
> A Free Song for Every Swiss Citizen
> Java in Harmony
> Jan getting carried away
> Evil Google Web Accelerator?
> JSON.stringify and JSON.parse
> Ajax for Java
> The launching of launchd
> Timeless RSS
> Kupu
> SNIFE goes Victorinox
> AJAX is everywhere
> Papa Ratzi
> How Software Patents Work
> Ten good practices for writing Javascript
> Free-trade accord with japan edges closer
> Mocha at a glance
> Adobe acquires Macromedia
> Safari 1.3
> View complexity is usually higher than model complexity
> Free Trade Neutrality
> SQL for Java Objects
> Security Bypass
> Exactly 1111111111 seconds
> Kurt goes Chopper
> Choosing a Java scripting language
> Spamalot's will get spammed a lot
> The visual Rhino debugger
> The Unix wars
> EU-Council adopts software patent directive
> FreeBSD baby step "1j"
> Never trust a man who can count to 1024 on his fingers
> Visiting the world's smallest city
> Finally some non-MS, non-nonsense SPF news
> Swiss cows banned from eating grass
> Ludivines, the "Green Fairy" of absinthe
> First Look At Solaris 10
> EU Commission Declines Patent Debate Restart
> Alan Kay's wisdom guiding the OpenLaszlo roadmap towards Mocha?
> 1 Kilo
> Re: FreeBSD logo design competition
> Schweizer Sagen
> Europas Eidgenossen
> XMLHttpRequest glory
> Art Nouveau La Chaux-de-Fonds 2005-2006
> The Beastie Silhouette
> The Number One Nightmare
> Safe and Idempotent Methods such as HEAD and TRACE
> Sorry, you have been verizoned.
> Daemons and Pixies and Fairies, Oh My!
> Sentient life forms as MIME-attachments: RFC 1437
> Anno 2004: CZV
> Web Developer Extension for Firefox
> Refactoring until nothing is left
> Brendan, never tired of providing Javascript support
> Catching XP in just 20 Minutes
> Designing the Star User Interface
> Rhino, Mono, IKVM. Or: JavaScript the hard way
> Re: SCO
> Judo
> Convergence on abstraction and on browser-based Console evaluation
> Today found out that inifinite uptimes are still an oxymoron
> New aspects of woven apps
> Original Contribution License (OCL) 1.0
> Unified SPF: a grand unified theory of MARID
> BSD is designed. Linux is grown.
> 5 vor 12 bei 10 vor 10
> Mocha vs Helma?
> Schattenwahrheit: Coup d'etat underway against the Cheney Circle?
> Abschluss Bilaterale II Schweiz-EU
> From Adam Smith to Open Source
> Linux - the desktop for the rest of them
> Big Bang
> Leaky Hop Objects
> Return Path Rewriting (RPR) - Mail Forwarding in the Spam Age
> Microsoft Discloses Huge Number Of Windows Vulnerabilties
> Steuerungsabgabe statt Steuern
> Anno 2003: deployZone
> The war against terror
> The war against terror (continued)
> The relativity of Apple's market share
> Are humans animals?
> Anno 1999: Der Oberhasler
> Anno 1998: crossnet
> Geschwindigkeit vs Umdrehungszahl
> Anno 1997: Xmedia
> "The meaning of life is to improve the quality of all life"
> Anno 1996: CZV
> How do I set a DEFAULT HTML-DOCUMENT?
> Global Screen Design Services



Forum for Direct Democracy

Javascript server-side

Helma Project


Christoph Zumbrunn
2610 Mont-Soleil, Switzerland
+41 329 41 41 41
chris@zumbrunn.com
IRC: zumbrunn on freenode.net
Jabber: chris@zumbrunn.com
Skype: ChrisZumbrunn
Listening to: worldradio.ch
Xing profile



Chris Zumbrunn's Mochazone
> First Soleil on Mont-Soleil
> Helma turns 1.6.3
> Helma 1.6.3-rc3 ready for testing
> Helma 1.6.3 Release Candidate 2
> Release Candidate 1 of Helma 1.6.3
> Helma at the 2008 OpenExpo in Zurich
> Large Hadron Collider
> Ecmascript Harmony
> The A-Z of Programming Languages jumps to Javascript
> Fresh Javascript IDE in Ganymede Eclipse release
> Helma at the Linuxwochen in Linz
> Brendan on the state of Javascript evolution
> Is AppleScript done?
> ES4 Draft 1 and ES3.1 Draft 1
> Want ES4 in Helma today?
> SquirrelFish!
> ES4 comes to IE via Screaming Monkey
> Apple's position on ECMAScript 4 proposals
> Helma Meeting Spring 2008
> Attila Szegedi about Rhino, Helma and Server-Side Javascript, and scripting on the JVM in general
> Helma 1.6.2 ready to download
> Larry Lessig's case for creative freedom
> Earthlings - Can you face the truth?
> The Story of Stuff
> A Quick Start to Hello World
> The Overlooked Power of Javascript
> Adobe's position on ES4 features, plus the Flex 3 SDK source code is now available under the MPL
> Solar cell directly splits water for hydrogen
> Asynchronous Beer and Geeking and other opportunities to talk about Helma, Rhino and Javascript on the server-side
> Openmocha and Jhino updated to 0.8
> Even more Server-side Javascript with Jaxer
> e4xd and jhino - javascript server-side soft-coding
> Additional Filename Conventions
> Update to Helma 1.6.1
> Netscape, the browser, to live one more month
> SimpleDB vs CouchDB
> Helma powered AppJet - Takeoff!
> CouchDB for Helma
> Bubble bursting friendship bracelets
> Evolving ES4 as the universal scripting language
> Helmablog and an article in Linux Pro Magazine
> More praise for Helma
> Javascript as Universal Scripting Language
> So, what's up with World Radio Switzerland?
> Helma Conspiracy Theory
> JSONPath and CouchDB
> Hold the whole program in your head, and you can manipulate it at will
> Keeping track of localhost:8080
> Rhino 1.6R6 with E4X fix and patches for Helma
> Helma 1.6 is ready!
> Junction brings Rhino on Rails to Helma
> Javascript for Java programmers
> The server-side advantage
> John Resig on Javascript as a language
> Rhino on Rails
> Release Candidate 3 of Helma 1.6.0
> ECMAScript 4 Reference Implementation
> Antville Summer Of Code 2007
> Helma 1.6.0-rc2
> Using H2 with Helma
> Helma warped around existing db schemas
> Rocket the Super Rabbit
> Bootstrap is out of the bag
> The last mention of Microsoft
> Helma 1.6.0-rc1
> Introducing Planet Helma
> Helma ante portas
> Fixing Javascript inheritance
> Shutdown-Day the Helma way
> Upcoming Helma 1.6, new reference docs and IRC channel
> Making Higgs where the Web was born
> Jala for Helma
> See you at Lift'07
> More on Javascript Inheritance
> Mocha Inheritance
> Helma 1.5.3
> Fresh Rhino on Safari
> Truly Hooverphonic!
> Helma 1.5.2
> RFC 4329 application-ecmascript
> Helma 1.5.1 ready to download
> Aptana - Eclipse reincarnated as a Javascript IDE
> Building the Conversational Web
> Drosera steps in to debug Safari
> Helma 1.5.0 has been released!
> Helma 1.5 RC2 is ready
> Helma 1.5.0 Release Candidate 1 available for download
> FreeBSD Jails the brand new easy way
> Javascript 2 and the Future of the Web
> Frodo takes on chapter 3
> No Rough Cut :-(
> Welcome to Helma!
> 40th Montreux Jazz Festival
> trackAllComments
> Rails' greatest contribution
> Consensus vs Direct Democracy
> A candidate for CSCSJS or a Mocha Fetchlet
> A (Re)-Introduction to JavaScript
> coComment Roundup
> Track your comments
> Sketching image queries and reinventing email
> ECMAScript - The Switzerland of development environments
> I love E4X
> Tutorial D, Industrial D and the relational model
> Stop bashing Java
> E4X Mocha Objects
> Logging and other antimatters
> Stronger types in Javascript 2
> Javascript Diagnosis & Testing
> Homo Oxymora
> More >>>