Lovin’ Linux? Dig This!

22. July, 2008

Want to make linux better? Ask the Linux Hater. If in doubt: He wouldn’t write 15 articles per month telling where Linux sucks if he didn’t care.


Toying With Swing

21. July, 2008

I’ve been toying with Java Swing (the UI which comes with Java in case you’re wondering) a bit lately to determine which UI to use for my ePen project. I’ll post a longer article about my findings in the next few days but for now, just a few links I’ve collected:

From LegHumped:

Then, there is the JFC Swing FAQ and of course the Java Swing Trail by Sun.

I’ve been looking for a good source on editor components. Swing Hacks looked promising but it seems to only scratch the surface like the rest.


Docs? Ask The Sphinx

16. July, 2008

If you need to generate docs for your Python projects, try Sphinx.


Java Tricks: Fastest Way to Collecting Objects in a String

11. July, 2008

The fastest way to collect a list of objects in a String in Java:

StringBuilder buffer = new StringBuilder ();
String delim = "";
for (Object o: list)
{
    buffer.append (delim);
    delim = ", "; // Avoid if(); assignment is very fast!
    buffer.append (o);
}
buffer.toString ();

Are Bad Tests Worse Than No Tests At All?

9. July, 2008

In his article “Are Bad Tests Worse Than No Tests At All?“, olivstor writes:

Are the drawbacks to bad tests worse than having no coverage at all?

I think the answer is that in the short term, even bad tests are useful. Trying to squeeze a extra life out of them beyond that, however, pays diminishing returns.

Just like other software, your tests should be built for maintenance, but in a crunch, you can punch something in that works. It’s better to have bad tests than to have untested code.

Tests are like any other code: They can go bad.

In my career, I’ve found that it’s surprisingly hard to write good tests if you have no experience in doing so. People starting to write tests make them too complex, too long, let them have too many dependencies and they take too long to run.

If you’re in such a situation, you have to face the fact that you just programmed yourself in a corner and you must spent the effort to get out of there. Tests are no magic silver bullet. They are code and follow the usual rules of coding: When it hurts, something is broken and it won’t stop hurting unless you fix it.

So in this sense, I agree that bad tests are better than no tests because they tell you early that you need to fix something. That’s what their core purpose is.

Management might argue that you’re spending too much time on testing. I’ve never had a problem to sell myself to them. I usually figure that I spend 50% of my time (or more!) writing tests and 50% actual coding – and I’m still much faster than those who write code 80% of the time or more. What’s more: when my code goes into production, it’s is rock solid or at least easy to fix when something comes up. In 99% of the cases, the things I need to fix were those which I didn’t test.

This is a positive reinforcement loop which drives me to test more and more because it stops the hurting. If your tests cost more than they seem to return, you need to fix them until you get the same positive feeling when you think about them.


MQSeries 2045: MQRC_OPTION_NOT_VALID_FOR_TYPE

8. July, 2008

While doing some work with MQSeries, I got an error “MQJE001: Completion Code 2, Reason 2045” in MQQueueManager.accessQueue() which translates to “MQRC_OPTION_NOT_VALID_FOR_TYPE”. Hm. Hey, IBM, how about adding real error messages to your products instead of having people look up odd codes in tables?

Anyway, the error means that I’m trying to open a queue for output which doesn’t support this. For example, remote queues can be opened with the option MQC.MQOO_OUTPUT but not with MQOO_BROWSE or MQOO_INPUT_AS_Q_DEF. Other queues don’t allow to read from them, i.e. you have to get rid of MQC.MQOO_INPUT_AS_Q_DEF in the openOptions.

See this page for all possible combinations: MQOPEN – Open object


TurboGears 2.0 Is On Track

8. July, 2008

There are three things which hooked me to TurboGears:

  1. Every day stuff is simple, complex stuff is possible
  2. Automatic reload after code change (no need to restart)
  3. It’s in Python

What I didn’t like is that TG 2.0 has been so quiet for so long. I’m on the Planet Turbogears RSS feed and I wasn’t sure whether 2.0 was alive or dead or whatever.

Well, it seems to be more alive than I expected and hopefully, we’ll see a 2.0 soon. In “Doing the right thing should be easy” by Mark Ramm, you can find more details.


Starting Your Own OSS Project

8. July, 2008

If you’re planning to roll your own little OSS toy project, you should read the article “Party of one: Surviving the solo open source project” by Kirill Grouchnikov. Very good points on what to do and what to avoid and why.


Fan Programming Language

26. June, 2008

Another language running on the VM which is worthwhile to check out: Fan.


Jazoon: The Closures Controversy

26. June, 2008

If you ever wanted to know if it is possible to go through 60 information-packed slides in 50 minutes: Yes, it is. I’ve been there and Joshua pulled it off in from of about 100 people, so it’s not a delusion of mine, either.

In his talk, Joshua presented a host of reasons why the BGGA proposal is a really bad idea. The key information here is “BGGA”. We all want closures and Joshua is no exception, it’s just that the BGGA proposal is like Generics on steroids and if you can’t wrap your brain about Generics wildcards, then you won’t understand BGGA closures as well.

The code in the proposal doesn’t look too bad at first glance:

{int x, int y => x+y}

Unless you try to use an array. If you did “int[] x”, you’d get an error because closures are based on generics and generics can’t handle arrays or primitives.

But the next example is better to understand why BGGA will add a new level of hell to Java which will be worse than generics:

{int,String=>Number throws IOException} xyzzy;

is translated into

interface Function1 { // system-generated
    R invoke(int x1, A2 x2) throws E;
}
Function1 xyzzy;

Doesn’t bother you because you’re never going to see this? Well, think again because if you try something that the generics type system doesn’t understand, you’ll get a generics error message like this one:

NewtonWithClosures.java:26: invoke(capture#418 of ? super {double => double}) in {capture#418 of ? super {double => double} => capture#928 of ? extends {double => double}} cannot be applied to (double)

The reason for this is that the closures are implemented using generics and without any high level support in the compiler so the compiler can’t generate a more useful error message. And this was a simple example. We all know how quickly generics get messy and for me, that means that any implementation of any new feature that is based on generics is a threat to the future of Java.

Again, I’m for closures and I use them as often as I can in Groovy but the current proposal is just a new way to make Java harder to use. Why don’t they simply change the compiler to allow to access field and method objects (from java.lang.reflect) via the class? Like so:

collect(list, Math.class.min)

If we could use Method objects like first class citizens (instead of via the horrible reflection API with it’s horde of checked exceptions), we could use Method objects as simple closures. Then, all we would need is a set of util classes for single mutable primitives and we’re done. Sure, the syntax wouldn’t be as compact but every normal Java developer would be able to understand the concept and how it’s supposed to be applied in a few hours.

If you care, here is a link to the whole set of arguments by Joshua Bloch. Read it, keeping in mind that Joshua is pro closure, he just wants to avoid a second generics debacle.