Wednesday, September 21, 2011

Fixing GRUB

Grub seems to be a constant source of problems.  After updating my Ubuntu I got an error along the lines of "grub may need sorting out for various reasons".  I hate it when it does that, because if it does go wrong, you're usually stuck without a computer and are thus unable to browse the internet to find out how to solve the problem, a'la Catch-22.  Needless to say, when I rebooted, I just got a completely blank screen, not even a cursor flashing in the corner.


Anyway, for my own reference, here's what I did (after booting from a LiveCD - what did we do before LiveCD's?)

Mount the disk:
sudo mount /dev/sdX /mnt


Re-install Grub:
sudo grub-install --root-directory=/mnt /dev/sdX
Obviously, change the sdX bit to point to your HD.
If you're a real masochist, you could try reading this.

Tuesday, September 06, 2011

How to be a productive programmer

Here's my humble checklist of what I think are the most important requirements for being the kind of programmer that can create something ultra-quickly.

* A stock of library code, built up over years so that simple and common tasks are already covered by a pre-written function or two.
* Be either the only programmer on the project or have your area clearly defined, and not be dependant on someone elses code that is still being produced.
* Have it clear in your head exactly what you are creating and how it is generally going to work.
* You have already "solved" any major technical hurdles that you know you are going to encounter.
* A quiet-ish place to work.
* A desire to actually create this program.
* Access to the internet to solve those niggly problems or to copy-and-paste code from websites.
* As a bonus, have a similar project that you previously created that can be easily subverted to the new task.

If you've got the above covered then you should be able to churn stuff out quickly, and then you can spend the rest of your time writing your own more interesting projects.

Tuesday, August 16, 2011

Megaproject #2: Worldcrafter

I call it a "megaproject" since I'm pretty convinced I can see this one through to the end without getting bored or sidetracked onto something else.

It's called Worldcrafter. In a nutshell, it's a 2D Minecraft-style game for Android. Yes! Another one! This is what it looks like so far, after about 5 days since I started (most of those days being spent trying to decide what to call it):-



Does the world need another Minecraft game? I'll let the world decide. What I like about writing this kind of game (and what I like about Stellar Forces) is that it's almost "modular". You (i.e. me) can play a bit, then think "ooh, wouldn't it be good if it did this". And then add it. However, the basic game is quite easy to get up and running, and that's the important bit when starting a new project: have something playable ASA-goddam-P.

Friday, August 12, 2011

Domain Squatters Can Die!

If you've ever tried finding a domain name for your new project, no doubt you'll have come across the problem of cybersquatters, the vermin that polute the internet with ad-farms by buying up any and all domains that might be remotely useful for anyone. The rest of us have to try and think up obscure domain names that still try and relate to whatever subject our website is about, and hope people will still be able to find our site on the net.

Of course, you can usually buy a domain back from them if you want, using one of the their very helpful "make us an offer" forms. Gee, thanks. You're doing mankind a service.

Friday, July 29, 2011

Software Patents Metaphor

I'm a chef, and I've just patented a new recipe: chips with *2* sprinkles of salt over them. So if I see anyone sprinkling between 1 and 3 sprinkles of salt over their chips, expect a letter from my lawyer.

-- Update --

I've just had an amazing idea: chips with 3! Yes 3! sprinkles of salt over them! I don't know how I do it. I might start to sell this new recipe over the internet, but of course it will take you more than 1-click to buy it.

Thursday, July 21, 2011

Tower Invaders: Hints'n'Tips


It was my deliberate intention to make Tower Invaders quite difficult from the start. I didn't want players to have to wade through loads of screens of baddies before they got to the challenging bit.

Anyway, here are some quick hints'n' tips for those who might be having some problems defeating the invaders. I like to think of the game as more of a puzzle or even strategy game. There is a lot of strategy involved in what at first seems to most simple of choices:-


* Position of towers is important!
Even though the invaders move from left to right (and back, and so on) covering the whole width, the position of the towers is still very important. Statistically, the invaders will be mostly above the middle of the screen, so that is the best area to place your pulse lasers. However, this also means that this is where the most bullets are going to fall; if you have the full version, shields are a good idea, especially on towers you've spent a lot of creds on upgrading.


* Sell towers that are about to be destroyed!
You will get the same amount of money back for a brand new tower as for one that's about to crumble. You do get more for upgraded towers, though obviously not as much as you paid for them. Wait until a tower is about to go belly-up before selling it.


* Keep Zappers to the side!
Since Zappers will always hit an invader, keep them out of the way of bullets. As mentioned earlier, the most bullets will fall in the middle of the screen, so you might as well build Zappers to the far sides, where they will have much less chance of being hit.


* Upgrade towers to limit your exposure!
It costs the same to buy two towers as it does to buy one and upgrade it. Even though an upgraded tower will shoot about 10% less than two basic towers, those two basic towers cover twice as much area, so they have twice as much chance of being hit by a bullet. Also, you'll need 2 shields to protect them. Of course, they will be able to incur twice as much damage, so things aren't always so clear cut.

Thursday, July 14, 2011

Android Apps: Minimum Price

After putting my first paid-for app on the market place, I noticed that the minimum price you can sell an app for in the US is 99c. This is strange, since it's possible to sell it for 50p, which is less than 99c. Isn't it usually the UK that gets the raw deal where price conversion is concerned?

Tuesday, July 12, 2011

My First Android Game!


I've just released my first Android game with the help of Dipper (who provided the graphics) called "Tower Invaders". It's a bit like Tower Defence mixed with Space Invaders, and (even though I say it myself) I actually quite like playing it, which is always a good sign.

It's free and available at https://market.android.com/details?id=com.scs.towerinvaders.main.lite. Let me know what you think!

Friday, June 10, 2011

Float.MIN_VALUE Craziness

Did I miss a memo? How can this be right:-

float f = Math.max(Float.MIN_VALUE, 0f); // Returns "1.4E-45" (i.e. Float.MIN_VALUE I think)

What? Maybe I missed something in the documentation that said "Please note that this function is crazy." Unless the logic of "closest to positive infinity" means that Float.MIN_VALUE is actually closer since it loops round backwards. I hope not.

Friday, May 27, 2011

Android Rect Confusion

Jesus christ! That's all I have to say on this subject. Apart from the following:-

In their wisdom, Google decided to give the Android function Rect.intersect() a side effect. Without reading the docs, you would naturally assume that something like:-

boolean b = rect1.intersect(rect2);

would be reasonably straightforward, returning true or false depending on whether the two rectangles intersected. However, if it returns true, it also sets rect1 to be the shape of the intersection. WTF?? Wouldn't calling the function something like getIntersect() be a good idea?

There is a function called Rect.intersects(), which does do what you'd expect (and avoids doing what you wouldn't expect); so just remember to add that little 's' at the end of the function name because it makes all the difference.

Tuesday, May 10, 2011

I got the call!

Last month I got an email from someone at Intel asking if he could call me about porting Stellar Forces to work on AppUp. We did, and had a quick chat about it and AppUp in general, which seems like Intel's take on the AppStore/Marketplace. I checked out the documentation that was emailed to me, and looked at the website. It wasn't going to be a small job, they obviously weren't going to pay me to do it, and it's a free game so I make no money from it anyway.

However, eventually I came to a page that listed the Java SDKs, and noticed the lack of a Linux version. I sent an email back to confirm if this was the case, which would be a showstopper for me. That was about 4 weeks ago and I've still not had a reply.

It's a bit crap that they expect me to spend the time converting a game to their system (without any financial benefit) but they can't even be bothered to send an email as soon as there's nothing in it for them.

Friday, February 25, 2011

Dependency Hell

I seem to be stuck in Dependency Hell when trying to write some Java code that will compile Java source; I'm trying to use Apache JCI but it's turning into a nightmare. Here is the list of all its dependencies, which need to be downloaded one by one (at least, I can see nowhere where they are all included in one nice download).

But unfortunately, at least one of the dependencies (as I could see no point looking for any more) doesn't exist, and I can't find it after lots of Googling. So, as far as I can see, there is no way to use Apache Commons JCI.

Thursday, February 17, 2011

My Adage

Everyone else seems to have one, so here's my "programming adage":-

"The worst thing you can do as a programmer is write new code."

Discuss.

Tuesday, February 15, 2011

A Bite at Java Bytes

After using Java for so long, I'm still surprised that you can't write something like:-


public byte addNums(byte a, byte b) {
return a+b;
}

// Call the function:-
addNums(1, 2); // Get a compiler error??


The compiler error is because the 1 and 2 are ints by default, and the function is expecting bytes. Surely it must be able to work out that 1 and 2 are bytes in this case, not ints? To get it to compile you need to write:-

addNums((byte)1, (byte)2); // Get a compiler error??

I don't normally mind verbose code as long as it adds information for the programmer, but this is pointless.

Tuesday, November 30, 2010

Databases and Threads

The usual disclaimer applies to this post: millions of people probably already know this, and will be thinking 'What? And you call yourself a programmer??'

What could possible be wrong with the following function:-

public int RunIdentityInsert(String sql) throws SQLException {
Statement stmt = (Statement) conn.createStatement();
stmt.execute(sql);
return getScalarAsInt("SELECT @@IDENTITY AS NewID");
}

How about the bane of my programming life, threads? I've got loads of programs that have been running on servers for years using the above code, and mostly without a problem. Until yesterday.

My function added a record to a table containing about 6,000 rows, but the insert returned an id of about 250,000. It was only after looking at all the other possible reasons that this probably cause hit me: what if another thread ran another insert statement at pretty much exactly the same time? That would surely cause the same symptoms.

To be honest, I don't actually know if that was the cause, but it seems to me that the code should look like this:-


public int RunIdentityInsert(String sql) throws SQLException {
synchronized (conn) { // Need in case another thread also does an insert!
Statement stmt = (Statement) conn.createStatement();
stmt.execute(sql);
return getScalarAsInt("SELECT @@IDENTITY AS NewID");
}
}

Wednesday, November 03, 2010

Why I like Java:

Because when I wrote a slow crap program, everyone blames the language and not me!

Thursday, July 22, 2010

The P*ssed Off Blog - Munin

I now update this blog rarely, and the only time I will probably write here is when I'm COMPLETELY P*SSED OFF with some software or other. And today it's Munin, a program to profile server, like network and CPU usage etc...

It seems like a great program, and worked great on my local VM which is running an old-ish version of Ubuntu (Hardy Heron, 8.04) and version 1.2.5 of Munin in Synaptic. I had it up and running in minutes thanks to this article.

Of course, you might have an idea what's coming; it's what happens with most great software programs: the programmers don't know when to STOP F*CKING AROUND WITH IT and start adding/removing features and generally making something that "just worked" into a friggin' nightmare to use.

After I installed Munin (1.4.4) on the latest version of Ubuntu (Lynx, 10), I ran into problems trying to run it. Unhelpfully, when trying to run Munin as root, it comes up with the message "this program will break if you run it as 'root'...". Jesus, I'm not some n00b. Anybody who wants to run something like Munin is not a casual computer user, and knows the problems associated with running everything as root. But no, the programmers of Munin obviously think they know better and want to protect us from ourselves (and getting any work done).

The older version of Munin has a switch (--force-root) to over-ride this. But that was too helpful so THEY'VE TAKEN IT OUT. Thanks a lot. The message does come with some help: "run it as user 'munin'". Erm, ANY CLUE AS TO WHAT THE PASSWORD MIGHT BE? No? Thanks for nothing. I've tried "munin" and blank, but no joy and Google doesn't seem to be able to help me either. I'm not even sure that would work anyway, as the file referred to in the "permission denied" error I get is owned by root. So do I have to chmod loads of seemingly random files to allow user 'munin' to edit them? Surely that's no way to have a secure system?

So to sum up, I got the older version working in about 5 minutes, but so far I've spent a couple of hours on the new version and got nowhere. Thanks, munin programmers, for taking Munin backwards. I won't be using Munin again, but that's more because I COULDN'T IF I WANTED TO than due to any principles and animosity.

Thursday, April 01, 2010

Eclipse and Subversion [SOLVED]

This is mainly a note for future reference for myself, since I always seem to have an ABSOLUTE F*CKING NIGHTMARE trying to get Subclipse working on any new install of Eclipse. Thankfully it seems to have got better in the last few months now that Eclipse automatically finds dependencies, and you don't have to realise that Subclipse requires Buckminster, Buckminster requires ECF, and ECF requires Equinox until YOUR HEAD EXPLODES.

Anyway, now all it seems you have to do is select the Tigris update site as per here and select all the Subclipse components.

Then finally, for the magic step that makes it all work that took me about 3 hours searching the internet for, you have to right-click on your project and select Team -> Share.

(Why it couldn't realise that a project is already in subversion by seeing if there were any .svn directories is something I can't answer. There may be good reasons for this).

Friday, January 08, 2010

Developing a Community

One thing I always aim to achieve with my games is developing a community around them. This has pretty much eluded me (at least to my standards) until now, as there there is a small community playing Stellar Forces.

However, I'm confused. I've just looked at the main page of a new game called Mule, which is an online remake of an old C64 game (which I've never played, BTW as I'm an old Speccy user and it would be against my religion to do so). As far as I can tell, it's only been going since December last year, and it already has over 8,000 registered users! There other stats are impressive to - 1,600 forum posts, 2,800 games played etc...

So my question is "What are they doing to get that many users?" It's obviously a far more polished affair than my own effort - is that it?

Monday, January 04, 2010

Use of Overriding Methods Considered Harmful

I've come to the conclusion that overriding methods is a bad idea.

You know the situation; you've subclassed another class, which has a method in it that's not quite perfect, so in your subclass you write another method (giving it the same parameters) that does something slightly different.

Cue several months later, and you innocently edit the method in the parent class, changing the method parameters. Suddenly bugs appear left right and centre. "But how?" you ask yourself.

Well, it's because the method in the subclass is now never called since the method signature is different to the parents signature. But how were you supposed to know? Exactly!!