Coding Styles

I’ve had some good exposure to the factory design pattern lately thanks to a co-worker who came by, looked over a block of if-else statements, and threw my mind for a loop. The end result is much cleaner and clearer code. I’ve also been reading a couple design pattern books.

Today I’ve done a quiet launch of the Guild Wars (GW) Ladder API as a beta. Below is the usage comment generated by the class that, well, is the API.



format		- xml, json, php-serial
ladder		- guild, hero
limit   	- 1-1000 (guild ladder), 1-1080 (hero ladder)
offset		- 0-1000 ", 0-1080 "
name		- string 1-50 chars
column		- column name (see example output for names)
order     	- asc or desc
callback	- string 1-40 chars (JSON only)

Errors will return in requested format output. Ladders update HOURLY: please
limit your calls accordingly.

NOTE: API is subject to change without notice. Currently available as BETA.
For questions, issues, etc. please contact support regarding "GW LADDER API".

It’s not a very complex piece of code but I wanted to make sure that it complied with best practices in API design, flexibility, security, scalability, and RESTfulness. I think as people discover it and start using it I’ll get a better feel for how its being used. Right now folks scrape our ladders parsing HTML from our ladder pages. Yuck! I’m using distributed caching (memcached) to store results and some throttling to ease the load in case load gets out of hand.

Another couple changes I’ve been making while working on new or refactoring old code is to avoid nesting ‘if’ blocks, avoid ‘else’ blocks, limiting myself to one evaluation per ‘if’, and put ‘return’ or ‘break’ code near the top of what I am doing. It has been interesting getting used to it.

for(;;) {
	if(condition === false) {

	if(something == 'yes sir!') {


I’d prefer to use something like a function and then multiple returns but the theory is essentially the same. This makes code block easier to decipher. Couple some logging into this and debugging just got easier.

Recently I fell in the middle of a religious debate surrounding stored procedures (SP) and parameterized queries. I find that although there are a lot of textbook reasonings behind using stored procedures I find no compelling reason to add another layer of code maintenance in the development stack. All the seemingly overwhelming benefits of doing SPs dematerialize once you realize you can accomplish the same with parameterized queries.

However, I see clear benefits to using SPs to encapsulate components used cross stack like web and application development. Or perhaps between multiple web applications. At that point, however, wouldn’t one rather employ the benefits of a service? And if you go the service route you are back at point one: why add another layer to maintain. I am by no means an expert on this topic but I have been very curious to find the facts. I just find that using SPs is a pain in the rear.

After cancelling my DI.FM subscription I’ve been actually able to locate a few great streaming radio stations. M2 and FG Underground out of Paris to name a couple. I’m diggin’ the Electro-House sound. Here’s After Hours (Original Mix) by Mellefresh & Deadmau5:

Crystal and I have been enjoying playing Aion an upcoming game from NCSoft that’s already made a huge splash in Asia. It’s a fun MMO that looks sexy and is interesting to play. We haven’t gotten very far but its fantastic to finally play characters in a game I’d want to be.

Other then that, I’m playing EVE but as I’m shifting to music production again so I’m sort of not all that interested in spending my limited free time playing. But dudes, I am totally having an AMAZING amount of fun playing Metal Gear Solid 4. What a great title. There are a bunch of cut scenes and sometimes it is noticeable but it doesn’t matter. It hasn’t been since Ace Combat a few months ago that I’ve been excited to continue playing a game.

This entry was posted in Uncategorized. Bookmark the permalink.

Comments are closed.