Customizing toString()

By sascha, September 8, 2008 – 2:15 am -

When writing classes for a framework I usually put a custom toString method into important classes so that debugging becomes easier. Normally they would go like something along the lines of:

override public function toString():String {
	return "[ClassName]";
}

… Sometimes adding properties to the returned String that give back information about the class, e.g.

override public function toString():String {
	return "[ImageClass, size=" + _size + "]";
}

But writing them rigid like that is a disadvantage when you decide later to refactor class names. Admittedly it’s also not a very elegant way so I got the idea to take the class name that is returned by getQualifiedClassName(). The only problem is that getQualifiedClassName not only provides the type name but also the whole package String of the class. Regular Expressions to the rescue! After twiddling around with them for a while (I’m by no means a RegExp expert) I got my toString method into the shape that I desired:

override public function toString():String {
	return "[" + getQualifiedClassName(this).match("[^:]*$")[0] + ", size=" + _size + "]";
}

This way it matches the String returned by getQualifiedClassName with the Regular Expression [^:]*$ which checks from the right end for an arbitrary text up to the first occurring colon, but without including the colon. Taking the first element of the Array returned by match() and you got what you need!

A nice way of using this is when writing abstract classes that contain the toString method and any subclass can use that toString method without the need to override it … that is of course unless you want ot add other output information.

Aw Snap! This site is not meant for you!

By sascha, September 6, 2008 – 2:22 pm -

Chrome, the new snazzy browser from Google is currently in everyone’s mouth and most people who had a look at it seem to be impressed so I decided to give it a go, after all it can’t be so bad, right?

Chrome installs right onto your system from the website and then takes over (or if you are cynical: steals) all the bookmarks, history, passwords etc. from Firefox (to make your life easier). It then opens with a slick and slender window that lacks all the tackiness of a plugin-convoluted Firefox. When opening a new tab it shows a neat history list with thumbnails of your most recent visited websites. Chrome starts up as fast as a finger snap! Maybe even faster! Can it get any better?

Read the rest of this entry »

Featured

FEAT (Freelancer’s Estimation Assistance Tool)

FEAT (abbreviation for Freelancer’s Estimation Assistance Tool) is a tool to help freelancers calculate hourly rates and project pricing estimates. It is inspired by a very similar calculation PDF sheet which was created by Lauren of creativecurio.com and by some other useful freelancer pricing resources on the net.

The tool uses the same calculations like the ones from the links mentioned above plus it stores your values so you don’t have to enter them again every time. Version 1.0 features hourly rate calculation, a project pricing wizard and an option to change the visual theme of the tool. It also resides nicely on your desktop or wherever you put it and is there whenever you need to make an estimation.

Continue Reading ยป

Using Flex 2 for GameDev Middleware

January 16, 2007 – 10:28 pm

While the whole world is hyping Rich Internet Applications, I'm sitting here in my lab and could not bother less! Flex is really neat and who says that it's only ...

Tools of the Trade Part 5: Filter Forge

December 28, 2006 – 1:21 pm

Filter Forge is a new software for Windows that allows creating Photoshop filters in a tree node based editor. Yep, thats right! You design filters by connecting components together with ...

Windows Vista the Protection Monster … and at which costs!

December 26, 2006 – 12:30 pm

Still think Windows Vista is a great OS? It might look great but whats going on under it's shiny surface? Peter Gutmann has written an extensive article about Vista's underlying ...

Guerilla Spam

December 10, 2006 – 8:09 pm

I'm getting some strange kind of Spam recently. Check out my Photoshop Script Positing! Around every week I'm getting one or two comments saying "great script!" or something similar and ...

Eclipse Tips & Tricks: How I organize my Workspace

November 28, 2006 – 12:15 pm

Here are some hints on how I organize my Eclipse workspace that you might find interesting if you want to keep all the stuff together in one workspace, not only ...

Waterproof AS 3.0 Singleton

November 24, 2006 – 11:22 pm

While reading Advanced ActionScript 3 with Design Patterns I've once again came across the AS 3.0 Singleton solution that has to deal with the absence of private constructors (I'll save ...

So you want to be an Indie Developer?

November 24, 2006 – 4:13 pm

Some links to nine articles about the topic on 'becoming an Independent Game Developer', found via Digg. Some more interesting, some less, the last one from a Mac perspective. There ...

Learn some patterns - Advanced ActionScript 3.0 with Design Patterns

November 23, 2006 – 8:16 pm

I've been reading this book by Joey Lott and Danny Patterson since yesterday and thought I'd loose a couple of words about it ... The book starts with a chapter about ...

Using Vista is like walking on thin ice … Vista’s EULA product activation worries

November 23, 2006 – 2:51 am

"...Once you activate the product, then you would assume that you are golden to go ahead and use the product, right? Wrong. You see, even after you activate the software it ...

Tools of the Trade Part 4: Console

November 21, 2006 – 6:08 pm

This is not really a true productivity tool but I think it has enough value that it deserves to be mentioned. If you're on Windows and work with the Command ...

Welcome to H1DD3N.R350URC3!

These are the adventures of a random guy trying to be an independant game developer, utilizing ActionScript for programming and talking abouting gaming and nonsense in general.

Need any news feed?

 Main Feed (contains all categories), Dev Feed, Design Feed, Audio Feed, Gaming Feed, Miscellaneous Feed
Find entries: