Tuesday, February 14, 2012

Pushing the Limits in Java's Random

Dr Heinz M. Kabutz, editor of Java Specialist's Newsletter, just published another fascinating article, this time about Java's Math.random(). This time with help from Dr. Wolfgang Laun, from Vienna. You can read the whole post here:

http://www.javaspecialists.eu/archive/Issue198.html

The important information is that, to get a random number from zero to some_int, we shouldn't use this code:

(int)(Math.random() * some_int)

Instead we should use nextInt(some_int) from java.util.Random class. Since Java 7, due to concurrency, we should use:

ThreadLocalRandom.current().nextInt(some_int);

But things are not so easy. There is a bug in Java 7 versions prior to 1.7.0_02, that results in returning the same value for all threads. I strongly recommend to any professional to read the whole post and also older posts from Dr. Kabutz's newsletter.

BTW: Dr Heinz M. Kabutz is a member of Java Champion group, an exclusive group of passionate Java technology and community leaders who are community-nominated and selected under a project sponsored by Oracle.

Monday, January 30, 2012

Immutable and no unit tests

This is something I came across recently in our codebase:
 public String doSomething(SomeClass inputParameter) {
...
if(result != null)
result.trim();
return result;
}

Well as you (probably) know the method will return untrimmed result. This turned into a nasty bug found during UAT testing, which took us couple of hours to find and solve. But this type of bug could be easily found with unit tests (if written properly). This is one of the reasons why I like Test Driven Development.

The One Correct Way to do Dependency Injection

Just read nice article about dependency injection explaining why dependency should be moved to constructors, and what benefits it may bring.

The One Correct Way to do Dependency Injection

Thursday, January 26, 2012

Intro

This is my first post. It is about my motivation to start this blog and what I want to publish here.

The main reason to start my own blog is to publish things I am missing on the web. This blog will be also something like my external memory, where I will put stuff that I need only occasionally and I always forget them (like some SQL or batch scripts).

Than there is motivation to practice writing and putting my knowledge under public scrutiny - so I can learn from my mistakes. This is really hard part, I admit that I am bit (actually really) worried about putting my skills under public scrutiny. For this you will find snippets from my code and some free/open source stuff I wrote.

The main theme on this blog will be software development and everything that has something to do with it. From very technical articles to articles dealing with software development management.

Tuesday, January 24, 2012

Why "Polyglot Programming" or "Do It Yourself Programming Languages" or "Language Oriented Programming" sucks?

Few days ago I read an interesting article about multi-programming language paradigm by :

Why "Polyglot Programming" or "Do It Yourself Programming Languages" or "Language Oriented Programming" sucks?

I have to say that he is talking from my heart. I've been working in enterprise environment for last 8 years and have seen many enterprise systems. Supporting a system that is build on homegrown framework, made of multiple technologies, with almost no documentation and no support is not a nightmare, it is a journey through software development purgatory.