Tuesday, September 29, 2009

Words of wisdom from Master Po

I am not a big fat panda... I am THE big fat panda!

Saturday, September 26, 2009

Reading stats

Due to a nice guy that didn't stop when he had to yield, now I happen to have quite a lof of free time, so I have decided to catch up with my reading stats. I was already ahead with respect to last year, but more than three months ahead of schedule I have reached the same number of books I read last year, which is 45. The number of pages I read is slightly less than last year, as we're talking about 16791 versus 16929, which means that the books I read this year are averagely 3.06 pages shorter.

That said, I have in mind to further increase my stats, I'd like to reach Francesca, who last year read more than 100 books... though target, I don't think I'll reach it but hey, the fun is the trip, not the destination ;-)

Friday, September 11, 2009

How to deal with collations

Sadly, the need to inspect a database to find orphaned records is not uncommon. One typical query you might write would probably look like this one:

select *
from table_one
where my_key not in
select my_key
from table_two

Every now and then the keys you need to compare are strings with different collations, so a query like the one above would yield error messages. To resolve the problem you can cast one of the field:

select *
from table_one
where my_key not in
select cast (my_key as ${type}) collate ${collation}
from table_two

Obviously, ${type} and ${collation} are just placeholders. If you are using SQL Server you can execute the Transact-SQL sp_help procedure to get the informations you need for the cast:

exec sp_help table_one

Of course, numeric keys would solve the problem at its roots. But... have you ever heard of natural keys and legacy databases?

Why British people play rugby

Englishmen play rugby because they invented it. Welshmen, Irishmen and Scots play rugby because if they bashed Englishmen in any other way they'd end up in jail.

Thanks to Pancho for the hint.

Shared forlders in VirtualBox

Just a reminder... shared folders defined in VirtualBox can be accessed as network resources, e.g. if you have a Windows system you'll find them in My Network Places/Entire Network/VirtualBox Shared Folders.

For more information you can read this post (in Italian).

Thursday, September 3, 2009

How to fold code in NetBeans

NetBeans editor has always had several nice features, one of which is the possibility to fold code thus eliminating unnecessary noise when working. Normally you can collapse methods, comments, imports, javadocs, and so on just clicking the + sign on the left (or using the CTRL + KeyPad- combination). To expand the collapsed section you can obviously click on the - or use the CTRL + KeyPad+ combination.

NetBeans also offers you the possibility to arbitrarily collapse contiguous lines of code: all you have to do is select the lines you want to collapse and press ALT + Enter, thus showing available suggestions given the context (in our case
Surround with //<editor-fold defaultstate="collapsed" desc="comment">...)

I also found an interesting post on code folding, so I'd like to add my two cents on the subject.

I personally think that all imports in Java classes should be explicit, as I want to precisely know what I'm importing. If I only see a couple of lines with asterisks I might think everything is fine, but that could be hiding the fact that I'm importing a thousand classes, which is definitely a smell. That said, I think this can be slightly different, say, when using Java persistence (or in similar situations): I surely want to see all "important" imports (nice alliteration, huh?), but I might want to hide persistence related imports. This would lead me to a hybrid hiding strategy, which can be confusing, but would hide unnecessary noise in the code, which is good.

About method collapsing I pretty much agree with Dustin, but every now and then I happen to collapse method when I work, e.g. if I want to see different portions of code at the same time on a narrow screen - otherwise NetBeans has the Clone Document feature that lets you reposition a copy of the code you're working on pretty much anywhere on the screen(s) - and I cannot/don't want to move methods around. Of course there should not be too many methods between the portions of code that I want to inspect. Anyway, I always use this kind of folding as a temporary solution except for "non-important" or standard code, e.g. plain setters and getters in simple beans, unlike Dustin who likes to keep all executable code shown - even if I can see his point.