Everybody seems to be using Fitnesse or Cucumber for integration testing these days. The main idea is that users (testers/business analists and programmers) can write what your program should do in plain text. The programmer then creates a small layer of code which gets interpreted and executes your actual program to see if the specified requirements are met.
For example a (hypothetical) piece of code in Fitnesse as it could have been used in the Port of Rotterdam:
This is something the testers and product owners can read and understand. Behind this layer of text Fitnesse will try to execute pieces of code. This is left as an exercise for the programmers to complete. They’ll need to write something like:
This is where the problems start, there is a lot of room for typos. Which will send you all over the codebase constantly translating Fitnesse text like “and it reports anchor down” to “andItReportsAnchorDown” during your searches.
Also people always say, because it is ‘plain text’ the testers, analists and product owners can instantly start writing tests. But this just isn’t true… It isn’t just writing down tests/requirements, it is programming with a DSL. Normal human text isn’t good enough, it still needs some DSL structure. They’ll have to learn to program in the Fitnesse DSL language. In almost all project I’ve worked on, it is the programmers writing and maintaining tests, people from the business stay far away from Fitnesse.
If you want to refactor the scenarios/fixtures in Fitnesse you’re in for a treat. Everything is bound by name only, and renaming code for example won’t rename the DSL! Using Fitnesse ‘sounds’ very agile, but it doesn’t really make the code agile at all. Most test code I’ve worked on is fragile, very ridged and not easy to refactor. Why not take advantage of that IDE and statically typed language if the programmers are writing and maintaining the tests?
Using code instead
Today we had a “ShipIt”-day (nautical-pun intended) at work, where we’re free to work on any project for 24 hours straight and we present our findings afterwards. This boosts the creative ideas and in the long run efficiency and innovation.
After using Fitnesse now for three years we’ve become used to it, and don’t ever question its usage. Although we feel the pain of the rigid/fragile test code on a daily basis. I decided to start rethinking the way we do acceptance tests.
My goals was to make our tests:
- Simpler to write
- Easier to refactor
- Maintain the readability
- Easier to reuse
- Faster! (no DSL parsing)
This is what the initial design now looks like. The example used above would become the following:
Using Jitness (working title) the scenarios will be implemented in exactly the same way we’ve already been doing. This makes it easier to transition from Fitnesse to this code.
The only bit of ‘magic’ is the execute annotation. You can write executors like this:
A (more elaborate) sample of the output it generates, with failure:
The main advantages of using this are obviously leveraging the full potential of your IDE, including renaming/refactoring. Changing methods and classes in your production code will automatically show up as changes in Jitness. And everything is easy to refactor because it is just code! This will eventually lead to much more agile code, simpler and easier to refactor. Obviously there is one main drawback, it is harder for testers to read and write. But if they pair up with a programmer this should be no problem I think. I’d rather have the testers learn a bit of coding than the programmers learn a text DSL which leads to fragile tests.
Another big advantage is execution time, using compiled code is always faster than parsing plain text or HTML at runtime. Also this code is compiled during the build, so there is no need for additional classpath (Maven) plugins. I’m really fond of the idea to use code to describe the tests, and I’m very curious how my colleagues are going to rate this tomorrow when we demo the “ShipIt” ideas. With a couple of more days work this can be fully tested and made robust enough to start using it and maybe even open source it.
What are your thoughts? Any ideas about improving the API? Should we just keep using Fitnesse/Cucumber or any other alternative DSL instead?
Programmers need more ethics.
And I’m not talking about ‘craftsmanship’ ethics such as “always make clean code”, “be agile” or “coffee should be consumed pure and black”.
No, I’m talking about real ethics:
Ethics, also known as moral philosophy, is a branch of philosophy that involves systematizing, defending and recommending concepts of right and wrong conduct.
Almost all the programmers I know are very active online, and all of them are condemning the US government project called PRISM. It is a huge electronic surveillance program, recently revealed by Edward Snowden. This program collects (all) data from a huge list of international websites such as Google, Facebook, AOL, Apple, Yahoo, Microsoft, and more.
One can only imagine the magnitude of this project, it handles a humongous amount of data and it would have to filter and match the data. It will have a lot of (secret) API’s and other methods of collecting the data. And this is all created by…. us programmers!
Just say no…
Why would somebody help the government in making these applications? I ethically wouldn’t think about programming this. And I’m serious about it, I’ve already turned down two projects in my young career because of an ethical standpoint:
- Helping to tweak an algorithm for the Dutch government for missile guidance (it would have been a cool project!)
- A project for a telecom company doing deep packet inspection, enabling them to ask subscription costs for (free) mobile apps
(such as WhatsApp)
Both these projects might influence my own, or other people’s life in a negative way, and I refuse to help people do that. It’s like being an arms dealer or gun manufacturer condemning the use of weapons. It would feel like selling a crowbar to a thief, making a bit of money, while actually enabling them to break in.
- I won’t write code which helps/enables people to harm others
- I won’t write code which will limit other people’s freedom
- I won’t work for companies using software patents to bully/attack other people and companies
If you have any good additions to the list, please drop a comment!
Last year I attended the first Devoxx4Kids in Gent (Belgium). It is a day where programmers introduce children aged 10 to 14 to programming. That day we used Scratch (a fun online programming framework), Lego Mindstorms and a Mars rover (with emulation). And it was a blast!
Once I returned and edited this video and showed it to my colleagues we quickly came to the conclusion: We need to organize a Dutch version!
Edwin (a JPoint colleague) and I tried a couple of contacts and found a willing foe in the form of the University of Amsterdam. They saw the potential and were kind enough to offer us rooms, laptops, Lego Mindstorms and a completely organized lunch! We in turn hired two students to assist with the sessions and took care of subscription, marketing and the technical know-how. It doesn’t take a lot of organizational skills to organize a Devoxx4Kids session.
Last saturday was the moment of truth, in the morning kids and parents started to arrive at the university. We did a quick introduction, flew around with (off the shelf) quadcopter to start off with the wow-factor and then we went into the sessions. In Belgium all the parents left the kids, but this time most parents accompanied the children into the session rooms. In retrospect this wasn’t very good and next time we should banish parents from the sessions. The sessions we organized:
The kids were split up into three groups and rotated over all the sessions. Every session was 90 minutes, in retrospect this is a bit long. Most kids got tired and a bit bored after about 45 to 60 minutes. The last track of the day the kids were a lot more distracted. For future Devoxx4Kids events I’d rather do short fun 45 minute sessions instead of complete in depth 90 minute sessions.
Kids learn quickly… even faster than adults! I tried my Arduino session on a couple of adults and they took about 75 minutes to complete all the tasks. The kids did it in record time, we had to improvise and set them a new challenge on the fly. They first made a blinking LED, then hooked up a piezo buzzer to play some music, then they created a ‘musical instrument’ with a photoresistor and the piezo buzzer. Finally (improvised on-the-fly) we made them create a traffic light with three colored LEDs! The quick learning was also noticed in the other sessions.
Our Devoxx4Kids was completely sold out in just 2 hours, so there is a lot of demand for events involving kids and programming. We are going to brainstorm this Wednesday on how we can do more on this front. Keep organizing Devoxx4Kids for 40 kids at the time? Or are there other options? How can we make it pay for itself instead of being fully voluntary…? All ideas are welcome, leave a comment/tweet/email!
Are you not yet convinced you should organize a Devoxx4Kids in your neighbourhood/country? Just watch the video I made during our event:
p.s. Having pictures and video help to tell the story. This video from Devoxx4Kids 2012 in Belgium helped us to get the University of Amsterdam involved!
We have a huge problem.
The knowledge gap
I’ve been a professional programmer now for over a decade, and during this time I’ve met a LOT of excellent programmers. Most of them are partially autodidactic and learned the business side of programming in school. But non of these guru’s/experts use their skills to teach the next generations. Sure, they attend programming conferences, give talks, join user groups etc. But all the other attendees are already good programmers! Companies usually send their brightest programmers to these conferences, not the beginning employees. This means there is already a gap in knowledge and it is increasing. The smart are getting smarter, and nobody is really helping the beginners…
During my time in college I wasn’t very happy with the programming teachers. They had some experience with the business side, they teached us about UML, gantt charts, and (then still hot) waterfall project planning. When it came to real programming, problem solving, algorithms, best practices… they didn’t really teach us much.
Most of the time we had more programming experience and skill than the teachers.
Although I haven’t been in college for a couple of years, except two guest appearances at the University of Amsterdam, I don’t think much has changed. The whole problem is the status and rewards of being a teacher. The average salary of a college teacher (here in the Netherlands) is about half, maybe two thirds of the average professional programmers salary. No wonder why most average or better programmers don’t become teachers! Only the programmers with least experience and skill, or teachers which later on learned programming end up becoming programming teachers.
In the ancient Greece and Roman times teachers were important professions. Especially the most experienced craftsmen, they did not only master their craft, but earned most money by passing their skills as master/mentor to their protégés. This doesn’t happen anymore, the big names in programming now don’t have apprentices to pass on their knowledge. In the best case they write books, which will take years before the school teachers have read them and adopt the ideas.
I’ve already mentioned Devoxx4Kids in previous blogposts. Although this is a great initiative (which I fully support, we’re holding our own version in the Netherlands!). It helps getting kids excited in IT/programming, but it won’t help getting the level of education to a higher level.
Being a teacher/mentor should have the highest social status in our modern world, it should be the highest paid profession and all the guru’s/experts should want to become teachers. But it isn’t. It is poorly paid and absolutely not the sought after job. How can we change this?
At work we’ve had a lot of discussion about epics lately. We seem to have forgotten what they are and how we learned to deal with epics. It became a ‘theme’ or just a big pile of stories which sounded like they belong together. But epics are much much more.
An epic is a goal, and just one goal only. All the stories in the epic should contribute to that epic! Also the epics goal should be a business goal, never a technical goal. The epic should describe a SMART described measurable goal without hinting towards a (technical) solution.
In our project we tend to forget what epics are for and why they are so important after some time.
To remind everybody we decided to write down a manifesto for the epic:
- An epic has just one goal, not more and not less.
- An epic is always measurable, thou should always ask “why” until the business value is clear.
- An epic has a fixed goal, new insights will lead to new epics.
- An epic should have a solution conceived with and verified by the stakeholders, users, product owner and the team.
- An epic contains only stories that help to achieve the goal.
- An epic is ‘done’ when the goal is achieved.
- An epic is only estimated in relative complexity, never in units of time.
- An epic is always in the correct order on the backlog (by the product owner).
- An epic is realized by the team with the minimal viable solution.
- Does your epic break one of the rules above? It is an epic failure!
This is going on several walls in our building just to remind us how important correct epics are. If the initial goal is wrong, all the stories are wrong as well. The epic is the base of all the solutions you’ll be creating and must be founded properly.
Any thoughts on this subject, don’t hesitate to reply. Agile projects get better by sharing best practices and trying to improve!
A couple of years ago, when our family was planning a trip to South Africa, I bought a nice DSLR. We had friends with excellent cameras, huge lenses and wild life photography experience. So instead of trying to compete with them I decided to buy a camera suited for filming. It was the rise of filming-DSLRs, and even television shows were adapting DSLRs for filming. I settled on a Canon 550D also known as Rebel T2i.
Just before I left for South Africa I decided to take the camera to the Devoxx 2011 conference. I didn’t even have a tripod at that time! After shooting some quick footage I decided to edit everything to make a nice movie and share it with the organiser. He liked it so much he placed it on the main website for a while. This is what I made:
The following year Stephan asked me to be the official videographer for Devoxx 2012! So I went back and made another video, it seems like I’m turning from regular visitor/developer to videographer. I took some more time to analyse the conference to include the main sponsors, show every aspect of the conference and to get across the Devoxx atmosphere (including the James Bond theme, we all watched SkyFall during the conference!):
The best time I had as videographer was during Devoxx4Kids. It is a separate event first hosted in 2012. The kids were having a great time and that is clearly visible in the video. Kids aren’t shy at all and much easier to approach then adults. That is why I did some quick interviews and I love the result, I might do that in the future for other conferences as well:
Devoxx UK 2013
The latest conference I filmed was Devoxx UK. For the first time the Devoxx conference has crossed the big blue sea to go to the United Kingdom. I’ve tried to make the resulting video look a bit more professional although I’m still just a Java developer with a hobby:
The last three years I’ve filmed at three weddings, four conferences and edited together our vacations to South Africa, Norway and some trips into the Alps (wintersport). As an amateur videographer (with a growing list of references) there still is a lot to learn, but I’m really enjoying the process! Any tips/hints/tricks are absolutely welcome, and I’m open for invitations!
Fitnesse is a very popular test framework, used in a lot of projects. Using a wiki you describe the tests as plain text, which get translated into ‘fixtures’, code that is called that, in turn, can call your application. An example of a fixture we use:
The corresponding Java code could be something like:
This is a very simplified example on how you could use Fitnesse to test your application. But the idea is very powerful, there are implementations for Java (initially) and now .NET, Groovy etc. Also, most of the time the system you’re testing doesn’t have a Java API but instead you’d like to test the user interface. With most Java applications being web applications there are numerous plugins to connect Fitnesse with for example Selenium to ease web application testing. The fixtures fill webpages and analyze the resulting HTML response.
At my current client (Port of Rotterdam) we’re building a very rich, partially offline, Swing application. This application has a backend and numerous clients running the Swing application. We’ve used Fitnesse to test the backend code from the start, and the last year we’ve put in some effort to also use Fitnesse for the Swing application. We’ve called this “Nonkey”, being an automated version of our Monkey integration testing we’d been doing up to that moment.
The first ingredient we need to test Swing GUI’s in Fitnesse is UISpec4J. This is an excellent Swing test framework that allows you to manipulate GUI elements from code. The framework is made with unit-tests in mind, but can also be used in integration testing. In our SetUp page in Fitnesse we call the following code:
The WindowInterceptor captures the Swing application and allows for manipulation in a later stage. For example:
This fixture causes the Swing application to fill in the username, password and press the login button. It is easy to read and can be launched from Fitnesse with a single line:
Nice! We are done, we can test Swing GUI’s in Fitnesse now! Well no… not really, unfortunately there are a couple more problem we ran into, regaring the Event Dispatch Thread (EDT).
Event Dispatch Thread (EDT)
The EDT, sometimes called Swing Thread, is a special thread. Everything you do in Swing should always happen on this thread. Setting components to visible, pressing buttons etc, all need to be done in the EDT. If you don’t do this correctly the application gets into a lot of race conditions and it can even cause the application to hang.
When we combined Fitnesse with UISpec4J and started making a lot of tests we noticed that sometimes mysteriously a test would fail without changes. It turned out to be a problem with the EDT. UISpec4J doesn’t worry too much about the EDT, and when we click a button or setText (like the examples above) it does this in the current thread. In Fitnesse this thread is the thread that called the fixture, obviously not the EDT.
We brainstormed a lot about how we could fix this, maybe change UISpec4Js code? This turned out to be a hellish task. How about setting SwingUtilities.invokeAndWait() in every fixture? That could work but is also a massive undertaking. We decided to take a look at how Fitnesse calls the fixtures. This is always done from a ‘StatementExecutor’. So we decided to build a custom StatementExecutor which causes the fixtures to all run in the EDT.
To do this we need a custom SlimService. First I tried to extend the normal SlimService, but this wouldn’t work for some odd reason (still unexplained, should try this again). We decided to copy the SlimService code and make our own:
Next we needed a custom JavaSlimFactory:
And last but not least our custom StatementExecutor which forces all calls into the EDT thread:
This uses a small static class we’ve used in our code before to safely run a Runnable on the EDT and invokeAndWait (without waiting IN the EDT):
The only thing left to do is to instruct Fitnesse to use our SlimService instead of the default implementation. This is done using the following parameter in our main page:
Make sure that the class can be found (for example, package it in a JAR and place it on Fitnesses classpath). And you’re done! Using a ThreadCheckingRepaintManager (workings described here) we checked to see if the tests are now repainting/manipulating Swing from the correct thread, and it works like a charm.
Good luck testing with Fitnesse in the near future, if you have any problems/improvements/ideas please let me know (in the comments below).
In the next couple of years dead will become an important aspect of the social networks. A time will come that most profiles on Facebook will belong to people who’ll never be able to post another update. Currently due to inactivity most dead profiles will be deleted or become inactive, but I think dead will take a much more important role on the internet.
My parents and even grandparents have a Facebook account now, but in twenty or thirty years, some people I’m connected to won’t be alive anymore. It would be great to be able to browse the lives of people who are no longer around us. I’d love to read about my deceased grandmother for example, just to see how she lived her life. So instead of deleting inactive accounts, death should become more accepted and a part of our social web as well.
Yesterday when I returned home from another amazing Devoxx conference I quickly created another impression video:
A couple of weeks ago I went to Devoxx4Kids. Devoxx is a very well known Java conference (the best in the world actually!). This time they organized an event especially for kids ranging from 10 to 14 years old. The goal is twofold, the main goal is to just give them a good time, the second goal is to introduce them to programming and technology in a fun way.
To show the world this is a great idea, Stephan invited me to film the event and capture the happy faces of the kids enjoying themselfs. And now after Devoxx 2012, I’m allowed to show it to everybody:
(more information in Dutch and French: http://www.devoxx.com/display/4KIDS/Home)
Stacktraces in Java are wrong. This is a conclusion that I’ve drawn after years of working with novice programmers.
What is the first thing novice programmers do when they encounter a stacktrace? They start reading it, and this is wrong! The first thing you should do is scroll down. That is because the most important piece of the stacktrace is most likely at the bottom.
Stacktraces in Java are usually wrapped numerous times, because all the frameworks and the application server wants to add their own little bit of information around the original exception. The problem is that Java uses the “Caused by” way of printing the stacktrace. With the “Caused by” you’ll get a lot of information about what happened (afterwards) first, until you get to the actual reason.
The first two traces aren’t at all important, it tells us something went wrong with a webservice call. But the bottom trace gives us the real reason, a NullPointerException!
I’d rather see stacktraces being inverted, so instead of saying:
|**Webservice failed||which is caused by -> Webservice failed during translation||which is caused by -> A NullPointerException!**|
It should say:
|**A NullPointerException||which caused -> Webservice failed during translation||which caused -> Webservice failed…**|
So using the example above it would become:
This is much easier to understand (IMHO). The first exception you see is now also the first thing that happened. Much clearer for the novice programmer.
Some more tips when you encounter a stacktrace:
- Look for the first line that starts with YOUR package, this is where your control over the code starts, where you might be able to fix it
- If there are a lot of other packages mentioned before YOUR package, Google it! You are probably not alone
Yesterday a friend of mine pointed me to the following thread:
Giving.github is a project that tries to bring people together. There are a lot of programmers looking for fun projects in the world, and so are scientists/charities and other people with problems!
Be sure to check it out, maybe you can help somebody as well.
Mara-Naboisho Lion Project
One of the problems posted to giving.github has something to do with Lion collars. The Mara-Naboisho Lion Project has a couple of collars and some files, but no idea what the data inside the files mean. Their initial description was:
The Mara-Naboisho Lion Project has asked for our help decoding and plotting the positions of lions fitted with GPS collars.
They receive SMSes from the collars:
These are presumably SMS PDUs, although simple online decoders don’t seem to make much sense of them. There’s the ASCII text “IRIDIUM” in them, presumably being the SMSC or sender or something string, as IRIDIUM is a satellite telephone system and presumably the bearer when the collars send up their positions.
What format is it, and how do we decode it?
Not SMS PDU
This is where I started analyzing, and I quickly ruled out that the hex-code is pure PDU (which can easily be translated). It seems to be some dialect/own protocol.
The first major breakthrough was realizing that there is one big header that both files have in common, and the real message starts with 0A. And the two messages after that have a repeating pattern:
This sure adds some structure to the files. I also guessed the first file has actually 6 entries and the second file has only 5 entries.
First field deciphered
The second breakthrough came through Twitter. I posted this problem in a tweet and after a couple of hours I got a reply that there was progress on the stackoverflow question.
This was DStibbe’s reply:
Perhaps the ‘13’ is not part of the headers but the message instead?
The messages would then be:
It does seem like a log , with the message for Aug 06 (guessing) has 6 entries and the second from Aug 07 having 7.
What would a collar record? I’m guessing longitude,latitude and timestamp?
Chances are high that the first eight digits represent the timestamp. They are incremental from bottom to top.
Eg. 13ef348a = 334443658.
334443658 seconds = 10 years, 8 months, 6 days, 23:00:58
This matches the date in the title of the first sms: Collar07854_100806 210058.SMS
It even matches the timestamp minus 2 hrs in the title!
At this point the progress stopped a bit, we couldn’t get the other bytes translated. There seemed to be certain integer values: 0039 d0ed for example. This probably isn’t floating point (which we thought it would be, latitude/longitude/altitude) because floating point numbers have the exponent in the first 11 bits. When a number starts with 00’s it doesn’t have the exponent part filled.
So we asked the project for some more information, for example about the recorded data (where/when) and the manufacturer of the collars.
They gave us this KML file, and this company name: Vectronic-Aerospace.
Lat/lon, I’ve got you!
The biggest part we wanted to decipher was the lan/lon location (that is what the researchers want to have). I came to this breakthrough after reading a PDF file from Vectronic-Aerospace’s website. It has some screenshots from their original software (why aren’t they using that free software?!). In these screenshots I noticed integer coordinates very close to the integers I’ve managed to get from the hex-data! It was called ECEF data, this is X,Y,Z data! Until now my guess was that the SMS files had lat/lon coded in binary, but it has XYZ information.
After a quick google I managed to find some code to translate from ECEF coordinates to lat/lon and it gave me the following location:
When plotted in Google Maps it gave me a location in Germany, at first I thought it was another dead end, but then I looked here. It turns out it was the EXACT location of Vectronic Aerospace, the creators of the collar! Problem solved.
There are still some mysteries, for example… what are the last bytes? Looking at the screenshots in the PDF I suspect it would be main battery voltage, backup voltage and temperature. The project also probably wants to integrate the collar files with the website. And there are of course a lot more giving.github.com problems to solve!
With the sudden surge of visitors from Reddit (Hello!) I decided to take look at Google Analytics. And two things caught my eye:
First of all, Google Analytics ‘Realtime’ is awesome, you can see minute by minute how many people are on your website and what they are looking at, where they come from (internetwise and geographically).
Second, my website gets the right type of visitors, I’m so proud at you guys and girls…
I fired up the profiler to see what was causing the Java code to be so slow, and it turned out the method it spend most time in was Math.pow(). Other slow methods were Math.acos(), cos(), sin() etc. It turns out that the Math library isn’t very fast, but there is an alternative, FastMath. Apache Commons has implemented a faster Math library for commons-math. Lets see what changing Math.* to FastMath.* does to the performance:
Warning: This isn’t the same as Math.pow/FastMath.pow!
The slowest method in the program now is FastMath.acos. From highschool I know that acos(x) can also be calculated as atan(sqrt(1-x*x)/x). So I created a own version of acos. When benchmarked, the different methods: Math.acos(), FastMath.acos() and FastMath.atan(FastMath.sqrt(1-x*x)/x), the result is again surprising:
The custom acos() function is a bit faster than FastMath.acos() and a lot faster than Math.acos(). Using this function in the Mandelbulb renderer gives us the following metric:
Well surprisingly in this case it is. With the code a 100% the same, using arrays as vector and Math.* the code actually runs faster in my browser!
Edit 2: People have been asking me: What could have been done to make it faster in Java? And, why is it slow?
Well the answer is twofold:
1) The Math libraries are made for ‘double’ in Java. Having a power() method work with doubles is much harder than working with just integer numbers. The only way to optimize this would be to overload the methods with int-variants. This would allow much greater speeds and optimizations. I think Java should add Math.pow(float, int), Math.pow(int, int) etc.
2) All the Math libraries have to work in all situations, with negative numbers, small numbers, large numbers, zero, null etc. They tend to have a lot of checks to cope with all those scenario’s. But most of the time you’ll know more about the numbers you put in… For example, my fastPower method will only work with positive integers larger than zero. Maybe you know that the power will always have even numbers…? This all means that the implementation can be improved. The problem is, this can’t be easily achieved in a generic (math) library.
This afternoon Will (the friend I mentioned in this previous post) showed up again on Google Talk.
If you have a bit of time:
The code can be found here: https://github.com/royvanrijn/mandelbulb.js
I’ve already included one improvement by Will himself, scanlines to smooth up the rendering (good for inpatient people!).