Posts

Showing posts from March, 2008

C# type inference

While I work mainly in a Java shop, I continue to be impressed by what Anders Hejlsberg, chief architect of C#, brings to the table to a language which in my mind has always represented Java done right. I do wonder however, how come they did not take the concept of type inference just a little bit further. Local variable type inference This feature of C# 3.0 basically allows you to omit the declaration which, especially when generics is involved, causes a lot of repetition and long lines of code: Dictionary<int, IEnumerable<decimal>> myCollection = new Dictionary<int, IEnumerable<decimal>>(); Which can be reduced to this: var myCollection = new Dictionary<int, IEnumerable<decimal>>(); No late binding is taking place, the compiler simply infers the actual type and substitutes var with it. No method return type inference? Some languages operates with the concept of tuples, a way of returning multiple values without having to wrap them in an arr

Java Puzzler: How low can you go?

Any seasoned Java developer would know of the seminal books Effective Java and Java Puzzlers by Joshua Bloch. The latter covering pitfalls and corner cases of the Java language, listing some 95 different examples of traps to watch out for in your daily work. Java puzzlers While a great read for toilet visits, unlike Effective Java, I don't consider Java Puzzlers particularly essential material to know as a developer. Not because there isn't anything to learn, but because there are many other pitfalls of the language not mentioned which you are just as likely to encounter before many of the exotic ones mentioned in the book. I recently ran into another one of this kind, which I will now describe. How low can you go? Take a look at the following snippet, which is a more flexible version of Math.max() which tries to find the largest Double in an array: System.out.println( max(0.0, -1.0, -2.0) ); public static double max(double... candidates) { assert(candidates.length >

Gee... Another one?

Hey everyone and no one! Like so many others, I've decided to start my own blog. Up until now I've just been an avid participant in various forums, blogs and communities with all the problems associated with that. It's my desire with this blog to be able to write my opinions without having to conform to established or expected perspectives which sometimes gets me into trouble. I will also use the blog as a personal wiki, an institutional memory and a communication medium, which may or may not be of interest to others. The content will probably revolve mostly around software engineering and associated technical issues, but I reserve the right to use it as a venting space for whatever comes to mind.