Generating Fixture Lists

Update 2007-03-21: If all you want to do is generate a fixtures list you can use my Fixtures Generator

I’ve been trying to find out how to generate fixture lists for some time (it is harder than it sounds!) and I finally worked it out thanks to this page about a fixture generating algorithm. My Java implementation of the algorithm is below.

/* 
 * This code owes an enormous debt to 
 * http://www.barrychessclub.org.uk/berger2001.htm 
 */

import java.util.Arrays;

public class Fixtures2 {

    public static void main(String[] args) {
        
        // Find out how many teams we want fixtures for.
        int teams = 0;
        try {
            teams = Integer.parseInt(args[0]);
        } catch (NumberFormatException e) {
            System.err.println("Please state number of teams as first arg.");
            System.exit(0);
        }
        
        // If odd number of teams add a "ghost".
        boolean ghost = false;
        if (teams % 2 == 1) {
            teams++;
            ghost = true;
        }
        
        // Generate the fixtures using the cyclic algorithm.
        int totalRounds = teams - 1;
        int matchesPerRound = teams / 2;
        String[][] rounds = new String[totalRounds][matchesPerRound];
        
        for (int round = 0; round < totalRounds; round++) {
            for (int match = 0; match < matchesPerRound; match++) {
                int home = (round + match) % (teams - 1);
                int away = (teams - 1 - match + round) % (teams - 1);
                // Last team stays in the same place while the others
                // rotate around it.
                if (match == 0) {
                    away = teams - 1;
                }
                // Add one so teams are number 1 to teams not 0 to teams - 1
                // upon display.
                rounds[round][match] = (home + 1) + " v " + (away + 1);
            }
        }
        
        // Interleave so that home and away games are fairly evenly dispersed.
        String[][] interleaved = new String[totalRounds][matchesPerRound];
        
        int evn = 0;
        int odd = (teams / 2);
        for (int i = 0; i < rounds.length; i++) {
            if (i % 2 == 0) {
                interleaved[i] = rounds[evn++];
            } else {
                interleaved[i] = rounds[odd++];
            }
        }
        
        rounds = interleaved;

        // Last team can't be away for every game so flip them
        // to home on odd rounds.
        for (int round = 0; round < rounds.length; round++) {
            if (round % 2 == 1) {
                rounds[round][0] = flip(rounds[round][0]);
            }
        }
        
        // Display the fixtures        
        for (int i = 0; i < rounds.length; i++) {
            System.out.println("Round " + (i + 1));
            System.out.println(Arrays.asList(rounds[i]));
            System.out.println();
        }
        
        System.out.println();
        
        if (ghost) {
            System.out.println("Matches against team " + teams + " are byes.");
        }
        
        System.out.println("Use mirror image of these rounds for "
            + "return fixtures.");
    }

    private static String flip(String match) {
        String[] components = match.split(" v ");
        return components[1] + " v " + components[0];
    }
}

Update 2005-06-05: Now allows “complementary teams”, that is – teams that never play at home at the same time as each other. For example, try 10 teams — for each pair from 1 & 6, 2 & 7, 3 & 8, 4 & 9, and 5 & 10, both are never both at home. It was meant to be in the original program but a bug in my code was fouling things up.

Update 2007-03-21: You might also want to see the source code to my PHP fixtures generator

Perfect IDE

My perfect IDE/text editor has the following features:

  • Java support. And extensible to support other languages. Preferably has existing libs/files for Perl, C#, Ruby, Python, PHP, ASP/VBScript.
  • Runs on Windows. Preferably cross platform for when (if) I make a jump to Linux or OS X as my main platform, and for when I am dabbling in those platforms.
  • Brilliant regex support.
  • Code completion. Intellisense (as in Visual Studio) where it understands the object model and supplies only methods of an object (for example) that exist on that object.
  • Unlimited undo.
  • Fast. Starts fast and stays fast when running.

To me that doesn’t look an unachievable list but my prime candidates all fall short:

Ultraedit doesn’t have the IDE-defining capability of understanding what the text files it is working on mean, therefore it cannot do Intellisense.

JEdit is too slow and Intellisense support is patchy and from a third party.

Visual Studio is just about there but only supports .NET languages.

IntelliJ IDEA is great, if very large/slow. But it only does Java.

My only hopes are Emacs (which doesn’t feel like a Windows application when running on Windows) and Eclipse (which at least aspires to supporting many languages though it is slow and uninituitive). I will investigate both of these further.

Basically I want Ultraedit (or any other really good text editor) with Intellisense. Or failing that Visual Studio/IntelliJ IDEA with support for all languages. Any suggestions?

Jobfight

I’ve added the ability to compare two keywords (and see which has more jobs attached) to my jobfight page.

Like googlefight, but for jobs.

The statistical record of how many jobs are available by keyword that I have been running for the past two years is still there, also.

Does Anyone Love Java?

Paul Graham says that
nobody loves java:

“No one
loves it. C, Perl, Python, Smalltalk, and Lisp programmers love their
languages. I’ve never heard anyone say that they loved
Java.”

I’m not so sure.

Google Says

Googling for “I love java” gives 5,400 results. Adding the word
programming to the search1 yields
2,680 results. Not all sarcastic, surely. The results include “Why I
Love Java” and a page that says that, “it makes programming quick and
fun”.

These numbers don’t tell us much. Anything as widespread as Java must
have some fans. We need something to compare with: ‘”I hate java”
programming’ gives 1,350 results. Java seems to be more loved than
hated, at least.

Paul Graham contrasts Java with C, Perl, Python and Smalltalk.
Google says:

“I love Java” programming 2,680
“I hate Java” programming 1,350
“I love C” programming 872
“I hate C” programming 506
“I love Perl” programming 1,720
“I hate Perl” programming 426
“I love Python” programming 1,330
“I hate Python” programming 46
“I love Smalltalk” programming 57
“I hate Smalltalk” programming 3
“I love Lisp” programming 185
“I hate Lisp” programming 77

So Java can claim to be the “most loved”. By the better measure
of love/hate ratio Java does approximately as well as Lisp, and better
than C.

Old and New

It is the two most established languages2 that are
most hated: Java and
C. It is this establishment that is key. Because they are established
they are forced on programmers more often, not chosen. Because they are
forced they are hated. It is harder to hate a tool that you selected
than one that is forced on you.

Python is not so well established. It finds its
place in the fringes of organisations and in the open source
community. Where it is used, it is selected. If it is not
ideally
suited for a task, it tends not to be used. Because of its
age3, if a library or feature
is missing it will be excused as “coming soon”. If a library or
feature is missing in Java it is considered a serious shortcoming.

Older languages also have more visible shortcomings. When C was young it
was the most portable language in the world. Now we say that Java
solves some of those portability problems with far greater success;
similar claims can be made for Perl, PHP and others. Older
languages also have the problem that more bad code has been written in
them – you are more likely to have wrestled with someone else’s awful C
than someone else’s awful Python simply because you are far more likely
to have had to edit someone else’s C full stop.

Newer languages seem to be loved more. This might be because a missing
library or functionality in a new language can be excused more easily –
“Generics? We’re working on that.” Also a newer language will be known in
less depth by its average user and therefore its limits will be less well
known. The problems of C and C++ are so obvious to us because hundreds of
thousands of programmers have butted up against them numerous times.
There may be terrible limitations on Python but they are less well
known.

When I wrote the first version of this article my
blog was quickly commented on by a
number of Ruby users all anxious to show that Ruby was the most loved
language. And the results for Ruby are spectacular (love: 1,450, hate: 13).
And Ruby became mainstream (if it can be said to have done so) very recently
indeed4.

It is not just that shortcomings become visible or inexcusable. The
state of the art does move on. Fortran is superior to Assembler5 and C is superior to Fortran. Perhaps it
will one day be possible to say that it is equally evident that Java is
better than C and Python is better than Java6. I suspect that these languages are too much
contemporaries for that distinction to ever be so clear.

Why Love Java?

Let’s look at what Java offers: portability, automatic garbage
collection, object orientation. Yes, Smalltalk offered the OO and the
GC in 1971 but never with such a large standard library and so many
tools, and with C-like syntax too.

If you were forced to work on somebody else’s complex C program
porting it to another OS whilst fixing memory leaks and then allowed to
switch to Java I wouldn’t be at all surprised to hear you say the words,
“I love Java”.

A previous version of this article entitled
Programming Languages That Are Loved previously appeared on this site.

Footnotes

  1. We add the word programming to exclude coffee-related
    results.
  2. Smalltalk and Lisp are both much older than Java but it
    would be difficult to argue that they are more established.
  3. Although Python was initially released in 1991 and Java in
    1996 you can tell by the better measure of when they got their O’Reilly
    books when they “hit primetime”:
    Python in a Nutshell (1st Ed.)
    2003;
    Java in a Nutshell (1st ed.) 1996.
  4. Ruby in a Nutshell (Nov 2001) is one of three O’Reilly Ruby
    books. By contrast Java has more than 150 and Python has 25.
  5. As a general purpose programming language.
  6. Not until after Python has a ternary if-else operatore
    though, I hope.

Ooooooooooooo

o.com,
oo.com,
ooo.com,
oooo.com,
ooooo.com,
oooooo.com,
oooooo.com,
oooooooo.com,
oooooooo.com,
ooooooooo.com,
oooooooooo.com,
ooooooooooo.com,
oooooooooooo.com,
ooooooooooooo.com,
and oooooooooooooo.com
are all registered domain names (although those with 12, 13 and 14 Os have expired).

I am also amused by the fact that
worldcup2006.com,
worldcup2010.com,
worldcup2014.com,
worldcup2018.com,
worldcup2022.com,
worldcup2026.com,
worldcup2030.com,
worldcup2034.com,
worldcup2038.com,
worldcup2042.com,
worldcup2046.com,
worldcup2050.com,
worldcup2054.com,
worldcup2058.com,
worldcup2062.com,
worldcup2066.com and
worldcup2070.com
are all registered too. Quick, grab worldcup 2074.com before it goes!

Lomography or Digital Photography?

The new Lomo ambassadors for London had a meeting on Tuesday night upstairs in the Griffin pub on Leonard Street. It was terribly oversubscribed with people sitting on the floor and standing on the stairs. They announced some kind of project the constitution of which was left very vague. It might have been a semipermanent Lomo wall somewhere in London? They also showed the BBC documentary about lomography.

I had a different perspective watching the documentary in 2005 instead of 2001 (when it was shown on BBC Four). Many of the virtues of the Lomo Kompact have been superseded by cheap, high-quality digital cameras. Digital cameras are smaller (“take your camera with you wherever you go”), cheaper to take lots of photos with (“don’t think just shoot” — no film to buy, cheaper processing if you want photos), better for shooting from the hip (“try the shot from the hip” — because of the viewscreen on the back). And while the lomohomes are nice I’d also say that flickr is a far bigger, better, more usable version of the same thing.

The Lomo still scores on simplicity and build quality (far less worrying to drop a Kompact than a digicam). And it still has the tunnel lens with colour effects (though I seem to get less of this in my photos than others do). But the crazy, spontaneous, shooting-from-the-hip feel of lomography is surely in the province of the digital camera now?

The Diary of a Nobody

Yesterday, inspired by Pepys Diary I thought I’d set up something else from Project Gutenburg in a similar format. I initially thought of the Diary of Anne Frank but unbelievably that is still in copyright. Then I checked out The Diary
of a Nobody
and by strange coincidence it begins on April 3rd.

One late-night coding session later and I give you thediaryofanobody.com. As it is fiction, you are unlikely to want to "dip in" so I set it up so that you can start your RSS feed on any date you like and get the diary over the next 18 months or so.

Blogs in Action

Attended the Blogs in Action seminar organized by Six Apart and sponsored by Nokia Lifeblog. Highlight was most definitely John Dale talking about the very ambitious and very successful project to make blogs available to all Warwick University staff and students at Warwick blogs.

Perhaps the very best thing about the Warwick blogs was the “slice n dice” aspect. You can elect to get feeds of people on your course, people in your hall of residence, people with the same interests as you, individuals you pick. You can publish to everyone in the world, everyone at Warwick, a group of three people. They seemed to have thought of so many useful options. Plus all the design work seemed to be very user-focused. I really wish that this had been available to me as an undergraduate or (especially) now as a part-time postgraduate (where actual physical attendance is sporadic).

Tom Coates spoke about his blogging experiences. Another in the line of those who have been doing it fairly intensely for about five years and have gone through the cycle of loving it, feeling their privacy invaded, getting bored, and so on. I’m sure there’s a cycle that is repeated across bloggers that is just as predictable as the shock, denial, anger, depression, acceptance cycle of the grieving process. I liked it when he called Dave Winer the “Arch Demon of Webloggery”. His core point was that a weblog is a representation of a person (almost like a suit you wear) and that anything that went away from that (group blogs, blogs about one topic only) would have to have something (like money) to propel them along or they would only be short-lived.

Neil McIntosh of Guardian Unlimited talked about how the Guardian’s blogging was started on expenses on a credit card because of the difficulty of getting it through IT. Their blogs are closely watched for offensive and libellous comments but the default response is hands off. He explained how blogging enabled the newspaper to get valuable feedback and sometimes correct mistakes before they went to print. He went some way towards refuting his own quote, “mainstream media trying to do blogs is like watching a vicar disco dance”. What he didn’t do was explain how the Guardian could make money off blogging. He sees the work as experimentation in a new form of journalism rather than having a responsibility to produce revenue or even promote the Guardian brand.

Dominique Busso, CEO of VNUNet Europe talked about their “corporate blogs” — approximately one for each print magazine that VNU produce. He quoted Dan Gilmore: “my readers know more” and said that the blogs for the print journals stopped the print journalists having web envy of their online colleagues as they had done during the bubble.

Charlie Schick from Nokia Lifeblog tried to convince us that blogging from your phone is a good complement to blogging from your computer. He’s never seen my phone, then. One interesting point he made is that with cameras in phones geting better and going up to VGA quality and beyond, posting from your mobile is prohibitively slow and that 3G won’t fix this because it is still slow upstream, just fast(er) downstream.

Far more complete notes were made on this event by Suw Charman.

Mind Hacks at Foyles

Tom Stafford and Matt Webb were at Foyles on Charing Cross Road (London) on Wednesday night to publicize their book Mind Hacks (O’Reilly). They stepped through a few practical examples of the stuff from the book — why faded jeans make your legs look good; how eyes and the brain adapt to light and noise levels; why putting a pen in your mouth and pushing it back for three minutes makes you feel good — fairly successfully and made some jokes about leopards.