Saturday, January 21, 2012

Play My Code: Wacky Cannon

I have always wanted to make a projectile game and now I have! I've just published Wacky Cannon on Play My Code. The aim of the game is to control the cannon using your mouse and click to shoot the purple targets. See how many levels you can complete!

Here's Wacky Cannon!

Play My Code is a place where you can create your own online games easily using the site's Quby language. The games are compiled into native JavaScript, compatible with all modern HTML5-compliant browsers. Once you've written a game, you can embed it on your website or blog, like I have done above. It's like YouTube, but for games! So, if you think you've got a game in you, head over to Play My Code and write one.

Click here to see all my games, including the popular Chain Reaction!

Did you like Wacky Cannon? Share your thoughts in the comments below.

Related posts:
Play My Code: Chain Reaction

Saturday, January 14, 2012

stackoverflow - 30k rep

Seven months after crossing the 20k milestone, I've now achieved a reputation of 30k on stackoverflow! The following table shows some interesting stats about my journey so far:
0-10k 10-20k 20-30k Total
Date achieved 01/2011 05/2011 01/2012
Questions answered 546 376 253 1175
Questions asked 46 1 6 53
Tags covered 609 202 83 894
Badges
(gold, silver, bronze)
35
(2, 10, 23)
14
(0, 4, 10)
33
(2, 8, 23)
82
(4, 22, 56)
As I mentioned before, I have really enjoyed being a member of stackoverflow. For me, it has not simply been a quest for a high reputation, but more about learning new technologies and picking up advice from other experts on the site. I like to take on challenging questions, rather than the easy ones, because it pushes me to do research into areas I have never looked at before, and I learn so much during the process.

I have to admit, I haven't spent much time on stackoverflow recently. I've been busy at work and also took up three Stanford online courses which I completed at the end of last year.

Now let's see how fast I can make it to 40k!

Saturday, January 07, 2012

Stackless Exceptions for Improved Performance

One of the reasons for standard exceptions being slow is that they have to fill in the execution stack trace for the current thread. Although, this is useful for debugging, in most cases you don't really care about the stack trace. What you care about is that an exception of a certain type was thrown and what the error message was. For example, a java.io.FileNotFoundException was thrown with message config.xml (The system cannot find the file specified)".

Stackless Exceptions are exceptions without any associated stack information. They are faster to create than normal exceptions because they don't record information about the current state of the stack frames for the current thread.

The class below is an example of a stackless exception. The fillInStackTrace method has been overridden so that it doesn't do anything and simply returns the current instance.

/**
 * An exception which does not fill in a stack trace
 * for performance reasons.
 */
@SuppressWarnings("serial")
public class StacklessException extends Exception {

    /**
     * Constructs a new stackless exception
     * with the specified detail message.
     *
     * @param message the detail message.
     * @see java.lang.Exception#Exception(String)
     */
    public StacklessException(String message) {
        super(message);
    }

    /**
     * Does not fill in the stack trace for this exception
     * for performance reasons.
     *
     * @return this instance
     * @see java.lang.Throwable#fillInStackTrace()
     */
    @Override
    public Throwable fillInStackTrace() {
        return this;
    }
}
I measured performance by comparing the time taken to create a million StacklessException and Exception objects. I found that the creation of stackless exceptions is nearly 40 times faster than normal exceptions.

You can then create more specific exception types which subclass StacklessException. For example:

public class PersonNotFoundException extends StacklessException {
    public PersonNotFoundException(String message) {
        super(message);
    }
}
As an aside, note that the JVM omits stack traces if an exception is thrown very frequently. This optimisation is enabled by default and can be disabled using the JVM option -XX:-OmitStackTraceInFastThrow.

Sunday, January 01, 2012

fahd.blog in 2011

Happy 2012!
I'd like to wish everyone a great start to an even greater new year!

During 2011, I posted 58 new entries on fahd.blog. I am also thrilled that I have more readers from all over the world too! Thanks for reading and especially for giving feedback.

Top 5 posts of 2011:

I'm going to be writing a lot more this year, so stay tuned for more great techie tips, tricks and hacks! :)