Shonzilla, a pattern-seeking animal

Life is a game of patterns and chance, and those who play well will win.

Feeds
Add to Technorati Favorites


Twitter

See also (via Entrecard)

programming coupons powered by RetailMeNot.com

Wed Jun 10

Extended code folding in Eclipse

The problem

I program Java. I use Eclipse to do it. I like concise code. I work with open-source projects. Sometimes I need to read someone else’s code. Sometimes (more so than not) people write ugly code or hard-to-read code at least. When I say “ugly” and “hard-to-read” I usually think of long methods.

Is there a solution?

If you fit the above description then you might want to use code folding. If you had a fair share of navigating through code, you probably already know about it. In a nutshell, code folding is an IDE feature which allows you to collapse (and later expand) a block of code that you do not want to look at all the times, thus leaving more screen real-estate for looking at code that matter to you at a given moment. Sounds useful? Well, it is!

However, you may not be happy with the code folding support bundled with Eclipse since it works with (nested) classes, methods but does not work with control flow structures (if, while, for, try-catch-finally, etc.). This full-blown code folding support that includes any code block including control flow structures I call extended code folding. You may have seen NetBeans and other IDEs sporting this feature and you wished you had it in Eclipse, your favorite IDE.

Solution indeed

Well, there’s a solution for this missing feature in the form of Eclipse plugin called Coffee Bytes Code Folding over at RealJenius.com. All you need to do is add the following update site:

http://eclipse.realjenius.com/update-site
Once installed go Preferences->Java->Editor->Folding and in Select folding to use drop-down menu choose newly installed Coffee Bytes Java Folding. This plugin, just as Eclipse’s built-in code folding support, allows you to see the folded code by hovering your mouse over a plus sign. While I’m there, let me suggest you to turn on line numbers via Preferences->General->Editors->Text Editors->Show line numbers as it will make it easier to not only recognize folded code sections but also to tell what line are you looking at without actually having to click at the precise line in code and read the number from status bar. This is good for linking compiler/run-time errors and what line your colleague is talking about with less effort in exchange for some 20-30 pixels. I also recommend using Modern icons for plus/minus folding handles so that you can easily distinguish whether you’re using extended or built-in code folding.

After using this plugin for a couple of minutes, I’ve noticed one thing I didn’t like. When a code block is folded, braces (a.k.a. curve brackets) are not hidden as they are with the built-in Eclipse code folder. Namely, the closing brace remains standing in a separate line thus needlessly wasting one line without providing any meaningful information.

Shortcuts

Shortcuts are your friends as they reduce the distance your mouse (and your hands) need to move (and programmers should do everything they can to avoid RSI). Also, each shortcut you learn improves your ninja skills. You may want to learn them:
  • Ctrl + <Numpad Plus> - Expand a single node
  • Ctrl + <Numpad Minus> - Collapse a single node
  • Ctrl + <Numpad Multiply> - Expand (toggle) all nodes
  • Ctrl + <Numpad Divide> - Toggle folding (turn code folding on and off)
  • Ctrl + Shift + <Numpad Multiply> - Reset structure
  • Ctrl + Shift + <Numpad Divide> - Collapse all

Final thoughts

This plugin will also allow you to define custom regions (as Microsoft Visual Studio .NET has had since first version), which Jeff Atwood (of Coding Horror and StackOverflow fame) calls glorified comments with which I fully agree. Having that in mind and understanding that “folding is used to sweep code under the rug” in mind, you should really use code folding ONLY on other people’s code that you have no control over. At the same time, you should make sure that you do not fold your own code as you may be led to believe your code is easy to read and you’ll end up creating horribly long methods and code blocks that are hard to read. Well it will be hard to read for people not using code folding, which are many. After all, nobody should be force-fed with a bunch of crutches plugins anyway. :-)

Conclusion (and a pattern)

So what’s the takeaway here? It’s a pattern to keep in mind:
If code requires code folding, that code must be bad.
Why do I say this? Because folded code hides what’s inside thus violating Separation of concerns principle since folding hiding code may lead you to squeeze all kinds of logic inside a single folded line.

Wed Apr 8

Google App Engine for Java available - Campfire One: App Engine Redux (pt. 1)

Google App Engine availability for Java is positively great news for Java developers everywhere. This move will not only make Java a more compelling platform but will also make it easier to develop and host web applications based on Java platform. Now you can create end-to-end Java applications where even client side can be implemented using GWT (Google Web Toolkit), i.e. without touching JavaScript and its cross-browser quirks.

Furthermore, with Google supporting Java in its own cloud I believe it is also good news for the future of Java platform in general. You probably know that Sun Microsystems may be acquired by some company (IBM or HP or… ?) that may decide to switch off some of the R&D within the Java platform which, again, may not be a bad thing considering Sun’s stance with OpenJDK (“openness”), OSGi (indecisiveness), JavaFX (closed source) etc.

[via GoogleDevelopers]
Sat Mar 28

Won a JavaRanch contest - book “Unlocking Android”

I was greeted by good news in my inbox this morning.
I won a JavaRanch contest and the award is a book on Android development - Unlocking Android. :-)

The prerequisite for taking part in the contest were to contribute to Android forum, which I did. I’m guessing they did not use a completely randomized system since I got selected after writing (only) 3 or 4 posts, but rather awarded by merit. I did put some effort in writing replies that are not only useful to the original poster but to a wider community

I believe it’s always a good thing to do contribute. Sometimes it pays off by winning something tangible like this book. In the rest of cases you win something even more valuable - enthusiasm. That’s my case at least. :-)

This book we’ll continue to expand my Android library next to Professional Android Application Development from Reto Meier, which I’m reading occasionally.

Anyway, I’m eager to get my hands on this book. I will post my book review and general impressions here.

Thu Oct 23
Fri Jun 20

Java is free as a bird

After announcing at JavaOne 2006, Java and it’s 6.5 million lines of code will become free software (which later became OpenJDK) last week open sourced Java passed the entire Java TCK (Test Compatibility Kit).

Java logo

What does this mean?

It means that any Java technology company will be able to improve any part of Java framework.Due to the nature of GPL any derived work (i.e. improvement) is required to be released under the same license, thus maintaining the best-of-breed Java improvements to be available to anyone.

GNU logo

In other words, this is really good news for any Java developer and company with Java technological focus.

Richard Shaples from RedHat (full title: Director of Product Management at JBoss EAP) writes more about the history and what it means also plugging Linux distribution Fedora 9 as the first one to bundle completely free and open Java.

Go Java!

Thu May 29

Pulse smartpen from company Livescribe is another exciting product presented at JavaOne 2008.

Yes, it is powered by Java. 

Check out more videos over at Livescribe.

It’s even not insanely expensive - $150 for 1GB and $200 for 2GB version.

The second part of the Blue-ray presenattion at JavaOne 2008 featuring the one and only rock’n’roll legend Neil Young.

You need to watch him… check out the teaser picture with the first 5 out of 40+ years of experience. No one else with such a long resume can so cool.

If you haven’t already, check out the first part. 

[via YouTube]

Do you know that you can use Java to enrich Blue-ray discs to create a rich, almost game-like experience?

Here’s a presentation from JavaOne 2008 where Sun Microsystems’ CEO Jonathan Schwartz (Space Balls anyone?) living rock’n’roll legend Neil Young and two other guys present what Blue-ray and Java an achieve.

Part one of two [via YouTube]

Wed Jan 23

Advanced 2D graphics for web using Java

Here’s something for web developers out there.

If you wonder sometime why Flash is being used so much, you’re going to like this.

I guess you may have heard for GWT (Google Web Toolkit) allowing you to write AJAX application in Java. GWT allows web developers can save their valuable/expensive time by not messing with infinite intricacies of writing cross-browser DHTML pages. Instead, they can use Java programming language in design time, use their favorite IDE in debug time while seeing the visual aspect effects rendered in an applet. When all coding and debugging work is done you can have the Java application compiled it into cross-browser JavaScript and CSS (using its own Java-to-JavaScript compiler). Intriguied? Go try it out!

The main point of this article is the WVGL (Web Vector Graphics Library) that builds on top of GWT to produce pretty advanced results - 2D graphics in web browser. WVGL library offers the graphics primitives and support for the following features:

  • Affine Transformations (used frequently in graphics)
  • Component Mouse Listeners
  • Paths
  • Strokes
  • Fills
  • Groups

Click here to check out how it draws a Bezier curve in web browser esentially using Java programming language!

Cool, isn’t it?

Kudos to Nathan Matthews, the author of WVGL! Thanks to Miloš Malić for the link.

Thu Dec 6

Initial rant about Android

Thinking about Google’s Android mobile platform…

Android logo

Ever since mobile phones got the company of their younger and smarter siblings called smart phones and PDAs (PDA phones?), we’ve witnessed, used and seen development for several mobile platforms - Palm OS, Java ME, Windows Mobile, Symbian, BlackBerry, BREW, iPhone… What, no link for iPhone?! Well, nothing interesting to point here as iPhone can only be used by platform agnostic web applications (i.e. well-known CSS and AJAX slightly adapted to play/look nicely on iPhone), while a true (extensible) Apple SDK is announced for February 2008.

Now Google has entered the mobile market battlefield with it’s own mobile platform called Android. Apart from that, its core, the mobile (software) platform, has been wrapped inside an initiative called Open Handset Alliance which aims at creating a mobile ecosystem of its own which includes 34 founding members falling in five groups:

  • mobile operators - to fuel the market penetration and partnering with operators that will both resell Android handsets, offer a more integrated and Android-friendly deals, and will benefit themselves
  • software manufacturers - developing killer apps (and app clones from other platforms) that will make the best use of Android SDK,
  • commercialization companies - sort of providing the glue between hardware and software, and even more market and end users, working towards improving user experience (by providing solutions for interaction design and novel user interfaces)
  • semiconductor companies - providing chip-sets and building blocks which Android OS and apps will run
  • hardware handset manufacturers - last but not least, as they’ll need to excel in both hardware design and, more importantly with heavy competition from Apple and Nokia, in industrial design.

Open Handset Alliance


For the first time in the mobile history, which is still in its adolescent years, it seems as if there’s a mobile platform that might actually tip the point when mobile devices will take over the world of (desktop) personal computers. Apple iPhone has managed to capture the hearts of many end users and developers alike, but is still very limited due to lack of iPhone SDK. Watch this space for the iPhone vs Android rumble. A month after the release of Android, there are already some inspired attempts on Planet Nerdom of running Android on some hardware.

Android platform has a viable future from market-oriented perspective. Carl Rosenberger nicely describes the mobile landscape and why Android is advantageous. After months and months of working in an Apple-style isolation, Google has yet to prove if it has made a good bet with Android. Google has certainly made a half-brave, half-smart foray into the mobile market. Here are some reasons:

  • betting on best-of-breed (and widely accepted!) technologies:
    • Linux - the most extensible and customizable operating system
    • Java - the most popular cross-platform programming language
    • Eclipse IDE - extensible development environment conceptualized with 20-year lifespan in mind
  • using Java dialect (using Java syntax and relying on Apache Harmony) thus benefiting from the greatest developer base,
  • implementing it’s own virtual machine (called Dalvik) which is incompatible with traditional JVM with the optimization in mind - compressing binary code, increasing performance and separating programs in process,
  • for both previous reasons, Google will be getting around JCP (Java Community Process) which is controlled by Sun Microsystems and other JCP members (incl. Google)
  • much more…

Before I go into details in my further posts, I’d like to open a couple of main points when analysing Android as a viable solution for the future of mobile computing (and beyond!).

Computing power and Internet are steadily moving towards mobile devices (pun intended), location-based services seem like an obvious step forward and the new market to explode. After user accounts, online activity and social networks, location is the next user context that will allow Google to deliver more targeted ad and add new revenue models.

When thinking about what Android will can bring, it doesn’t hurt thinking two steps in advance, towards something we will call Mobile 2.0 or Web 3.0 or whatever - depending on whom you ask.

What do you think about using Android for more seamless interchange of data between devices (mobile phones, personal computers and anything else with CPU heartbeat, network connectivity and some memory)? As a random though, imagine that whatever Microsoft Surface computer will do for top company executives, Android could do for everyone else.

How about something that could also step into Web 3.0 - personalized TV programming, where set-top boxes will allow browsing of user content and streaming of user-targeted multimedia, and all that facilitated by Android mobile/set-top platform?

More ideas, not necessarily far-fetched as some I’ve mentioned, will follow…

Stay tuned and mobile!