The SSJS dilemma - I am an idiot

Wednesday, November 5, 2014 at 2:56 PM UTC

You may heard of and/or read about it before: experienced XPages developers around the globe are preaching not to use SSJS whenever it is possible. I'd count myself to the semi-experienced guild on XPages right now though I've done several complex things and projects with them - and I am still learning new stuff. I never gave too much for statements like "SSJS is a crutch" as Andrew Magerman posted in September this year (http://blog.magerman.com/2014/09/17/ssjs-is-an-abomination-born-out-of-ibms-misguided-condescension/). He is right with that though in some points.

But I also have a focus on people who are beginners at XPages development as a whole new way of programming and designing. Despite they may have years of experience in Notes programming, XPages are a complete different approach and the learning curve is very steep.

This might have been the reason for IBM to create Server Side Javascript (SSJS): a whole new language which provides some of the benefits of Java AND of the Formula language just to simplify things by offering a similar syntax and functionality that a long term developer is able to come around with in less time - great idea!

For some reason I excessively used SSJS in my current project (started months ago and now I'm working on it again in a follow-up project). I'm actually doing all the validation stuff for my XPages in SSJS as it was easy to do so (most of the time). I have to mention that I am working with another developer from the customer on two different branches of the application (we use Gitlab and Sourcetree to manage that and until now it works like a charm). But for some reason that developer changed a bit the libraries he found that I created months ago so I had (and still have) to adapt my parts to that. No problem!

But now I ran into a timing and object handling issue although I was very careful in the adaption process. Nothing worked as expected anymore - doh!

I am not able to use the OpenNTF Domino API here but switching my SSJS stuff into a bean that I already had was the best decision I made in this project. Sure, I am supposed to handle my objects for myself, recycle them appropriately and have to care about infinite loops. MIME is also a big part here but I can handle it for myself, too. It took me the whole day to rewrite the stuff and test everything again - but at the end of the day I am convinced one more time by saying:

Use Java and managed beans whenever you can!

While rewriting my stuff I noticed some capital fails and faults in SSJS. With SSJS you can do and are able to effort things that you can't in pure Java, e.g. automatic type casting. SJSS code contained something like that:

if(result==false && (userBean.getMessage('Error') == "" || userBean.getMessage('Error') == null)){
        userBean.addTopMessageToStackHolder("Es ist ein Fehler aufgetreten (s. rote Markierung[en]). Bitte überprüfen Sie Ihre Eingabe!"); 
}

Apart from the fact that you should test an object if it is null BEFORE testing anything else the test itself wouldn't compile in Java at all as userBean.getMessage() returns a LinkedList and not a String. In SSJS this was automatically casted so that it ran, in Java you have to cast it correctly. I love it when the IDE tells my that I am an idiot - and how to fix things!

TL;DR

The question is: why did I start with that way of programming? I actually "didn't start the fire" (a co-worker did) but I continued to do it the same way. That was a fault. 

When I am programming my own private projects I always use Java and managed beans etc - with no problems at all until now. Although I am using the OpenNTF Domino API most of the time the message of this post is: you can also use Java without it - if you obey the orders and follow some rules of thumb.

So please, you beginners in XPages development, please have a look at the benefits pure Java will offer and use it! I promise you don't want to do anything else as soon as you are familiar with it!





Latest comments to this post

Andrew Magerman wrote on 05.11.2014, 17:33

Thanks for the link!

I'd like to mention, though, that I am very much in the middle of the steep learning curve. To be honest, I am currently splattered on the wall of the learning curve and most of the time I am thinking 'I have no idea of what is going on here'.

All the best

Andrew

 Link to this comment

Leave a comment right here