Monday, June 22, 2009

To MDEC: Java should be a national agenda

















I had a meeting with MDEC a few weeks before OSCONF and they reveal some startling statistics: Apparently 50.6 % of MSC companies are in need... no... are dying to find good Java programmers. So much so, they don't mind going to Indonesia, the Philippines and many other places, to recruit programmers there (offshore). These companies are willing to train them and
pay them a handsome fee just so that they can have decent Java programmers.

Now, 50.6 % is a big number. It's bigger than the need for .Net, for Ruby, for Phyton,, for PHP, for SAP.

Heck, it's bigger than .Net, Ruby, Phyton, PHP and SAP COMBINED!

In other words, most (and that's a big "most") of the projects within MSC now are Java based.

Now here's a short reality check, what if we (as a nation) do not provide our MSC companies with these much needed Java programmers? Do you think the jobs will switch to PHP? No way
Jose. What will happen is that jobs are going to go away. In this case, it'll be roughly 50% of the jobs. I've read somewhere that we want to outdo China as the second largest outsourcing destination... well, if 50% of the jobs here are going to Indonesia... good luck with that.

So what should we do. Here's a few sugestion to MDEC:

1) Take over Java education in Malaysia and don't leave it to Sun

... Heck, don't even leave it to Oracle. In my experience, Oracle is sooo not interested in small markets (where most of the jobs dwindle) They care for big multi-million dollar accounts but Oracle is almost invisible in smaller arenas. The fact that Oracle is going to buy over Sun (and thus become the steward of Java) will mean less resources will be dedicated towards Java education (and it was already bad under Sun).

OK, I know a few people in Microsoft and the Ruby/Phyton/PHP group are so going to whack me on this but listen up: MDEC has to take over Java education, not because MDEC is favouring Java over other platforms or languages, not because MDEC is some Sun/Oracle/Java/Obama hugger. No! but because it makes business sense to do so. If MDEC is not doing this, good bye 50 or so % of MSC jobs. Besides, if you are a Ruby/Phyton/PHP developer, these language s run well on the JVM too so this call make sense to all (well, almost all :P )

2) Revamp the Java sylabus

Sun's objective in Java education is to ram a dead horse down the programmers throat... and that dead horse is called "applet programming". Ask any university student who has studied Java and they will equate Java to ugly applets.

Gosh! stop it already!. Applet is dead, get over it Sun... wait a minute, they did. That is why they introduce JavaFX. So, what is with this rubbing of people's face with applet anyway? because
people are lazy ... especially to update sylabus.

We need to revamp the sylabus. Sun will not do it for us. MDeC has to do it (On a side note, I'm more than willing to volunteer my time to revamp the Java sylabus).

In my opinion, to teach basic Java and OOP, Java ME should be a better platform. First off, I can just imagine how students feel if the "Pong" game they created can run on their own phones. It's
something to show off about, it's cool, it's something to twitt about...

Game is a perfect environment to teach OOP. Objects become natural (in form of sprite and what not).

Next, come basic networking. Heck, ask them to create a twitter client. That'll be cool too eh?. Next come bluetooth, GPS and what not. Mesh that up with Google Map and voila, Java becomes cool again!

Another point about revamping the sylabus is this: stop "protecting" the students. I know lecturers who say "We can't teach them JavaEE. It's just too complex, the students will become demotivated"... puhleeezzz.

The truth is, JavaEE is intimidating to the lecturers, not the students. JavaEE (Servlet 3, JSF 2, EJB 3.1, basic security, messaging... heck, even SOA) should be taught to final year students because if you do not know basic ORM you're practically useless as a Java programmer.

If the lecturers are inadequate in terms of experience and knowledge, we need to bring in the professionals into the universities. And thus my third point....

3) Bring in Java pros into the universities

During that meeting with MDEC, I can really feel the dire need by the companies to get good Java programmers. Now, if these companies are willing to travel in Indonesia to train people there, I'm sure they are more than willing to contribute to our local universities.

Sure, these Java pros might not have a PhD and, I guess, according to univerisities, they are somehow "muggles" and "has no right to take a podium at our distinguished ivory towers".

Here's what I have to say to that: Bulls**t!

Knowledge is knowledge. If it comes not from a research work but rather from the grudge of waking up at 3 in the morning debugging a JBOSS classloader, it is still knowledge worth propagating, worth teaching. And thus these Java pros need to be integrated into universities despite their lack of a PhDs.

4) MDeC needs to work closely with the universities

... on how to teach Java. Work closely with the council of Dean of IT faculties. Get them to commit on Java BIG TIME!. Bring Neal Gafter and Josh Bloch here to teach our lecturers on the intricacies of Java. Have an unconference where any lecturer can propose his approach to teach Java. (Heck, Microsoft did it for Windows, now MDeC has to do it for Java... remember the 50.6% )


It is not too late to act if we act now... I mean like now, this very second. To my friends in MDeC, please push for this. Not for Sun, IBM or Oracle but the sake of the nation.

Tuesday, June 9, 2009

Did we get MVC wrong?

Every computer science major and their iguanas have heard of the MVC pattern. It's being used by everyone from Sun to Microsoft.

Here's a diagram showing how MVC is suppose to work (shamelessly copied from wikipedia)


Now quoting from Wikipedia's entry on MVC [http://en.wikipedia.org/wiki/Model-view-controller] "Successful use of the pattern (i.e. MVC) isolates business logic from user interface considerations, resulting in an application where it is easier to modify either the visual appearance of the application or the underlying business rules without affecting the other."

Now here's what Reenskaug has to say about MVC (BTW, Trygve M. H. Reenskaug is the inventor of MVC) [http://heim.ifi.uio.no/~trygver/themes/mvc/mvc-index.html] and I quote "The essential purpose of MVC is to bridge the gap between the human user's mental model and the digital model that exists in the computer. The ideal MVC solution supports the user illusion of seeing and manipulating the domain information directly. The structure is useful if the user needs to see the same model element simultaneously in different contexts and/or from different viewpoints."

Wait a minute, that's different: The inventor of MVC emphasises the ability of MVC to give different views of the same data, while the wikipedia entry somehow talks about isolating (i.e. modularising - is there such a word?) application. Those two things are not the same!

The rub is, if you allow me to repeate: MVC was not created to modularise application, repeate after me. It was not for isolation people! It was created to give different views of the same big gianourmous data (c.f. Reenskaug's definition).

Sure, things are seperated into model, view and controller but that is just a consequences and not the main goal of MVC.

Confusing the goal of MVC with some other goals is actually detrimental to software development. Let us see how.

A typical MVC flow is like this:

User input --> Controller --> Update model--> View, observing the model has changed, updates itself

A typical non-MVC flow would be like this:

User input --> Controller --> (Update model and Update view)

The non-MVC is the model followed by say a typical Java Swing application, JSF and Struts. The problem is that the view is really inactive. The vision of multiple views being in sync with the huge data in the back-end becomes more difficult. Say, for example I want to add a new field in the view. The field already exist in the database, just a matter of displaying it. With MVC, I just query the model (from the view) when the view is "waken up" by the observation event. I need to change the view and that's that. With non-MVC approach, I have to update both the view and the controller to get the same effect.

The problem lies in the fact that, even in the non-MVC approach, my code is isolated and compartmentalised, if I stick with the definition given by wikipedia, I would therefore have the impression of doing MVC without actually doing it. Whereas with MVC, I'm reaping the benefit of MVC and at the same time getting my modularity, its like having my cake and eat it too.

Given how fast interface technology (RIA, Flex, JavaFX, Silverlight, your-hoot-n-nanny-of-the-day) is evolving, having multiple, insync views of a large data is inevitable. You would probably need to cater for, at least, the web and the mobile audience. Having a real MVC framework would help enormously... if and only if MVC is done correctly.

Friday, June 5, 2009

Scala Actor + Message Driven Bean (MDB) using JMS

 

What I wanted to do is to integrate Scala Actor and MDBs. The reason to do so is because Scala actors, as good as they are, are :

1) Not transactional

2) Cannot send message through  a network

This leads me to investigate what Java EE has to offer: Java Messaging Service.

Now in many implementation of JMS that I see, it will always end up in some Message Driven Bean (an EJB). So that is what I’m going to do. An actor will send a message in an MDB and the MDB replies back.

To use JMS with Scala actors, we need to use Spring. Spring offers a utility to create Message Driven Pojos (meaning, any Java object can be transformed into a message receiving object) Since Scala actors are actually Java objects on steroid, I figure that we can use Spring to equip plain old Scala actors with message (as in JMS message) receiving capability. This receiving actor will be called a “wormhole actor” as it bridge the JMS world and the Scala world.

OK, let us start: First we need to create a Spring xml file. This file contains several beans:

This bean helps us to find the JNDI engine of our Java EE server where the MDB resides.

    <bean id="myJndiTemplate" class="org.springframework.jndi.JndiTemplate" scope="singleton">
        <property name="environment">
            <map>
                <entry key="java.naming.factory.initial" value="com.sun.appserv.naming.S1ASCtxFactory"/>
                <entry key="java.naming.provider.url" value="iiop://127.0.0.1:3700"/>
            </map>
        </property>
    </bean>

This bean defines the queue factory

    <bean id="jmsQueueFactory"
               class="org.springframework.jndi.JndiObjectFactoryBean"
                abstract="false" lazy-init="default" autowire="default"
                dependency-check="default">
        <property name="jndiName">
            <value>jms/QueueFactory</value>
        </property>
        <property name="resourceRef">
            <value>false</value>
        </property>
        <property name="jndiTemplate" ref="myJndiTemplate"/>
    </bean>

These beans define the request and the response queue respectively:

    <bean id="jmsRequestQueue"
                class="org.springframework.jndi.JndiObjectFactoryBean"
                abstract="false" lazy-init="default" autowire="default"
                dependency-check="default">
        <property name="jndiName">
            <value>jms/RequestQueue</value>
        </property>
        <property name="resourceRef">
            <value>false</value>
        </property>
        <property name="jndiTemplate" ref="myJndiTemplate"/>
    </bean>

     <bean id="jmsResponseQueue"
                class="org.springframework.jndi.JndiObjectFactoryBean"
                abstract="false" lazy-init="default" autowire="default"
                dependency-check="default">
        <property name="jndiName">
            <value>jms/ResponseQueue</value>
        </property>
        <property name="resourceRef">
            <value>false</value>
        </property>
        <property name="jndiTemplate" ref="myJndiTemplate"/>
    </bean>

We then customise Spring’s JmsTemplate with the beans configured above. Note that we will use JmsTemplate to send JMS messages later:   

<bean id="jmsTemplate"
        class="org.springframework.jms.core.JmsTemplate">
        <property name="connectionFactory" ref="jmsQueueFactory"  />
        <property name="defaultDestination" ref="jmsRequestQueue"/>
    </bean>

Last but not least, we create a Message Driven Pojo which is the WormholeActor. Note that the WormholeActor is listening to the reponse queue.


    <bean id="messageListener" class="org.azrul.osconf.jmsActors.WormholeActor" />

    <bean id="jmsContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
        <property name="connectionFactory" ref="jmsQueueFactory"/>
        <property name="destination" ref="jmsResponseQueue"/>
        <property name="messageListener" ref="messageListener" />
    </bean>

Next, we create a WormholeActor class in Scala

class WormholeActor extends Actor with MessageListener{
    def act:Unit = {
        loop
        {
            react
            {
                case msg:String =>
                    val context  = new ClassPathXmlApplicationContext(Array[String]("/org/azrul/osconf/jmsActors/client-context.xml"));
                    val jmsTemplate = context.getBean("jmsTemplate").asInstanceOf[JmsTemplate];

                    jmsTemplate.send(new MessageCreator() {
                            def createMessage(session:Session):Message={
                                val message =  session.createMapMessage;
                                message.setString("MESSAGE", msg);
                                return message;
                            }
                        });
            }
        }
    }

    def onMessage(message:Message):Unit={
        val responseMsg = message.asInstanceOf[MapMessage];
        println("-------From Listener------");
        println(responseMsg.getString("MESSAGE"));
    }
}

Basically it has two primary functions: act that reacts to Scala actor messages and onMessage that reacts to JMS messages. Note that when we receive a Scala message, we automatically send it to the JMS world (via our request queue created through our Spring config.)

Here is the MDB:

@MessageDriven(mappedName = "jms/RequestQueue", activationConfig = {
    @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
})
public class MyMDBQueueBean implements MessageListener {

    public MyMDBQueueBean() {
    }

    public void onMessage(Message message) {
        try {
            MapMessage requestMsg = (MapMessage) message;
            System.out.println("-------From MDB------");
            System.out.println(requestMsg.getString("MESSAGE"));
            System.out.println("----------------------");

            Context ctx = new InitialContext();
            ConnectionFactory connectionFactory = (ConnectionFactory) ctx.lookup("jms/QueueFactory");
            Queue queue = (Queue) ctx.lookup("jms/ResponseQueue");
            javax.jms.Connection connection = connectionFactory.createConnection();
            javax.jms.Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            MessageProducer producer = session.createProducer(queue);
            MapMessage responseMsg = session.createMapMessage();

            responseMsg.setString("MESSAGE","READ:"+requestMsg.getString("MESSAGE"));
            producer.send(responseMsg);

        } catch (NamingException ex) {
            Logger.getLogger(MyMDBQueueBean.class.getName()).log(Level.SEVERE, null, ex);
        } catch (JMSException ex) {
            Logger.getLogger(MyMDBQueueBean.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

The MDB listens to the request queue and forward any message to the response queue. Of course in your application, you may want to do some business logic between request and response. In our case, we just do this:

 

System.out.println("-------From MDB------");
System.out.println(requestMsg.getString("MESSAGE"));
System.out.println("----------------------");

 

To bootstrap it all, we need a Scala main function that will send a message to the wormhole actor:

object Main {

main(args : Array[String]) : Unit =
    {
        var wormholeActor = new WormholeActor;
        wormholeActor.start
        wormholeActor ! "I’m John Connor and if you’re listening to this you are the RESISTANCE!"

    }
}

Next, just run the MDB and run the Main object.

Note:Use Netbeans to easily create an MDB . Follow this tutorial under the topic Creating the NewMessage Message-Driven Bean

Complete source code for Actor (password: qwerty)

Dependencies:

Wednesday, June 3, 2009

OSCONF 2009: Awesomeness just got a new name!!

As if the world’s total awesomeness converged for 4 days , OSCONF was totally awesome (more awesome then some conf that starts with Tech and end with Ed). The community rocks!!

Ubuntu guys rocks!!

PHP guys (Joomla guys too) rocks!!

Sun guys rocks (although not as much, yeah yeah, I know, the Oracle thingy is probably in their mind)

Python guys rock soliidd!!

BSD guys rocks and are horny too (no no, not the other kind of horny :)) )

ADempiere guys manage to maintain their cool :P

And best of all, the lightning talks really really rock!! with total awesomeness that rocks can have :))

Everyone just plain awesome !! Yeah, everyone! Even the OpenSUSE guys. :))

Please please please make this a yearly event

Anyway, I delivered my Scala talk too. Here’s the slide

http://www.scribd.com/doc/16094125/azrulosconfkickingbuttenterprisescala

 

I’ve also done a lightning talk called Cyber Merdeka (Cyber Sovereignty)

http://www.scribd.com/doc/16094325/Cyber-Merdeka-Cyber-Sovereignity

 

I’ll make the video available if I can get it from MDeC

 

 

Me and Anthony Baxter of Google

Thursday, February 19, 2009

Unintentional user created content

A few years ago, I stumbled upon a dialog featuring Sun Microsystems' Johnathan Shwartz and a few other names (sorry too lazy to look it up).
In the dialog, one of the participants ask this question:

"Would you write a book for someone for free"

If you ask me, then my answer is no. Then come the next question.

"What about a paragraph... for free"

Well, probably,

"What about a word, just one word"

Sure.

Well, that is what Google (and Microsoft and Yahoo etc.) is doing. Google is asking all of us to write a "book". A few words a person.
This book contains the combined knowledge of all of us... well at least it contains to combined "intention" from all of us. My question is this,
are we aware that we are creating content for Google? Some of us do, most don't. This is waht I call "unintentional user created content"

Imagine now, if we have a video cam that will take movie of every aspect of our lives. Couple that video cam with a sound recorder and you can
express yourself whenever you feel like it. It will also capture your interaction with people around you. Couple that with a GPS receiver and
your location, your image, your interaction will automatically be your blog: an autoblog if you prefer.

No more messing around with computers and no more having to type things. All you have to do is ... welll ... nothing. Everything becomes a blog.
(Of course there are time when you want to shut off such device.) Now, of course all these are voluntary. Now before you dismiss this as some
fantasy I cooked up, just watch your next season American Idol. You'll see that people LOVE to put their live online. (And also, the hordes of
idiotic videos on youtube substantiate this also).

I do belive that unintentional user created content is the future. Today, we do have youtube and blogspots and twitter and whatnot, but these
"intentional" web 2.0 stuff are small fry compared to what is coming.

Sunday, June 22, 2008

The perils of HR

Every working adult and their cats would have a story about how much they dislike, nay, abhor, HR (and in some places, things are so bad that even HR folks have their own HR story to tell and I kid you not). So is it a wonder that someone actually writes “Why They Hate HR? [http://www.fastcompany.com/magazine/97/open_hr.html]”.

Just like everyone else I have my story to tell and I also have my own theory why HR just doesn't work. Mind you that this story is not my worst brush with HR, but it demonstrates, with simplicity, the abysmal state of HR.

This happens to me on one of my previous job. The story starts when my project team applied to go to this one training. You see, my team uses this software platform in our project. The platform (let us call it Platform X) is ubiquitously present all along the system we are developing. I.E. the GUI guys would be interacting with Platform X as much as the database guys or the middleware guys. Due to that, we all applied to go Platform X training and guess what, we got rejected because... wait for it... the policy says only one person from one project can go to a particular training.

Apparently, a few years ago (before I joined the company), a group of 5 employees from the same project applied to go to a 5 day training. Now instead of staying for the whole 5 days, each one of them would take turn to go to the training while the others enjoyed a 'paid vacation'. The HR director found out and decrees a law that 'hence forth, thy projects can only send one soul to training’. I guess, in some projects in makes sense, furthermore it does save the company a few cents on training expenses. But in my case (and I'm sure the same goes with many other projects) this law just doesn't make sense. If we send a GUI guy to the training, as much as he would like to understand how Platform X interact with our distributed multi agent based high performance cache system, I don't think he can. The same goes if we send a middleware guy, he would be clueless on how Platform X interact with the GUI stuff. Now to make matters worse, there was a change of requirement and we now need to include mobile devices components in our project and guess what? The mobile stuff are also ... going to interact with Platform X.

We wrote an appeal letter to HR saying that if we don't get this training, there's a high probability that the project will fail. The lady officer assigned to our case informed us that there's nothing she can do, apparently the decreed law has made its way into our HR system as a 'business rule' and it'll take a whole lot more than our collective pretty faces to change that. Sure we can make the appeal go all the way to the CEO but that'll take too much time and that is a luxury we didn't have.

All and all, due to the importance of the project, the client agreed to sponsor the training (with a huge reduction in fee and a large red line going through our Gantt chart cutting our timeline by almost half) and it was worth it. The training went well, we learnt a lot about Platform X but things could be better. Due to the reduction in fees, we had to let go of a few engineers (some of them are quite good) and due to the reduction in time, we need to rush like crazy. (In fact we were a bit off schedule in the end) What if HR would just swallow its pride and help let us go to that training we asked, Ok so what is some of our project team skip a day of the training... I'm sure that would actually cost less that what we have to 'pay' in the end.

And herein lies the problems with HR.

1) Business Process Over-Automation

How many times have you been to HR to complaint about something and they would simply dismiss you by saying 'it is already in the system, I can't do anything about it'. Well, if you're anything like me, that is almost the single most quoted excuse ever... OK, I lied, the single most quoted excuse is actually 'The manager's on leave' but 'it is the system' excuse must be one of the top 10 if anything.

I call this over-automation. Don't get me wrong, I'm all for automation but when the business rule goes something like: 'If the employee has been working less than 2 years and the project's duration is less than a year and the employee's mother is a keen supporter of Manchester United and the employee don't like sushi, then deny him any access to training'. You know that there's something wrong. Over automation is when rules 'hard coded’ into the HR system just doesn't make sense and yet it is religiously enforced because it's 'policy'. Now, over automation in itself is still OK, what makes things worse is over-automation plus paranoia. This brings us to the second problem.


2) Assuming the worst in your employee

How are HR business rules created? Simple, they just observe the employees, find the worst thing that they can do, assume everyone else will also be as bad and create rules against that.

Stupid HR rules is all about assuming that you are evil somehow, that you will abuse the system and you will run the company bankrupt with your lofty 'paid vacations' and 'non-cost-saving' attitude. Will there be abuses? Sure. Will the collective cost of failed projects and low morale make up to the cost of those abuses? I don't know; in fact, don't ask HR, they won't know either. And therein lies a problem. To concretely study each business rule in the system and find out its actual cost has never been attempted. In fact, everyone assumes that HR is omnipotent and will not make mistakes. Well, here's news for you HR does make mistakes, again and again.

Now what should HR do instead? Shouldn’t they have business rules? They should but HR officers should be given enough authority to make exceptions. In fact they should be encouraged to make exceptions because we are all different! We have different talents and different needs. Ned in accounting has a baby boy who suffers from thalassaemia. He should get more 'emergency leave' than Sue from engineering who is single. Consideration should be given on a case by case basis because HR stands for HUMAN resource and not HIGHLY AUTOMATED resource.

But how do you avoid abuses? Now since HR has this system in place, couldn't they measure how much a decision improves or not a project for example? You cannot improve what you cannot measure so HR should start making exceptions and start measuring if things are really abused or if it is just plain paranoia of some lonely HR manager still clinging tightly to his pillow, scared stiffed that the boogeyman is going to come out of the closet tonight.

Wednesday, May 21, 2008

World Congress On IT -- WCIT

I went o WCIT 2008 at KL Convention Center as a delegate and had to suffer a few days of "ye old boring diatribe and ego venting" almost all the way through the seminar. I mean, come on!, if you're an avid IT blog reader (and writer) and you read forums such as dzone, zdnet, theserverside, or even slashdot every single day, there is nothing new here. There are a few gems though, the "Future of the Internet" forum was really something else. The WCIT Great Debate (well, it's not much aof a debate since all the debaters agree with each other all the time) was also insightful. The final keynote by Vonton Cerf (the interplanetary internet googler) was also very interesting

My real beef is that most of the presentations touch only the surface of any particular issue and use up all the time given to retouch the same surface over and over again (and desperately hoping that the audiences would get some kind of an orgasm from this). I mean, there wasn't really a session where things are scrutinized to the nearest atom and problems are disected like dead frogs on some 15 year old science students lab table (and yeah those 15 year olds can really disect frogs). Even the CIO breakout sessions (well I attended the FIS session) didn't really go that deep.

Another dispointing thing is that, no technical session was done AT ALL. I mean, come on!. It's World Congress of Information Technology and no "technology related track was done. Couldn't they run a few tracks on some general tech issues. You know things like building next the generation of internet apps or whatever. But nothing at all, rien, nada.
Now before you jump your guns and say, "hey Azrul, this is a business seminar, get over it!" I would like to remind you that they have a PC Fair going on downstairs at the convention center. (Of course WCIT was co sponsored by PICOM whose hammer (read PC Fair) is applied to every single problem they have... What? earthquake in China? let's do a fundraiser... and throw in a PC Fair for good measure). Now, is PC Fair, full of pimple head bloggers wannabe drolling over some MP4 player, is more business related than "Tools and techniques to build the next generation of internet application"? Yeah... of course... NOT!

I was also a bit disappointed by the chief ministers trying to lure investors to their respective states. During their speeches, they were reading from a text... I mean, come on, reading?! Gosh! you guys are politicians for God sake. Use your public speaking skills (how on earth did you guys win the last election anyway?). Throw away the freaking text your secretary made the night before and speak from your heart. What can we expect from you. You track record. Your resources etc. If things are lacking what do you do to improve the situation, and last but not least... give us your phone number and email so that we can contact you. If I want to invest in a company, I want speak to the boss. Not some "account manager" you hired yesterday. The same goes with investing to a state.

Lastly, why the heck did they call WCIT as "the Olympics of IT" anyway? . Well, if the Olympics of IT consist mostly of sitting down, snorring, chatting and eating good food (and the food was good), should one wonder why IT workers are getting fatter?