Jazoon 2013 – STJS: Managing JavaScript application complexity

24. October, 2013

Jazoon 2013 badgeThe talk “STJS: Managing JavaScript application complexity” by Alexandru Craciun (LinkedIn) and Nicolas Piguet (LinkedIn) focused on one of the major pains with JavaScript: It’s easy to get started, you have can quickly build a useful app which then just as rapidly turns into a maintenance nightmare (slides).

They used ST-JS as a tool to reign the dragon.

In a nutshell, ST-JS is a tool that parses Java code and converts it into JavaScript.

What ST-JS isn’t: It’s not GWT (see the FAQ). The code can be edited in your IDE, it compiles but it doesn’t run directly. The Java code is just used to allow you to write type-safe code using all the amenities of a modern Java IDE to write JavaScript. But if you want, you can implement so parts – think about sharing POJOs between your Java code and the script in the browser.

This works by writing thin wrappers (usually just a bunch of Java interfaces) to simulate the API layer of a JavaScript framework like jQuery. This code is called a bridge, here is a list of already available ones. You can then write code using code-completion, JavaDoc popups and type safety. You can apply tools like PMD, FindBugs, SonarQube (formerly Sonar), dead code analysis, …

The tool will then convert this code into JavaScript. A standard JUnit runner can now execute it by opening a browser window or simulating one using env-js and Rhino.

The output of the tool is plain JavaScript. To run it, you just need to include stjs.js which you can serve statically from your server.

As I see it, this project has the following benefits over anything else I’ve seen so far:

  • Full support from your Java IDE – Code completion, refactoring, type/JavaDoc popups, jump-to-definition, …
  • You can split the JavaScript mess easily into classes and packages
  • Not intrusive, low complexity
  • Easy to build bridges to other JavaScript frameworks
  • Allows to share POJOs between Java and JavaScript

Jazoon 2013 – Test First Saves The World

24. October, 2013

Jazoon 2013 badgeThe opening keynote “Test First Saves The World” by Joe Justice introduced WIKISPEED. The project aims “to deliver a mass-production, ultra-efficient, Comfortable Commuter Car, the C3“.

You can find the current list of bugs here.

Some important points about this car: Building the first road-worthy prototype took only 3 months. A team of untrained individuals can build one of them in about one day. It runs on 2.8 l gasoline per 100 km.

In comparison: Professional car manufacturers need hundreds of people and 3 years to build something which dozens of trained teams can assemble in a few hours. And the result is either four times as expensive or pollutes the environment more.

Sounds good? They use scrum. They proved on several occasions that the method works very well for hardware, too (Forbes, CNN Money).

I agree with Joe that scrum is now entering the 3rd phase of the hype cycle: Only the most conservative companies remain cautious.

But scrum isn’t easy – if our problems were easy to solve, we wouldn’t need help, right?

While you can spend some money on training (for example, by asking scruminc to send Joe to your place), you need to remember one of the most important points of scrum: Continuous improvement.

Conclude every spring with a retrospective, identify one item that the whole team wants to have solved – more plants, better soap, an additional microwave, more light, new computers, you name it. Put that as the first item in the next spring and work on it first. Don’t forget to define acceptance criteria.

Or do you like working in a place where the general mood is that “nothing ever changes – especially not for the better”? Everyone knows that happiness and quality will make teams more productive. It’s high time to take a stand in the face of “it’s just the way it is.”

Joe’s next project? A $100 house for homeless.

What’s your’s?


NSA Killed Groklaw

10. September, 2013

I’m not sure how to process this.

Because of the ubiquitous surveillance by the US government, Groklaw closed shop. Pamela “pj” Jones just didn’t feel like she could continue her work in such a situation.

If you didn’t know Groklaw: It was the site which cared about law and how it was (and should) be applied in the context of technology. They showed the absurdities of the recent patent lawsuits and other economic war games like the famous lawsuit between IBM and SCO.

And now it’s gone.

I feel guilty because I didn’t notice.

And after reading pj’s last article, I wonder whether her reaction is too emotional or actually more appropriate than my own “it won’t be that bad” attitude.

Now some people will say it’s not a problem. The NSA isn’t allowed to monitor US citizens.

Wrong. It’s way too complicated to filter your mails out of the traffic. So the NSA stores them anyway. And as soon as you write an email to a non-US person, they can watch you without breaking any laws. How much? All the mails? Just the ones which you exchange with someone else on the planet? Who knows. You think you can find out? They know all about you but they won’t tell you anything.

Or maybe you think that you have nothing to hide.

Really? Send me copies of your bank accounts, please. Oh, and photos of your home, your timetable (especially when no one is at home) and where you keep your spare key. How about a password list? Of course, I’m not going to abuse this information. What do you think of me?

And, as pj correctly wrote in her last article, the problem with surveillance has never been what anyone might have to hide.

Instead, the state is suddenly treating its citizens like enemies, creating an atmosphere of distrust. Also, in a few years or maybe even months, “smart” computer programs will look for patterns in the huge amounts of data that the NSA collects. They will stop looking for “Who is a terrorist” and start looking for “Who might become a terrorist?” It makes sense, doesn’t it?

If you have ever used a computer, then you know how dumb and uncaring they are. And suddenly, they decide who is a terrorist? Without anyone being able to second guess this? When the police comes kicking in your door, they won’t even be allowed to tell you why – national security.

i said before: I’m all for surveillance but for everyone. You want to watch me? Well, good. I want to watch all the people in the government. I want to know who they met, how long, what they talked about, how they voted, every penny they goes though their bank accounts. While we’re at it, I want the same for the management layer of big corporations. They are often as big as small states. We observe those, why not corporations?

What, no? Why not? How can it be OK to watch me, a nobody, but not the people who make the big decisions?


Learning JavaScript Design Patterns by Addy Osmani

6. September, 2013

Learning JavaScript Design Patterns” is a free eBook (also available in print via O’Reilly Media) by Addy Osmani which explains how to apply various design patterns to JavaScript.

It’s not only a great resource to improve your JavaScript skills or an easily understandable refresher of design patterns (if you didn’t understand the C/C++ or Java versions, this is the place to go!).

It also lists some of the latest patterns that you might have missed like the MVVM pattern.

Last but not least, it can serve as a test for huge HTML pages 😉


Wine on OpenSUSE Without Sound

4. September, 2013

Yesterday, I tried to install the Windows game Homeworld on my openSUSE 12.3. After a couple of problems, the no-cd patch, I could start the game with:

/opt/cxoffice/bin/cxrun --bottle Homeworld homeworld.exe /1600 /enable3DNow /enableSSE /device gl /heap 1073741824

Note: For /device gl, you must install DirectX 9.

The main problem: No sound. Starting the Wine Configuration, I saw that it was using winealsa.drv in the Audio tab.

Looking into the terminal finally solved the mystery:

ALSA lib dlmisc.c:236:(snd1_dlobj_cache_get) Cannot open shared library /usr/lib/alsa-lib/libasound_module_pcm_pulse.so
ALSA lib dlmisc.c:236:(snd1_dlobj_cache_get) Cannot open shared library /usr/lib/alsa-lib/libasound_module_pcm_pulse.so

My system is 64bit but Crossover is probably a 32bit application.

Installing alsa-plugins-pulse-32bit finally solved the problem.

Also make sure you have this in your ~/.asoundrc:

pcm.!default {
    type pulse
}
ctl.!default {
    type pulse
}

Related:


Selenium vs. ZK

30. August, 2013

Testing ZK applications using Selenium can be a drag. Selenium offers a lot of tool to test traditional request-response cycle applications. But it relies heavily on stable element IDs and submitting whole forms.

ZK, on the other hand, sends just a skeleton page to the browser and from then, builds everything with JavaScript. Instead of posting a whole form, it submits individual field values (to trigger validation). And it assigns random IDs to reach element.

At first glance, the two don’t seem to be a perfect match. But there are a couple of simple tools that will make your life much more simple.

Getting Stable IDs for Tests

One solution here is to write an ID generator which always returns the same IDs for each element. But this is tedious, error-prone and sometimes impossible.

A better solution is to attach a custom attribute to some elements which doesn’t change. A beacon. If you have a central content area, then being able to find that will make your life much more simple because whatever else you might seek – it must be a child of the main content.

To do that, add a XML namespace:

    <zk xmlns:cl="client" xmlns:ca="client/attribute">

to the top of your ZUL file, you can now use a new attribute ca:data-test-id="xxx" to set a fixed attribute on an element. In Selenium code, you can now locate this element using this code:

    By.xpath( "//div[@data-test-id = 'xxx']" )

I suggest to use this sparingly in order not to bloat your DOM. But a few of them for fast moving targets will make your tests much more stable.

Debugging the DOM

Sometimes, your life would be much more simple if you could see what the DOM was when your test failed. Here is a simple trick to get a HTML fragment from the browser:

    protected JavascriptLibrary javascript = new JavascriptLibrary();

    public String dump( WebElement element ) {
        return (String) javascript.executeScript( driver,
            "return arguments[0].innerHTML", element );
    }

You can now use JTidy and JDOM to convert the fragment first into W3C XML nodes and then into JDOM elements:

    public org.w3c.dom.Document asDom( WebElement parent ) {
        String html = dump( parent );
        Tidy tidy = new Tidy();
        tidy.setShowWarnings( false );
        tidy.setErrout( new PrintWriter( new NullOutputStream() ) );
        org.w3c.dom.Document dom = tidy.parseDOM(
           new StringReader( html ), null );
        return dom;
    }

    public static org.jdom2.Document asJDOM( org.w3c.dom.Document content ) {

        // JDOM chokes on: org.jdom2.IllegalNameException: The name "html PUBLIC "-//W3C//DTD HTML 4.01//EN"" is not legal for JDOM/XML DocTypes: XML names cannot contain the character " ".
        Node docType = content.getDoctype();
        if( null != docType ) {
            content.removeChild( docType );
        }

        DOMBuilder builder = new DOMBuilder();
        org.jdom2.Document jdomDoc = builder.build( content );

        return jdomDoc;
    }

Another great use case for this is a default exception handler for tests which saves a screenshot and a copy of the DOM at the time a test fails. No more guessing why something didn’t happen.


Debugging proxy.pac Files

29. August, 2013

I just wrote a small utility to debug proxy.pac files using the excellent pacparser library.

You can find it here (gist).


Why God Can’t Exist

7. August, 2013

A little thought experiment. Nothing in an experiment is true but it can help you understand.

God is said to be almighty. If She is, then She should be able to create the perfect world, a place where nothing bad or evil ever happens.

But such a place would be incredibly boring.

Boredom is bad.

Hence God can’t be almighty. Without this attribute, God is incomplete.

Or maybe our universe is perfect – we’re just unable to see it because we whine all the time about everything bad and evil that happens instead of enjoying the good things.

PS: If God exists, She must be female. Or did you ever see something created by a male that kept working for more than 5000 years?


Google Shares Your WLAN Passwords with NSA

17. July, 2013

If you “Back up my data” is enabled on your Android phone, then Google keeps a clear-text, unencrypted copy of your WLAN passwords on its servers. Since Google is an US company, the government and its agencies have access to this data. Google also keeps a database with the location of all WLANs (for their location service) so it’s trivial for them to gain access (even though someone must physically walk/drive into the range of the WLAN router).

Solution: Disable this function, use a local backup program (disable cloud backup for them as well) and change all your passwords.

Related articles:


Printing Money @Home

2. July, 2013

Ever thought about printing money at home?

It’s illegal, right. But think about this idea:

Your printer driver is connected to, say, PayPal. You draw some cute image (or use your cat if you can’t draw or the Internet, it’s full of cats). You create a QR code worth $15, slap them together with gimp and go to spend it.

Everyone has a mobile phone, so checking those codes would be no big deal. Just an app and you’re done.

And the best part: The NSA would know all the time where you are! You’d never get lost! When they notice you stopped spending money, they could send you an ambulance!