Monday, December 7, 2009

Code coverage and Enum types

Hi,

I've been trying really hard to achieve 100% code coverage on one of the projects I'm working on right now. Pretty much all my business code showed the desired code coverage right up to the point where I introduced enumeration.

First let me explain why I wanted to get to the 100% in the first place.

Whenever I'm writing code that should be covered by unit tests (which is pretty much always nowadays) I'd like to be reminded (by either the code coverage results in CI or by the IDE) that some of the edge cases have not been tested yet. I know this might sound bad in the first place because I should only write as much code as required to satisfy the test I wrote but still - there are cases where the business code I produced does a little bit more than what's in the test. So it's a good idea to keep the 100% test coverage at all times so that once it drops below this magic number I'll notice immediately that something has been skipped.

Back to enumerations.

Those guys contain synthetic methods generated by the compiler (like valueOf and values) that do exist in the byte code but have no corresponding lines in the code itself. This means that there's more that meets the eye from the code's perspective but the code coverage tools I use (Cobertura and EclEmma) know only about byte code and they couldn't care less if the method they are testing came from the code itself or if it was dynamically generated by the compiler.

To that end, whenever I use an Enum the overall coverage drops like stone which simply looks awful.



But there's hope! One line of stupid test and all is green again.

MyEnum.valueOf(MyEnum.VALUE.toString());








I admit that the actual value of this test is minimum but the real reason to do that is to allow yourself the luxury to always react on the drop of coverage below 100% instead of manually checking every time if what's missing is really something we don't care about.

I hope this helps.

Wednesday, November 18, 2009

Microsoft PDC 2009 - first recordings available!

There's been the first recording made available from this year's PDC. It's the key note from day one. It looks like things are going to be very much thumbs up for the next year!

Java and Closures - own goal

Today in the morning there was an announcement made that closures (a feature long awaited in Java) will make it to version 7. Here you'll find some examples of how it will actually look like.

But...

To have an understanding of what closures really are useful for one must follow an example. Here's something written in C# for sorting a list of strings:

var list = new List<string>() {...content go here...};
list.Sort({ (s1, s2) => s1.Length - s2.Length });

And here's the equivalent in Java:

List list = ...
Collections.sort(list, #(String str1, String str2) {
return str1.length() - str2.length();
});

One can clearly see the intent of what the closure (a function being passed as parameters) looks like in both languages with the clear winner in succinctness being C# (or pretty much any other modern language out there). I know that java tends to be verbose on all possible counts but having a different approach for commonly understandable constructs is a bad thing all along.

One other thing that you can clearly see in the example above is the lack of type inference feature which makes the syntax even more verbose.

So when I said "own goal" in the title what I really meant is that the primary function, which is succinctness and clarity has been lost in transition.

Unfortunately we're facing yet another messed up implementation of a perfectly good idea (like generics with type erasure) in one of the most popular languages in the industry.
With this kind of mind set the end is near!

C ya!

Monday, September 28, 2009

Java 7 - a dissapointment

I've just been looking into the "features" available in J7 and I must say I'm mostly disappointed. Closures are out, properties are not yet implemented... I guess the code base must be to big to do any relevant changes to the language. Maybe it's time someone will admit that the language is going down and that there's time for Java++?

Tuesday, September 15, 2009

I Come to Bury Agile, Not to Praise It - by Alistair Cockburn

Hi all,

from all the presentations about programming methodologies I believe this one given by Alistair Cockburn at the InfoQ conference to be of particular value. It's mainly because of the fact that he discloses most of the actual patterns occurring during a software development process and shows probable solutions for the upcoming (or present) challenges that we might face.

Go check it out at Bury not praise agile

And please - have fun!!!

Monday, September 14, 2009

PostgreSQL and phpPgAdmin on Ubuntu Server

I was struggling to get the phpPgAdmin application to work on a virtual machine running Ubuntu 9.04 today. As it turns out phpPgAdmin's default installation is by default targeted at desktop environments which is by all intents and purposes stupid (to say the least).

So what's so "desktop-ish" about it? Well as it turns out the default configuration accepts connections from localhost only which is completely unusable in a server-like environment with no graphical environment and no web browser whatsoever.

The default behavior also manifests itself in a very non-verbose manner. At first the log entry

"GET /pgphpadmin HTTP/1.1" 403 268

is not saying very much. It'd be better if the error message said something more verbose and direct the user to change the access rules or better yet to have a configuration step during installation that asks for this rather than to have poke around some configuration files.

To change it's default behavior one has to edit the file /etc/apache2/conf.d/phppgadmin (which is a symbolic link to /etc/phppgadmin/apache.conf) and change the default access policy from 127.0.0.1/255.0.0.0 ::1/128 to all.
To do that simply comment out the line that reads

allow from 127.0.0.1/255.0.0.0 ::1/128

and remove the comment from one line below that reads

allow from all

That does the trick. Of course that opens the ability to connect to this server from the outside world, but since this is a server installation it's not uncommon to access it from far far away, is it?


Happy hunting!

Thursday, September 10, 2009

The size does not matter

I've just finished a very inspiring conversation with a friend of mine and I want to share the outcome with the rest of you.

So it started quite innocent. He talked how he liked the Flex framework with some server-side code, I talked about the discovery of Apache Wicket... Just a normal conversation between 2 fellow programmers.

Then after some time he expressed his bad feeling about dynamic languages and all. Well, I've asked if he'd like to see the waves of a WiFi transmitter where he immediately replayed that he ain't got a microscope laying around....

At that time it was quite obvious that he thinks of them as something that really is there. That they are something he can take for granted. That's an assumption even if on a very theoretical level. He made an assumption and to that end he expressed his behavior as dynamic.

This fact lead to a conclusion that human beings are in fact in their nature more suited to the dynamic part of programming languages than anything else. We choose to think about programming as a very static thing whereas it is completely dynamic in its very nature. We can never predict what the user will give for an input to our carefully design form, do we? We can never predict what kind of weather condition will be fed to our application's flight planning routine - it's just a wild guess that we can cope with all of that.

On a more structural level it's a lot better to define the actual interface required for the part in question to work as expected than to say that this part must definitely be of some special type. Hell, the duck and a canary are birds and are similar in a lot of different ways. Did they evolve from the same species? Maybe yes but, on the other hand, maybe not. The fact remains the same that we can talk about the wings of a duck as well as of the wings of a canary and we all know that they move more-less up and down to create some lift to allow the bird to fly!

At the end of the day both ideas (the static and the dynamic one) have their advantages and disadvantages. It's just takes the openness of one's mind to realize the similarities and advantages of both solution to pick the right one for the job.

Happy hunting!