Tuesday, November 23, 2010

Use compiler to catch new enum value not covered in "switch"

This old trick shines more and more when our project's code base grew over million+ lines. I have to put it on the web one more time just in case there is a developer out there haven't seen this.

Basically you can set the compiler to generate compilation errors when there are enum values not covered in switch block. So that when a new value is added to an enum class, every switch statement on this enum class will get a compilation error. This way it is easier to find and add corresponding cases, and it is impossible to ignore them. :)

To make this work, you have to do (or not do) two things:

  1. DO NOT use "default" case when you do switch on enum values.
  2. Set your compiler to generate ERROR instead of ignore enum values not covered in switch. In eclipse (the greatest IDE), it is here:

Thursday, February 25, 2010

hey gmail, what is up? I am a little worried about you.

I am a loyal fan of gmail ever since its first beta version. I jumped all over the web to get an invitation back in 2004. A couple years ago when my geeky friends switched their companies' email system to gmail, I was a supporter too.

But a couple things happened recently, which made me not so sure no more. Starting later last year I began to receive emails sent to another address that I had no relation with. Apparently gmail is forwarding others email into my inbox, all junk though. But if it is doing this, how do I know it is not forwarding my email to others?

Another hiccup happened this week. I pop emails from several alias accounts. And mails start showing up late, 2 or 3 days late, as a consequence I wasn't able to get back to people in time.

Google pretty much runs my life. I wish the best for them. But with the buzz burns still all over the web, this kind of misbehaviours on email application is worrisome. Even the giant can bite more than it can chew, sometimes. So this is a shout out to the gmail team, check it out.

Tuesday, February 16, 2010

JBoss Tools Eclipse plugin content assist lessons

I learned a couple lessons in the process of making JBoss Tools Eclipse plug-in to do content assist (where you type ctrl-space to get code suggestions). This is mostly about JSF component libraries.

First of all, in order to get content assist for JSF components, you must have the TLD file in your class path. We are using Richfaces libraries, and all its components get content assist. The ones I had trouble with are jsf-core and jsf-html, the f: and h: tags by default. Oddly enough though, with all the JSF libraries I have on my class path, none of them had packaged the TLDs for these two. I made a jar file and put jsf-core.tld and jsf-html.tld in the META-INF folder to get this working.

Another lesson learned is that the name space URI has to match exactly with the TLD's. I mean exactly. Kind of obvious, but easy to miss when trouble shooting. I added Openfaces like this xmlns:o="http://openfaces.org" in the first place and it didn't work, because it is expecting a "/" at the end. So the correct syntax is xmlns:o="http://openfaces.org/"

Sunday, February 14, 2010

Build Synergy in a new ubuntu system

Had to jump through quite a few hoops to get synergy to compile on a fresh ubuntu 9.10 box, including gcc-cpp and libxtst stuff. The most annoying error message is the 'You must have the XTest library to build synergy' one, it just won't go away after I got all the xtest, libxtst, libxest, libxcb-xtest crap installed.

Well, here is all it takes: (copied from synergy-plus)

By the time I figured this out, I already moved on to synergy-plus, which is much easier.

Thursday, January 28, 2010

jQuery goodies that I will try in next project

jqGrid, the data grid plugin with editing, searching, paging, and a lot more features

iconDock, good idea to put a bunch of icon/buttons on the page

Horizontal Accordion, just cool