Posts

Showing posts with the label Programming

@SuppressWarnings completion

Image
Why it was made Although NetBeans is capable of suggesting and auto-inserting @SuppressWarnings, it doesn't actually provide code completion or documentation for these values. Indeed, as I've blogged about before , it is tricky to track down the exact enumeration and semantics of these magic values. This is due to the fact that they are entirely dependent on the compiler and IDE. This plugin adds support for the values currently supported by NetBeans 6.1, namely "cast", "deprecation", "divzero", "empty-statement", "empty", "fallthrough", "finally", "serial" and "unchecked". It also tries to explain how and when to use them. How it was made Creating plugins for NetBeans is relatively easy if you start by grabbing existing code and have invested in the RCP book. Especially blogs like Geertjan' s and Sandip's are virtual goldmines. So for this one, I used the Geertjan's blog entr...

NetBeans on speed

Image
In the post from yesterday I was a little harsh regarding the performance of recent NetBeans versions, which seems to have taken a toll for the worse. One of the most annoying things is how much scanning and processing is going on all the time which harms responsiveness and the overall user experience. The NetBeans mailing list yielded responses like "more features requires more work" which is fair enough. However, I decided I wanted to have my cake (speed) and eat it too (features). Memory mapping to the rescue It's not exactly new. So called "RAM drives" have been used for ages to speed things up, some Linux distro's even mount the temporary files location into RAM to improve performance. We can do the same to our source checkouts to gain massive increase in throughput as well as access time. There are two easy ways to archive this out of the (Linux) box, mount a dedicated RAM drive or use the TMPFS filesystem . Sorry, Windows users will have to look els...

NetBeans: Pretty Much Unusable

NetBeans Pretty Much Unusable If you care about NetBeans and its performance, an interesting development occurred over the last 24h on the nbusers mailinglist. It seems the upcoming 6.5 release sparked a debate claiming that it's pretty much unusable . While I wouldn't go that far, there is actually some truth to the matter as experienced by my colleagues and I. A little bit of history I've been back and forth between various IDE's over the years, coming from Visual Studio (VB/C/C#) I've been rather spoiled in regard to syntax highlighting, code completion and debugging. In fact I remember back in 2001 how I was convinced into doing a college project in Java, primarily because of the assistance offered by Visual Studio J++. At that time, no tool provided these kind of features (although Forte and JBuilder tried). In this day and age, things looks quite different of course. SUN finally realized that it's worth having great tools (some would argue they have to sol...

NetBeans plugin: Special copy/paste

Image
The very little I've had to paste code into this fairly new blog, was enough to give me the idea of creating an extension to NetBeans which would help to remedy this formatting nightmare. Now, in my world, there's approximately a 100:1 ratio between idea and actual realization, so I'd have to salute the awesome OpenIDE API's for making this possible spending just a few late nights and taking just 200 lines of code. Without further ado, I present, my first NetBeans plugin . Special copy/paste The plugin will add a couple of new actions to the context-sensitive popup-menu of the source editor, which will allow you to copy the selected text as preformatted HTML, as well as a CSS version which will preserve the formatting used in NetBeans. Using the "Copy as HTML and CSS" menu as in the above screen dump will result in you being able to paste it directly into a website/wiki/blog and have it display like this: /** * @param args the command line arguments ...

Type registry strategy pattern

One pattern that I have often seen applied in Java, is the one where you plug-in and register a handler for a given type of object to thereby supply a specific behavior for it. For instance, this is often used in order to render, edit and validate elements of various visual components in Swing, such as the JTable. I am unaware of any official name for this mechanism, but it appears to be a combination of Martin Fowlers Registry Pattern and the GoF Strategy pattern so I like to think of it as the Type registry strategy pattern. Legacy example Conditional behavior is encapsulated by some common interface, which provides the mechanism for dispatching to elsewhere, responsible for applying a concrete strategy. An example is this format handler, which allows an object to be formatted as a String: 1 interface Handler 2 { 3 String format(Object object); 4 } And an API, capable of associating handlers for various Object types registered and dispatching to these: 5 class SomeAPI 6 {...

@SuppressWarnings values

Image
Meta-data and how to associate it has always been a bit of a confusing topic in Java. For instance, the transient modifier is really a kind of marker annotation, as is the @deprecated javadoc tag compilers are also required to process, as is the marker interface Serializable. Then in JDK 1.5, a dedicated annotation facility was added, probably in light of the success of C#'s attributes. One of the first practical uses of annotations appears to be as a way to suppress compiler warnings. @SuppressWarnings This build-in annotation allows the developer to signal a respecting compiler that it should forgo a particular warning. It can be applied in front of a type, a field, a method, a parameter, a constructor as well as a local variable. It is up to the compiler to make sense of whatever you put inside the String, the only value mandated by the JLS is the "unchecked". Compilers as well as IDE's will typically implement each their own set of warning types, the Eclipse IDE d...

Know thy acronyms

Maybe it's caused by the passing of time, maybe it's because of its open nature or maybe it's simply because people like to make them up. In any event, few technologies in computing are as littered with acronyms as Java is. Just for fun, while eating lunch (yeah I know it's bad habit) I compiled a list off the top of my head of what an average developer might be subjected to, when tracking technologies in the Java space. AWT - Abstract Window Toolkit (UI) BGGA - Gilad Bracha, Neal Gafter, James Gosling, and Peter von der Ahe (Closures) CICE - Concise Instance Creation Expressions (Closures) EAR - Enterprise ARchive (Packaging) EDT - Event Dispatching Thread (Lingo) EJB - Enterprice Java Beans (Packaging/technology) FCM - First Class Methods (Closures) JAR - Java ARchive (Packaging) JAX-RPC - Java API for Xml-based Remote Procedure Call JAX-RS - The Java API for RESTful Web Services JAX-WS - Java API for Xml-based Web Services JAXB - Java Archtecture for Xml Binding JAXP...

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 > ...