Archive for the 'a compiler' Category

ping pong programming

Wednesday, June 15th, 2005

i’ve first heard about ping pong programming somewhere in the thoughtworks corner. it’s a kind of enhancement to pair programming, but first let’s remember what pair programming was actually about:

in XP, all production code is written in pairs. 2 people sit in front of the computer. one is the driver, she has control over the keyboard and writes a test or some code. the other asks questions about what is being written and comments on the work. roles are frequently switched. the result is a higher motivation, increased velocity and an overall improved code quality - 4 eyes see more than 2 :)

now ping pong programming: it is basically pair programming with extended rules. instead of simply swapping roles from time to time the driver starts writing a test that fails. then hands the keyboard over to the other, who now has to get the test to pass, and then extend it so it fails again. switch back, make test pass, extend it, switch and so on. the result is a higher switching frequency. that way, no one keeps driving for too long. as the peers prepare the task of their respective opposite, they develop a kind of healthy competition - who can write simplest code, the most elegant test etc.

so far the theory, people who have tried it report that they wrote easier and clearer code, and generally had more fun than with just pair programming, where the frequent role switch is not enforced so sometimes one peer is driving for too long, which leads to frustration at the other side.

anyway, i’ll give it a try in the next couple of weeks, let’s see what it can do. more on this topic to come.

Tags:

programming ruby

Friday, May 27th, 2005

yeah, i’ve finally started using ruby. instead of diving into the depths of ruby on rails i decided to start with something really easy:

i had written a simple tool in java that gathers a couple of text files from the file system, does a bit of parsing and creates an index html file as well as copies those text files to a new location. it consists of 4 classes:

  • main class: gathers a list of files to start with and uses the other classes to do the rest - 47 lines
  • SceneOutput - this class parses a text file to read some descriptions and that - 137 lines
  • HtmlGenerator - generates the html file from a set of SceneOutut objects - 131 lines
  • FileHelper - methods for copying files - 82 lines

java lines: 397

i then reimplemented the whole thing using ruby (don’t ask me why). the ruby implementation consists of the same classes minus the FileHelper, simply because ruby has built in file copying (even recursive directory trees)

  • main - 22 lines
  • sceneOutput - 39 lines
  • htmlgenerator - 65 lines

ruby total: 126

well, what can i say. it’s obvious that the ruby solution uses way less code to achieve the same results. since that was my first playing around with ruby it wasn’t really faster than doing it in java, but i’m optimistic this will improve quite a lot.

for now just a list of my personal pros/cons for/against ruby:

pros

  • less code, e.g. you can implement all getters of a class in one line: attr_reader :property1, :property2 ...
  • more expressive language: instead of just an if clause in java, in ruby you have also unless (not if), which can also be written after the actuall statement, elsif statements etc.
  • blocks - instead of having to implement certain interfaces all the time you can simply pass a piece of code to a method using a block
  • less verbose - you simply don’t have to type that much, the apis are simpler to use, e.g. reading file content:
    java: FileInputStream stream = new FileInputStream("xx.txt");
    BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
    String line;
    while((line = reader.readLine()) != null) {
    doSomething();
    }
    stream.close();

    ruby:
    file = File.open("xx.txt", "r")
    file.each_line {|line|
    do_something
    }
  • more to come

cons

  • there’s no cool IDE like eclipse (or i simply don’t know any), i actually used the RDT eclipse plugin, which brings some very basic syntac checking, colored code, an outline view and a button to run ruby from within eclipse. no code completion, no documentation tooltips, no linking between classes/methods, no error checking in the editor…
  • no private methods - everything in a ruby class is public (at least i think it is, update: thanks to a comment i know better now, there are private and protected methods), confusing….
  • haven’t come across something like javadoc yet, but i think i’ve heard of something like it somewhere
  • no classloader.getResourceAsStream to load resources (the css file)
  • the sytax is more complex than the java stuff, but i got used to it
  • i wonder if there’s something like hibernate for ruby
  • probably some more things to come, but not many

conclusion

i’m not sure why but it was real fun do code in ruby, everything just runs more smoothly, is easier and faster to achieve. if there was an ide like eclipse that could mark my typos and missing commas it would be even better.

i think i’ll try to use it as often as i can from now on. and i’ll delete that java version of the tool….

btw, i’m gathering links i find useful on my del.icio.us linklist

Tags:

java decompiler for eclipse

Wednesday, May 11th, 2005

jode is an eclipse plugin that integrates a java decompiler into eclipse. no more ‘attach source’ messages when hitting a class file on source code browsing…

Tags:

ruby/rails everywhere

Friday, April 8th, 2005

the thoughtworker’s blogs are full of ruby and especially ruby on rails these days. seems like there won’t be any java programmers left in a couple of weeks. everyone just loves coding in ruby so much better than in java, and the productivity gain is said to be just crazy. i’m still looking forward to starting my own first rails project, hopefully in may.
obie fernandez also mentioned a book called the poignant guide to ruby, probably worth a read.

Tags:

chizzle - ruby ide

Friday, April 8th, 2005

chizzle is a new cross platform ruby ide written in ruby. haven’t tested it yet.

Tags:

ajax

Tuesday, March 1st, 2005

javascript is coming back to the web. the new keyword is ajax - asynchronous javascript and xml. it’s essentially about creating web apps that use javascript to load data from the web server into the page currently displayed instead of loading an entire new page, which enables a much nicer user experince. examples are google suggest, google maps and tada lists.

Tags:

unit testing, easymock

Sunday, February 6th, 2005

i wrote my first unit test that uses easymock today. easymock is a little tool that lets you easily create mock objects for your unit tests. mock objects are a kind of dummy implementation of the classes required by the class you are testing.
example: you have a class … ActionExecuter. that class takes objects that implement an Action interface and executes their execute() method.


public interface Action {
public void execute();
}
public class ActionExecuter {
public coid executeAction(Action action) {
action.execute();
}
}

you now want to test if this class really executes the execute method, so with easymock you write the following test:

public void ActionExecuterTest {
public void testExecuteAction() {
MockControl control = MockControl.createControl(Action.class);
Action action = (Action) control.getMock();
// record expected behavior
action.execute();
// indicate end of record phase
control.replay();
// run test
new ActionExecuter.executeAction(action);
// run easymock verification
control.verify();
}
}

so, you create that mock control and the mock object, which implements your Action interface. then you tell the mock object what method calls it should expect, and then you execute the class you want to test. the verify method verifies if the expectations were met.
of course you can do a lot more than this, but i hope this gives a rough idea. without easymock you’d have to implement you own Action implementation and write code to verify that the correct methods have been executed, and the correct paramaters have been passed. who’d wanna do that? :)
there is another project JMock, they specify the expected behaviour differently using string descriptions, check it out. don’t know what works better yet.

Tags:

javapolis presentations

Friday, February 4th, 2005

javalobby has put a bunch of presentations from the 2004 javapolis conference on their site. most promising (for me): spring in action, hibernate in action, eclipse in action, ejb3, j2ee without ejb … + many more.

Tags:

learn ruby

Wednesday, February 2nd, 2005

hmmm…. i’ve been thinking about it for a while, have read a couple of articles, heard people praising it as you can only praise something really good. finally i read this post and now decided: i have to learn ruby. now all i need is a bit of time (sigh) and a good starting point, probably a book, ’cause i hate reading through huge web pages.

Tags:

unit testing - jmock

Wednesday, February 2nd, 2005

i came across a tool called jmock. looks like a collection of generic mock objects so you don’t have to write mocks objects for all your unit tests - more on that after i’ve played with it a bit…

there has been a request for readings on unit testing - junit.org is a good start i guess, plus maybe one of these colorful XP books (eXtreme Programming) around, to get the motivation behind test first. i’ve read xp installed which is a nice introduction and am reading ‘planning xp’, which is - as the name suggests :) - more about he planning/management side of xp projects.

Tags: