Search This Blog

Monday, February 11, 2013

Evaluating new frameworks, libraries and technologies

Introduction

New frameworks and libraries are developed so fast it is nearly impossible to evaluate all of them. This can make it hard to judge whether a particular technology is worth investing (time) in. This post gives you some tips which may help when evaluating new technology.

Conceptual level

Although there are many different libraries and frameworks, most of them can be grouped based on some conceptual differentiation. The following concepts may help to give an idea of this conceptual differentiation:

  • Component based frameworks
  • Request/response based frameworks
  • Object Relational Mapping
  • Map-reduce
  • Key-value stores
  • Messaging
  • And many more... 

When evaluating a specific technology it helps to identify to which concept or concepts it belongs. Before further analysis of a particular technology, make sure you understand the concepts. Without this understanding it is almost impossible to do an objective analysis. Understanding these concepts requires an investment in time. Usually in the form of reading, watching presentations, experimenting, training and talking to others. Understanding the concepts will make it easier to objectively evaluate a particular technology.

Simpler is usually better


One of the key actions in evaluating a particular technology is to determine if and how it satisfies the given requirements. A lot of frameworks and libraries provide a 1 minute introduction, a 5 minute guide, a 30 minute tutorial and more. I really like these sorts of introductions since it usually gets you up-to-speed quickly. Besides getting up-to-speed quickly, a more important factor is the complexity of the given solution. I really like the idea of "Make things as simple as possible, but not simpler".

The starter guides, as mentioned above, present the readers with a relatively simple case or problem to demonstrate the key features of a given technology. To find out if a certain technology will fit I suggest to look at the complexity of the solution for the cases in the introduction guides.

In my opinion, if the solution for a relatively simple case or problem is complex and not easy to understand, how can a solution to a more complex problem be easy to understand? This complexity comes of course in various flavours:

  • How much code do I need to write to get even the simplest things done?
  • How many classes do I need to extend? 
  • What and how much configuration should I write?
  • What is the quality of the documentation?
  • How can I easily test my solution?
  • Etc.

If the solution to a simple problem is indeed simple and easy to understand, it is worth investigating more time to find out if the technology satisfies your requirements. If the solution to a simple problem is not simple and not easy to understand, think long and hard before investing more time in it.

Conclusion


New frameworks and libraries are developed so fast it is nearly impossible to evaluate all of them. To speed up the decision process make sure you understand the technology at the conceptual level. Once you understand the conceptual level, experiment with the technology using introduction guides if they are available.

If, from those introduction guides, solutions to a given problem are simple and easy to understand, it may be well worth spending more time investigating the particular technology for more complex problems. If not, proceed with care.

As always, your mileage may vary.

Tuesday, November 13, 2012

Sample generated melodies

Based on some questions, I uploaded a couple of sample melodies in MP3 format which are generated by my genetic algorithms melody generator. The generated sample melodies can be found here: http://code.google.com/p/melodycomposition/downloads/list.

The original article of the melody generator can be found here: Melody generator

Thursday, October 18, 2012

Kinect within VMWare

Recently Microsoft announces the availability of the Kinect 1.6 SDK. One of the big enhancements in this release is the support for the Kinect device within a virtual machine (VMWare or Parallels)!

For a client we developed a Kinect application which was shown at the Dutch Floriade festival. More details about this project in a next post.

The problem with the old Kinect SDK was the inability to use the Kinect within a virtual machine. Because of this I had to create a bootcamp partition and install Windows on it just for the sole purpose of Kinect development. The 1.6 SDK solves this!

Below are the results of my tests with the Kinect within VMWare. I used the following system configuration to test on:
  1. MacBook pro 2011 with 2Ghz core i7 and 8GB RAM..
  2. OSX Mountain Lion.
  3. VMWare Fusion 5 running Windows 7.
  4. Visual Studio Express 2012.
  5. Kinect 1.6 SDK.
First I tested the above setup with the Xbox Kinect. This did not work which I more or less expected since Mircosoft wants to push the Kinect for Windows for Kinect development.

Next I tested was the Kinect for Windows. After I connected the device I started the Shape Game sample application. The device was found and worked immediately! I also tested the Kinect with our own application and this also worked as expected.

Ont thing I noticed was that both applications did not run as smooth as when I ran the application under bootcamp. After examing my virtual machine settings I noticed I had given it only 1 cpu core (out of the available 8). This could be the problem. When I changed the maximum number of cpu cores the virtual machine may use to 4, things ran much smoother. There was no noticeable difference when running within a virtual machine or bootcamp. 

For more information about the 1.6 SDK see: http://msdn.microsoft.com/en-us/library/jj663803.aspx#SDK_1pt6_M2.

Conclusion
The new Kinect 1.6 SDK does work within a virtual machine if the Kinect for Windows is used.


Thursday, October 4, 2012

IntelliJ SSR: replace constructors

Suppose you have a large codebase which uses a particular class named SomeClass (nice descriptive name :)). SomeClass has one constructor:

public SomeClass(String a, String b, String c, String d) {
    // Do something
}

This constructor is used at various places in the codebase.

At some point in time an update to SomeClass is made which introduced another constructor:

public SomeClass(String a, String b) {
    // Do something
}


Lets assume you want all calls to the 4 argument constructor to be replaced by the 2 argument constructor. The arguments of the 4 argument constructor should be used in the 2 argument constructor in the following way: new SomeClass(1, 2, 3, 4) becomes new SomeClass(3, 1).

See the following example:


public class UsageOfSomeClass {
    private SomeClass instance_1 = new SomeClass("a", "b", "c", "d");
    private SomeClass instance_2 = new SomeClass("d", "e", "f", "g");
    private SomeClass instance_3 = new SomeClass("h", "i", "j", "k");

    public static void main(String[] args) {
        SomeClass someClass = new SomeClass("1", "2", "3", "4");
    }
}

Should become:

public class UsageOfSomeClass {
    private SomeClass instance_1 = new SomeClass("c", "a");
    private SomeClass instance_2 = new SomeClass("f", "d");
    private SomeClass instance_3 = new SomeClass("j", "h");

    public static void main(String[] args) {
        SomeClass someClass = new SomeClass("3", "1");
    }
}

You can achive the following for an entire codebase with one single structural search and replace action. Use the following templates to achieve this:

Search template: new SomeClass($arg1$, $arg2$, $arg3$, $arg4$)
Replace tempalte: new SomeClass($arg3$, $arg1$)

Hit find and Replace All. Thats it!

Sunday, September 9, 2012

IntelliJ: HTML and structural search and replace

I was asked to do some quick fix on some website. The website used a lot of table structures for laying out the page. To give an impression, the page had more than 50 tables each with 4 columns and 20+ rows.

There was no external CSS used. All styling of the tables was done with attributes or inline style elements. The styling was also not consistent throughout the page so each table looked slightly different.

Here is an example:

<table>
    <tr>
        <td width="200px">Some text</td>
        <td width="221px">More text</td>
        <td width="300px" height="100px">Example</td>
        <td style="width: 210px;">HelloWorld</td>
        <td style="width: 190px;">More text</td>
        <td id="test" style="width: 222px;"></td>
        <td id="test2" class="right" style="width: 200px;">Java</td>
    </tr>
</table>

Without rewriting the whole site at once I wanted to remove all the inline styles so I could use css to style all the tables the same. That at least looked more attractive in the short run while in the long run we could focus on a complete redesign of the site.

The first thing I wanted to do was replace all the td elements with inline styling with plain, empty td elements. As written in my previous posts, IntelliJ's structural search and replace features fits this use case nicely.

In the structural search and replace dialog I used the following:

Search template:

<td $width$="$value$" $style$="$value$">$text$</td>

Replace template:
<td>$text$</td>

In the Edit variables dialog I specified a minimum count of zero for the $width$, $style$ and $text$ variable. The $value$ variable has a minimum count of one. For all variables I used a maximum count of one.

The template searches for all td elements with zero or one width or style attributes (or both) and with or without text. The replace template replaces the td found with the search template in a plain td. The output of the HTML after the search and replace is run is:

<table>
    <tr>
        <td>Some text</td>
        <td>More text</td>
        <td>Example</td>
        <td>HelloWorld</td>
        <td>More text</td>
        <td></td>
        <td>Java</td>
    </tr>
</table>

After this replacement I could just insert the appropriate CSS and style all tables consistently. Without structural search and replace I think such scenario's take considerably longer to execute.

Hope you enjoyed it.

If you have other interesting structural search and replace use cases please share them.

Saturday, August 11, 2012

IntelliJ: customize the editor

In this post I explain the modifications I make in the configuration of the IntelliJ editor and project window. With these modifications I find it even more easier to work with source code.

I make the following modifications to the IntelliJ editor settings:

Show method separators
This option shows horizontal lines between methods with which seperate methods are easily identified. To enable method separators do the following:
  1. Open the settings window
  2. Open Editor -> appearance and check Show method separators.
High light usages of element at caret
This option highlights all usages of the element where the caret is positioned. To enable this option:
  1. Open the settings window
  2. Click Editor and check Highlight usages of element ar caret.
Highlight current scope
This option highlights the current scope of a code block in the left gutter. To enable this option:
  1. Open the settings window
  2. Click Editor and check Highlight current scope.
Disable allow placement of caret after end of line
To disable the placement of the caret after the end of a line do the following:
  1. Open the settings window
  2. Click Editor and uncheck Allow placement of caret after end of line.
Use and show soft wraps
Soft wraps are useful when the editor window is smaller than the actual line length that can be displayed. The lines that exceed the editor window wraps to the following line.
  1. Open the settings window
  2. Click Editor and check use soft wraps in editor and Show all soft wraps.
Tab limit
The tab limit limits the maximum open tabs so the tabs remain manageable. To limit the maximum open tabs:
  1. Open the settings window
  2. Click Editor -> Editor Tabs and specify a tab limit.
Optimize imports on the fly
This option automatically optimizes the imports when you are typing code. To enable this option:
  1. Open the settings window
  2. Click Editor -> Auto Import and check Optimize imports on the fly
The results of the above modifications can be seen in the screenshot below. I made the editor window smaller than usual to demonstrate the soft wraps.


In the project window I make the following modifications:

Autoscroll to source
This option lets me autoscroll to the editor window when a file is clicked.

Flatten packages
Abbreviate qualified package names
The above two option give a nice compact but complete overview of the package structure with abbreviated names. This can be seen in the following screenshot:



Let me know which options you use.

Sunday, August 5, 2012

IntelliJ: Final parameters and variables


Different teams require different coding styles and source code metrics. We have for example a rule which states that all method parameters should be final. Without going to discuss this rule (since your mileage may vary) I will show how IntelliJ can be used to enforce this rule.

There are two use cases here:
  1. Adding the final keyword to all methods generated with IntelliJ.
  2. Add the final keyword to existing methods.

To add the final keyword to parameters of generated methods do the following:
  1. Open up the Project Settings dialog and navigate to Code Style -> Java.
  2. Click the Code Generation tab.
  3. In here you will find the Final modifier section.
  4. Check the "Make generated parameters final" option.

If you now generate methods, IntelliJ will insert the final keyword before every parameter.

Besides adding the final keyword to every parameter in generated methods you can also add the final keyword to parameters in existing methods. To do this, do the following:
  1. Open up the settings dialog and click Inspections (in Project settings)
  2. Click copy to copy the Project default inspections and name the profile anything you want.
  3. Click the Rest to Empty button to disable all inspections. Disabling all inspections is a quick way to only focus on a specific inspection if you want to apply just that specific inspection.
  4. Enter 'final' in the search box
  5. Under the "Code style issues" check the following rule: "Local variable or parameter can be final".
  6. On the left make sure the option "Report method parameters" and/or "Report Local Variables".
  7. Click OK.
  8. Click Analyse -> Inspect code in the menu.
  9. Make sure you select the Whole project and select the profile created in step 2.
  10. Click OK.
  11. In the inspection dialog you see all methods where the parameter could be final.
  12. Right click the inspection and click "Apply fix 'Accept suggested final modifier'" to add the final modifier to all method parameters where it can be final.

Please note that the inspection does not add the final keyword to parameters which are reassigned since this gives compile errors. You could argue if this should be included in the inspection as well. I personally feel this can be handy to add final to all parameters regardless if they are changed or not. You can then afterwards fix all compile time issues you may have.