Όσοι γνωρίζουν θα γελάσουν … πολυ!!!

Μου το έστειλε ο Δημήτρης (‘εκλεκτός’ συνάδελφος).

Εδώ και χρόνια χρησιμοποιώ το FrondEnd Plus για να κάνω decompile κλάσσεις και να βλέπω τι γίνεται “κάτω από το κάπο” όπως λένε (under the hood).

Ένα απλό παράδειγμα είναι το τί γίνεται όταν κάποιος χρησιμοποιήσει το enhanced for loop, το οποίο αποτελεί μέρος του συντακτικού από την έκδοση 1.5 και μετά. Ας πούμε λοιπόν ότι έχουμε το παρακάτω loop που γεμίιζει έναν πίνακα από αντικείμενα String με την ίδια τιμή:

String[] arrayS = new String[10];for(String s : arrayS)    s = "same string";

Κάνε compile και μετά άνοιξε το FronEnd Plus. File -> Open και επέλεξε το compiled αρχείο (.class). Θα δεις ότι ο κώδικας έχει μεταλλαχθεί στην παρακάτω μορφή:

String arrayS[] = new String[10];String arr$[] = arrayS;int len$ = arr$.length;for(int i$ = 0; i$ < len$; i$++){    String s = arr$[i$];    s = "same string";}

Όπως καταλαβαίνεις αυτό που κάνει ο compiler στα πλαίσια της βελτιστοποίησης είναι να μετατρέψει το enhanced loop σε απλό for loop αφού προηγουμένος έχει πάρει ένα reference από τον δηλωθέν πίνακα.

Το Singleton είναι ένα από τα πιο χρησιμοποιημένα design pattern για έναν προγραμματιστή java. Ο σύνηθες τρόπος αρχικοποίησης ενος Singleton, όταν πρόκειται για Lazy Loading είναι ο εξής:

String aSingleton = null;if(aSingleton == null)    aSingleton = "An Instance";return aSingleton;

Ένας πιο σύντομος τρόπος να γραφτεί το παραπάνω είναι η χρήση του ternary operator της Java.

String aSingleton = null;return  aSingleton != null ? aSingleton :  (aSingleton = "An Instance");//optimization απ' τον compiler

Καλά εντάξει δεν ανακάλυψα και τον τροχό, πιστεύω πως οι περισσότεροι προγραμματιστές java χρησιμοποιούν τον Ternary Operator όχι μόνο σε αυτήν την περίπτωση, αλλά και σε πολλές άλλες. Απλώς πιστεύω πως αξίζει κάποιος να τον χρησιμοποιεί γιατί έτσι γλυτώνει γραμμές κώδικα και συνεπώς χρόνο.

Before building my portal I searched the web for a good CMS system. There are allot of good CMS systems out there, but as a self respected java geek I was determined to find a java based one. I searched, tried and tested several of the java solutions available for free, but nothing worked quite as I hoped. I ended up to the conclusion that as far as CMSs are concerned nothing beats the php solutions (joomla, drupal, mambo etc), period!

I cannot understand why nobody tried to implement a joomla like featured java CMS. I don’t know how difficult this may be, as I haven’t tried it myself, but I would like to find out. So, another task added to my TODO list.

Anyway, after allot of frustration and disappointment I decided to base my portal on joomla and I have never looked back since. Joomla is a great, easy to use and highly configurable CMS system that will get the job done without breaking a sweat. This is why it’s my top recommendation that anyone who wants to build a website can rely on, even if (s)he doesn’t have any programming experience.