December 1st, 2009  | Categories: Development, Open Source  | Tags: ,

The Simile Timeline allows you to make beautiful, interactive timelines for web pages using only JavaScript. It is fairly flexible and allows you to create timelines with intervals of Seconds, Hours and Days right up to Centuries and Millenniums.

However, it does not support Quarters, which is what I needed. So I have submitted a patch to the project, and have also been using the following code so I can use Quarters now without needing to patch my local install.

The code is not the most elegant, as it duplicates a lot of the code from the library, but until my patch gets incorporated it is the only way to have Quarters.

To use it, download the js file and include it in your web page after the timeline files. You can then use a Quarter in the same way as you would any interval, as shown below:

Timeline.createBandInfo({
    ...
    intervalUnit:   Timeline.DateTime.QUARTER,
    ...
});

Find the code on GitHub, or


October 25th, 2009  | Categories: General  | Tags: ,

This weekend saw the end of British Summer Time, where the clocks in the UK go back an hour. In the old days, you needed to remember to change your clocks or risk making some embarrassing mistakes. But in today’s digital age, your PC, phones and other devices are smart enough to compensate for the change.

So you would think that any well designed website would also be smart enough to respond to the change in time. Especially if the main purpose of that site is to display the start and end times of TV programs. Well in the case of OntheBox.com, you would be wrong.

Compare the times in this screenshot from OntheBox, and a screenshot from Yahoo TV. Notice how at OntheBox, all the listings are an hour later than they are at Yahoo. Thats because it has been unable to correctly account for the change in times.

Unfortunately for me, this meant I after staying up to watch a program at 11pm, I tuned in just in time to see in the end credits. In my anger, I wrote this post to spread some bad publicity on their behalf, and also sent them the following message:

I thought you would like to know that the times on your website have been an hour out since the end of BST on Sunday morning.

Unfortunately for me I relied on your site and waited up till 11pm to watch Match of the Day 2, only to find it was in fact on at 10pm.

I find it astonishing that your website was not prepared for the change in time. Its not as if it was unexpected, the date when BST ends is set many years in advance. It is also not difficult to write software that can work out the time without human intervention.

On a website listing the TV schedule, displaying incorrect times is unforgivable, and with so many competing websites I expect you would have lost a number of regular visitors after today, including myself.

Regards,
Andrew Jones

Regardless of any response I get, I will be getting my future TV listings from one of the many other similar websites.

</rant>

Update

I should mention that I received a response from OntheBox, apologising whole-heartedly for their mistake. Its good that they responded in such a polite way :-) .

October 8th, 2009  | Categories: Software  | Tags: , , , , ,
Chrome application shortcuts in Linux

Its taken a while, but the Linux version of Google’s Chrome is really starting to catch up with its Windows counterpart, both in terms of features and stability.

I have been using the dev releases of Chrome for a while now and recently I have been able to make the switch to using it as my default channel. In fact, I haven’t used Firefox in weeks!

Getting the web browser is easy if you are using a Debian based distribution, such as Ubuntu. Simply download the package from the Chromium website and the package manager will do the rest. Not only will it install the browser, it will also add the Google repository so you are kept up to date.

Most of the features that you would expect from a web browser are now complete, including Flash support. Extensions are also now available, although not yet completely implemented on Linux. One of the main features that you might miss is printing, so keep another browser available.

I have made the move to using Chrome as my default browser on Linux mainly because Firefox 3 is just so slow, and not just at the rendering of pages. On my desktop, start up takes upwards of 10 seconds. Chrome doesn’t take more than 3.

Where Chrome really shines is on my netbook. Once Firefox loads, it can only handle around 4 tabs before it really starts to feel sluggish, and GMail is just unusable. Chrome does not have these problems. I can have half a dozen tabs open, including GMail, and my netbook is still just as responsive.

Of course, it is still an early release, so there is the odd problem. I have noticed once or twice that Chrome can eat up the CPU, and playing a Flash video can sometimes be a bit flaky. But these happen rarely, and even with this I already feel that Chrome is the best web browser available on Linux.

October 6th, 2009  | Categories: News  | Tags: , , ,

Google have launched a website in an effort to teach users about their web browser.

WhatBrowser.org provides a 1 minute introductory video to describe what a web browser is, some tips for the users current browser and the opportunity to try a new browser, with links to all the major browser vendors.

Its an interesting move. Clearly the hope is that by informing users they will choose to upgrade to a modern web browser, perhaps Google’s own Chrome.

Of course, its no coincidence that this comes less than 3 weeks before the launch of Windows, which is set to feature a browser “ballet screen” in Europe following pressure from the European Union.

September 24th, 2009  | Categories: Open Source, Software  | Tags: , , ,

After a lot of work I have finally released the new Kino Search extensions for Foswiki.

Kino Search is a Perl port of the Lucene indexed based search engine from Apache. The Foswiki extensions use this to provide fast, full text search of both topics and attachments. The attachments that can be indexed include MS Office 2003 and 2007 documents and PDF files.

This original add-on was available for TWiki but I have now ported this over as a new KinoSearchContrib and KinoSearchPlugin and made many improvements, including:

  • Fast CGI and mod_perl support
  • Indexing MS Office 2007 files
  • Much more resilient indexing
    • In particular when indexing password protected files or when an incorrect file type is supplied (such as attaching a image and calling it myfile.txt)
  • Using more of the official Foswiki API
  • Improved documentation and templates

There have been other technical improvements that are behind the scenes. The extensions also comes with a good testing suite, helping to ensure that it is of good quality.

For more information, see my posting on the official Foswiki blog (although remember that I wrote both, so the wording is similar…).

August 15th, 2009  | Categories: Software  | Tags:

In a standard Foswiki setup there is a topic in every web called WebTopicList, which is linked to from the side bar as Index. By default it simply lists all the topics in one big list, as shown below (or view on foswiki.org):

old-webtopiclist

This certainly isn’t very elegant. Luckily by using Michael Daum’s Filter Plugin we can improve the index by giving it some structure and making it more like a directory, as shown below:

new-webtopiclist

To do this we only need to make a small change to the WebTopicList in the System web. Since all the other webs simply import that page the changes will be immediately visible across the wiki with just the one change.

Edit the WebTopicList topic and replace this line:

%TOPICLIST{"   * [[%BASEWEB%.$name][$name]]"}%

With this:

%MAKEINDEX{"%TOPICLIST{"$name" separator=","}%" cols="3" header="$anchors" format="[[%BASEWEB%.$item][$item]]"}%

Thats it! You now get a much more friendly and useful index in all of your webs.

Note: This tip has also been made available on foswiki.org.

July 6th, 2009  | Categories: Services  | Tags: , ,

For a while I have been using Gmail Tasks to try and organise myself. While it is nicely integrated into Gmail, I would quite like to be able to access it without needing to be in Gmail. Having looked at http://mail.google.com/tasks/ and found there was no interface I assumed there was none, until today when I found http://mail.google.com/tasks/ig.

The interface is very plain, which at first thought makes it a bit rubbish. Then I remembered that Firefox has a feature that allows it to open bookmarks in the sidebar, rather than the main window. While not very useful for most sites, the interface for Gmail Tasks is so minimalist that it works great in a sidebar.

To load the bookmark in the sidebar firstly save it as a regular bookmark. Once its saved find it in the menu and after right-clicking on it choose Properties from the menu. Then simply check the box marked Load in the sidebar, as shown below.

saving-tasks-bookmark-in-sidebar

Click here to view how the bookmark looks when loaded in the sidebar.

June 23rd, 2009  | Categories: Linux  | Tags:

I recently wanted to run a set of commands on a Linux machine at some point in the future. I knew about using cron to schedule a set of commands at defined intervals, but I only wanted to run the commands once at a specific time on a specific date. After searching the internet I found the at command, which allowed me to do exactly what I wanted.

The at command will execute a command or a script at a later time or date and allows for some fairly complex time specifications. Below are two examples of the at command:

1) using at to execute commands taken from stdin at 17:00 on the same day:

$ at 17:00
at> ...
at> ...
at> <EOT>
job 1 at 2009-06-22 17:00

2) using at to execute commands from a file on a June 19 at 17:00:

$ at -f myscript.sh 17:00 Jun 26
job 2 at 2009-06-26 17:00

You can also use atq to list the scheduled jobs, as follows:

$ atq
1      Mon Jun 22 17:00:00 2009 a ajones
2      Fri Jun 26 17:00:00 2009 a ajones

The atrm command allows you to remove a scheduled job:

$ atrm 1
$ atq
2      Fri Jun 26 17:00:00 2009 a ajones
June 19th, 2009  | Categories: General  | Tags: ,

I just added the irrepressible.info widget to my site and thought I would write up a quick blog post to help promote it.

irrepressible.info is a campaign from Amnesty International which allows people to republish excerpts of censored sites on their websites. The idea is to undermine states such as China and Iran that are trying to censor and control free speech on the Internet.

To add the widget to your WordPress sidebar simply go to the Widgets admin page and add a new text widget. Then enter the following text into the widget:

<script type="text/javascript">
var irr_lang = 'en';
</script>
<script src="http://fragments.irrepressible.info/js/fragment-180.js" type="text/javascript">
</script>

Once you have saved the changes the widget will now be displayed in your side panel. The text will change on each page load with censored material from the irrepressible.info database.

A number of different widgets are also available from the irrepressible.info website and it also has a public API.

If you have some free space on your site then consider adding this widget and supporting a very worthwhile cause. There is also a pledge you can sign at the website.

June 8th, 2009  | Categories: Development  | Tags: , ,

Having been working in a team on a large-ish project I quickly found out that we all have very different coding styles. This has provided constant headaches and frustrations throughout the project as we try to work on the same files, re-factoring each others code so it fits in with our preferred styles. Not only is this a waste of time, but it can also make it hard when using subversion to merge changes to the files, as it often thinks the file has significantly changed when really it was only the amount of white-space in the indentation.

In an effort to overcome these problems I have looked into creating some coding standards for my group at work. This article discusses my research into coding standards, including what benefits they might bring and what they should specify.

What are Coding Standards?

Coding standards (also coding conventions or coding guidelines) could be defined as follows:

Coding standards are a set of guidelines that recommend programming style, practices and methods for each aspect of program. They aim to help improve the readability of the source code and make software maintenance easier.

Why do we need Coding Standards?

As defined above, coding standards are designed to help improve the readability and maintainability of your source code. This is important because:

  • 80% of the lifetime cost of a piece of software goes to maintenance
  • Hardly any software is maintained for its whole life by the original author[1]

Coding standards help to enforce consistency over different parts of the software when there are a team of developers working together and help make the code more predictable.

Finally it can be difficult to produce and/or read diffs and patches against source code if it does not adhere to any standards, in particular when it comes to white space and indentation.

Discussion of Specific Standards

I will now look at some of the specific coding standards that are often defined in guidelines and discuss whether what benefits they bring and how appropriate they are. They will form the decision of what I include in my first version of the coding standards for my team. This is not a complete list but should capture the main sections of a coding standards document.

Spaces Around Parenthesis

Everyone has their own style when it comes to having spaces around parenthesis. Some examples are:

if(foo)
 
if( foo )
 
if (foo)
 
if ( foo )

Some coding standards define where the white space is acceptable. However, I do not think it makes a significant difference to the readability of the code and so will not be specifying a standard.

The Location of Braces

As with the spaces around the parenthesis, everyone will have their own style when it comes to the location of the braces. Some editors will also be configured to place the braces in a particular location. Below are some examples of braces placement[2]:

 if (condition) {
    doSomething(); }
 
 if (condition) {
    doSomething();
 }
 
 if (condition)
 {
    doSomething();
 }

I don’t really think the location of braces matter a great matter a great deal, so long as they are sensible and the indenting is consistent. It is not something that is worth defining a standard for, especially at the risk of upsetting people who have their own ideas on the right place to put them.

Indenting

One thing that nearly everyone does agree on is the need to indent your code. This makes the code so much more readable as you can easily see where one code block starts and finishes and if there are nested blocks.

Although it is agreed that indenting is a good thing, there are arguments about how many columns to use for indenting. Most specify between two or four columns, although it really does not matter much as long as it is consistent.

In the coding standards it might be worth defining the amount of columns to use for indenting and a reminder that it should always be used where appropriate.

Tabs vs Spaces

The issue of using tabs to create white space seems to be a contentious one. The problem is the tool you are using might be configured to use tab stops of four, where another persons might be configured to use tab stops of eight, and yet another person might use spaces. So you might have spent some time formatting your code to look nice in your editor, but when the next person opens the file it might look very ugly and difficult to read.

To avoid this issue a lot of coding standards forbid the use of tabs and only allow the use of spaces to create white space. Using only spaces ensures that the code will look the same in all editors and will also avoid problems when printing or emailing code and producing/reading diffs. It should be possible to configure your editor to use spaces instead of tabs (often under the setting of “soft tabs”).

I have certainly found the issue of tabs and spaces to be very annoying and so would suggest that there should be a guideline defined in the coding standards.

Comments

As with indenting, it is generally agreed that commenting your code is a good idea. Comments help to explain what the code is doing, which can be especially useful if it is a complex piece of code. They can also be used to highlight where some code needs later attention, using comments that start with TODO, FIXME or SMELL[3].

There is a question on how many comments there should be. Some people think you can never have too much of a good thing and therefore your code should be littered with comments. Others might say that if you need a comment then the code isn’t sufficiently simple enough[4].

I don’t think its worth specifying how many comments people should be writing in the coding conventions. However, it might be a good idea to include a reminder that ensures everyone is using comments where appropriate.

Function Headers

Function headers use comments before a function is defined that documents what it does and possibly more. A function header might be as simple as the following[5]:

 // This function trims right and left of the string
 function trim(s)

Or it could be a bit more verbose:

 // -----------------
 // function trim
 // input: theString = string
 // returns: middle portion of theString, using the Wiki2001StringAlgorithmNotByKnuth
 // assumptions: theString must be at least 3 characters long (plus terminating null)
 //  to avoid buffer overflow error.  NotKnuthStringLibrary must be opened & initialized 
 //  before calling this function.
 // ------------------
 function trim(theString) {

Like comments, there are mixed feelings about the usefulness of function headers. While they can help to give you an overview of what the function does, it could also be argued that if the code is clear enough then you should be able to work out what it does.

Many languages have their own format for documenting functions in the code, such as Perl’s POD[6] and Java’s Javadoc[7]. This can then be extracted and formatted for output in a number of ways, such as HTML and PDF.

Depending on what you are working on function headers might need to be included with the code. However for the kind of projects my group works on it should be enough to specify one or two lines before each function to describe exactly what it does.

Naming Conventions

A naming convention defines how variables, types and functions should be named in a program. This is another contentious issue where most developers have their idea of what is the right naming convention and will not want to be told to do it in a different way.

Naming conventions might need to answer a number of questions. For example, should you use bumpy case, where you use capitalization to divide each word from the next (i.e. formatNumber) or should you use underscores (i.e. format_number). They might also use the name to identify the type of macro, for example a CONSTANT in all capitals, a Class with an initial capital and an instance in lower case. A subroutine would also be lower case and would be clear from context as its usually followed by parentheses.

A famous variable naming convention is the Hungarian Notation and is where the type of the variable is encoded into its name. There is no standard for which characters should be used as the identifier, but an example might be iSize for an integer.

Naming conventions do sound like a good idea. However, different people will have different ideas on the right way to name a type. As long as it is consistent with the names of functions already in the program then it does not really matter how it is done. Therefore, when I wrote my first version of the coding standards for the team I work in I decided not to suggest a particular naming convention.

Writing the Coding Standards

It is worth considering what the coding standards document might look like and how much detail it should go in. Some coding standards are fairly short and concise, such as the BBC’s Perl Coding Guidelines, while others are quite the opposite and provide guidelines for almost all parts of writing code, such as Adobe’s Flex SDK coding conventions.

It is also a good idea to think about the style and layout of the document. Should it be listed as bullet points or discussed in paragraphs?

The coding conventions I think got the best layout are the BBC’s coding conventions for C++ and Perl, and I wrote mine in a similar way.

Publishing and Agreeing the Coding Standards

So I now have an idea of what I want to outline in the coding standards and now need to think about the best place to publish it and getting everyone’s agreement on it. At work we have a wiki, which would make an ideal home for the coding standards as it is accessible to everyone and also editable by anyone.

Once I have published the first version of the standards it will be important to get everyone’s feedback and discuss whether they are the best practices for our group. It will also be important to ensure that everyone feels a sense of ownership for the standards, which will make people more likely to adhere to them.

Conclusion

After completing this research I feel I have a good idea of what makes good coding standards and how much depth they should go into. I have also discussed many specific standards and tried to capture a developers thoughts on them.

You can view the coding standards using the link below. It turned out to be a very short document, but that’s not necessarily a bad thing. I have purposely decided not to define specific standards where we should be able to rely on the developers common sense. Also this is only a first version of the standards and they may well grow as feedback is received.

The success of the standards will be measured by their uptake and whether people feel like they have involvement in the document, rather than just being told what is right. In a months time I will write a follow up discussing how successful the coding standards have been in my group and whether people feel it has helped to improve the consistency and quality of the code.

View the coding standards (PDF)

Since I read so many articles related to coding standards it would probably be easiest to browse them on Delicious. You might also want to see the Wikipedia article.

References

  1. Code Conventions for the Java Programming Language []
  2. http://c2.com/cgi/wiki?CodingStandard []
  3. Foswiki Coding Conventions []
  4. http://c2.com/cgi/wiki?MassiveFunctionHeaders []
  5. http://c2.com/cgi/wiki?SmallFunctionHeaders []
  6. Perl’s Plain Old Documentation format []
  7. Java’s Javadoc format []
TOP