Blog

The Flyweight Pattern: (Mis|ab)used at times.

In my brief career in software development thus far, I have seen a lot of “WTF” code, that is, code that deserves to be posted to The Daily WTF. Some of this code was admittedly developed by myself and upon reviewing it a few months after it was written, I secretly wondered what I’d been thinking.

This isn’t going to be an indictment of bad programming; in fact, I think it’s good if you can look back at your old code and see where it could be improved. Such a process suggests that you are continually self-improving, a skill crucial in software development. Besides, all of us have made a mistake or two at times when we were stressed, tired or just plain not thinking straight.

However, there’s one mistake that I’ve seen that I think warrants bringing to light, and that is the misuse of the Flyweight pattern.

Continued

Goodbye, old friend…

I’ve had the same pair of prescription glasses since about 2004, having changed the lens more than once. I just got so used to them that whenever the opportunity arose to replace them, I couldn’t find a pair that felt or looked right. So, I just continued with the same old dependable pair.

They’ve fallen off of my face more than once, have tumbled many times to the hardwood floor from my nightstand while I fumbled for them in the dark, been lost in my bed covers and rolled onto during numerous occasions, and of course I’ve fallen asleep with them on more times than I can remember. Despite all of this, they not only held together, but retained much of the original lustre and remain in excellent condition.

Only one of the earpieces is starting to look worn, the nose pads are looking a little old and one of the lens screws had to be replaced when it fell out and got lost, but other than that, they’re as good as new. This was the first “thin” pair of glasses I had ever worn and I initially had some reservations about durability, so I’m more than pleased with how well they’ve held up. (I think the frames are made up of some titanium, but I can’t remember)

But this past weekend, I decided it was time to finally replace them.

We’ve had a good run, old friend, but I’m afraid it’s time to part ways.

Continued

Boston reflection and updates

It’s been two months since the 2011 Boston Marathon, which was my first attempt at this historic race. As some of you may know, it had been one of the focal points of my life for the past several months, ever since I qualified by 13 seconds back in September of 2010.

I took a new approach to training and really dedicated myself to it. There were many mid-week 4 AM mornings, followed by 1.5-2 hour runs in the dark, snow/rain and wind. I arrived at the starting line being as prepared for any race as I’d ever been.

Continued

Excess packaging

I recently ordered some extra Sanyo eneloop batteries when they were on sale at Dell. They’re great rechargeables, but I don’t know why most packages always come with a charger – I now have three of them from previous purchases.

However, when I received the package from Dell, I was surprised at the size. It came in a huge 18″x13″ bubble envelope:

Dell packaging

I thought it was just excess shipping packaging, but opening the enveloped made it clear that the packaging was only just big enough to hold the actual item:

Huge eneloop package

Green packaging?

For batteries with packaging that seems to imply they’re good for the environment, you think they would have made the packaging a little less excessive. The packaging is still 100% recyclable, but it still costs energy to make it.

At least Dell didn’t put the already-large item in a huge shipping box.

Java, Weak References and WeakHashMap

Most any Java Developer will be familiar with the concepts of references, as in pass-by-reference vs. pass-by-value. (Pointers, now that’s another thing…)

When calling methods, primitive data types are passed by value, while objects and arrays are passed by reference. This means when you call a method with an object as a parameter, you are merely providing that method a way to access/manipulate the same object via a reference; no copy is made. Contrast that with primitives: When calling a method that requires them, a copy of that value is put on the call stack before invoking the method.

In that way, references are somewhat like pointers, though they obviously cannot be manipulated by pointer arithmetic. But what about weak references? What are they, and how do they contrast with strong references?

Continued

Folding changesets with the Mercurial Queues extension

Mercurial is my distributed revision control system of choice, a trait I picked up at my previous job. I haven’t had the opportunity to deal with Git for any period of time, so I can’t comment on the various “Why X is better than Yarguments out there.

Most of you using Mercurial/Hg (or revision control in general) will be familiar with the concept of merging, where the changes in a source branch are merged into a target branch, creating a new revision or changeset on the target branch. But what about the times when you would like to combine two or more changesets/revisions into a single one that has the combined/overall changes of all of them? In that case, the Mercurial Queues extension provides for the concept of folding, which accomplishes just that.

Continued

What I’ve been up to

I’ve had a serious lapse in updating this blog with useful information, and for that I apologize. I would have liked to continue to provide helpful guides and other tutorials, but I continually found excuses to be lazy. Writing these guides is as helpful for readers as it is for me, so it’s something that I need to engage in more often if I am to continue with personal development.

With that in mind, I thought it’d be useful to provide an update on what I’ve been up to for the past few months, to keep things in perspective.

Continued

Qualified for the Boston Marathon!

On September 26th, I ran the Toronto Waterfront Marathon, thus completing the GTA marathon three-pack within one year. (GoodLife Toronto Marathon, Mississauga Marathon and the Toronto Waterfront Marathon are the three major GTA marathons) More significantly however, I qualified for Boston, getting my ticket to the event for 2011! My time of 3:10:46 qualified me by 13 seconds, and it was an epic battle for every one of those seconds. For these reasons, I felt this marathon experience to be the best of the five marathons I’ve run so far.

Continued

Completed the Mississauga Marathon!

On May 16th, I ran in the 7th annual Mississauga Marathon. This was my fourth marathon, and I’d decided to run it sometime back in March, after being unhappy with my result in the Toronto Good Life Marathon in October of last year. (Which I had run only two months after the Edmonton Marathon)

Though I had qualified for Boston during the Edmonton Marathon with a time of 3:02:50, I decided not to register for Boston after my poor performance in the Toronto Good Life race. I wasn’t sure I’d be ready again for another marathon in mid-April, and the timing with my schedule wasn’t ideal either.

However, by the start of February I was feeling better and started getting back into training mode. I had a May marathon in mind, which would give me a solid three months of training – more than enough considering the base level of training I’d maintained over the winter. However, I didn’t want to push myself and commit to something I couldn’t do – so I did not register until the end of March, when my condition was more certain.

And so when May 16th came, I was feeling pretty confident. I’d run the Sporting Life 10K two weeks before, finishing in 39:38, within my target time of a sub-40 minute run. I had a target time for this marathon of anything under 3:20, not enough to qualify for Boston since I didn’t want to push myself, since this was partly the result of why I’d done poorly at the Good Life Marathon last year.

The first three-quarters of the race went well, and I was able to maintain a fairly even pace, passing the halfway point at 1:33:55. While things went smoothly for the first 30 km, at about the 35 km mark I started feeling some slight leg cramps and had to slow things down. I lost quite a bit of time in the last 7 km, and managed to finish in 3:13:06, less than three minutes away from qualifying for Boston again.

While I was disappointed at coming so close to a qualifying time, overall I was happy with the result, having met my original target and improved substantially from my previous marathon. Despite this being my fourth marathon, I still feel that I’m very much a beginner at this, as I need to work on my overall race strategy, pacing and training if I want get more consistent results. I’ve thought about doing another marathon in the fall, perhaps the Toronto Waterfront Marathon (thus completing the GTA marathon three-pack), but I don’t want to push myself. I’ll see how the summer plays out.

Continued

Opera Mini approved by Apple for the App Store

On the heels of a controversial update to the iPhone SDK’s license agreement, Apple has unexpectedly approved Opera Mini for iPhone for distribution in its App Store.

Opera had previously announced that it had submitted its browser to the App Store for approval back on March 23rd, in an effort to drum up support for its inclusion in the App Store. Back then, many suspected it would likely be rejected on the basis of it duplicating built-in functionality on the iPhone, namely the included Safari web browser. (Though some questioned this analysis)

Whatever the reason, this comes as a surprise to many, especially given Apple’s most recent behaviour towards potential competitors and development on the iPhone in general. Nonetheless, let’s give Opera Mini for iPhone a quick test drive!

Continued

View all entries by month or by category