My Blog

Blog

View All Posts In My Blog »


Coding Kata – January 29 2010 – Playing Vegas

1.29.2010 | 4 Comments

Goal: Design and implement an algorithm to detect certain hands in a game of Poker. You are given your parameters as 5 ints [0-13] representing each value of the card. The hands to check are:

  • Four of a kind (ex: 5,4,5,5,5)
  • Full house (ex: 5,4,4,5,5)
  • Three of a kind (ex: 5,4,5,5,1)
  • Two pair (ex: 8,4,4,5,5)
  • Pair (ex: 7,1,2,5,5)
  • High card (ex: 1,2,3,4,5)

Constraints:

  • Return the String value or enum code (to your specification) representing each case

Hmmm of the day: Are there any poker hands which could fall into more than one category?


Coding Kata – January 28 2010 – Crazy List Copying

1.28.2010 | 0 Comments

Goal: Create a duplicate copy of a linked list given the following facts about the linked list:

  • Each node in the list has a pointer to the next element in the list, or null if no element is present
  • Each node in the list has a data pointer which points to any arbitrary node in the list

Constraints:

  • You are allowed to modify the list, so long as it is returned to its original state

Example:

Hmmm of the day: Can this be solved using pointer arithmetic, and if so, is it the most efficient solution?


Coding Kata – January 27 2010 – The Ski Lift

1.27.2010 | 0 Comments

Goal: Create an algorithm to determine how close you are to the summit of a mountain (percentage) whilst on a chairlift. You know the following information:

  • What chair you are on
  • The chair coming in the opposite direction visible to your left at the current time

At what point do you have an accurate estimate of your progress? When you are at that point, what is your percentage progress to the top?

Constraints: You are not given the number of chairs on the chairlift.


Coding Kata – January 26 2010

1.26.2010 | 0 Comments

Goal: Create code to rotate an N by N array 90 degrees clockwise.

Constraints: All manipulations must be made to the original array, but a single staging variable can be used.

Hmmm of the day: Can this be done for N by M arrays as well? If so, how? If not, why not?


Coding Kata – January 25 2010

1.25.2010 | 4 Comments

Goal: Design a data structure and controller to model a Connect Four game.
Your controller must have two functions, putPiece and checkForWin (using any parameters you choose).

Constraints: Your checkForWin method should be relatively efficient (i.e. it can’t have O(n2) efficiency). Think you can do it in O(n)? How about O(1)?

Hmmm of the day: The most efficient way to put a piece may seem a little ‘backwards’ at first.


Coding Kata

1.25.2010 | 0 Comments

Ever write code that looks like this?

thatll_work

If you’re saying no, then you’re either a legend or you might have some delusions of grandeur – but in any case a little practice never hurt anybody. I’ve decided to keep my skills fresh, I’m going to try and create (and tackle) a new problem every day, and I’d like to share them with the rest of the world so that you might benefit as well.

This concept is by no means new, and I encourage you to check out Dave Thomas’ Coding Kata, which is the earliest example of Coding Kata I can find. I really like the concept, but unfortunately the site is no longer maintained, so I’d like to pick up the torch and carry on from where Dave left off.

Some of them you may have come across some of before, but I’ll try to keep them as fresh as possible. I’ll also post the answer in the comments the next day for those who are interested. Karma points to whoever gets it first before that though :)


Man in the middle design

11.03.2009 | 0 Comments

I used to always be a relentless top-down developer. I deduced that it simply was the best way to go – once you create the interface the client wants, you have a better understanding of the requirements and can get feedback right away which would help cut down potential changes in architecture mid-project. Bottom-up projects often suffered costly redesigns as the client would change their minds after seeing the product and in some cases I’d have to re-invent the wheel again.. and again. After being scarred too many times, I switched over to a top-down philosophy for my app development, and have been doing it for several years now.

The procedure was more or less the same for every project. I would create my user interface in Photoshop and slice it up (or if I’m feeling exceptionally keen, straight to the code), and then piece by piece I would snap little bits of interface together to form an overall gestalt. After many refinements and tweakings, I’d prepare a demo and portfolio for my client and showcase the new interface. If all went well, I’d begin design of my Controller and Model components from then on, giddy with satisfaction that the client liked the demo.

But that’s when the honeymoon period starts to end. Quickly.

The app now has all these lofty requirements and proposed features, and there’s a substantial chasm between the various elements. Solutions pop into your head on how to connect them, some more eloquent than others, but invariably the initial solution isn’t as clean-cut as you’d like it to be. Several pads of paper and pots of coffee later, a nice design emerges for your Controller and you swiftly bind all the GUI elements to their proposed functions. Life is good. But then there’s the Model…

Travis-cavingunderpressure

After slewing through the Model, and getting that last unit test to pass, you finally have first release candidate to show to the client. You’re pleased with yourself, glad that you pulled it off and you’re happy with the results, and the client is too. The client then pulls you aside afterwards and was wondering what happened in the past few weeks. Despite the fact that you told them it was going to take a while to ‘do the plumbing’ to connect everything, they expected something working earlier than this, after all – they saw an interface with everything they wanted to see on it! How hard could it possibly be?

Time after time I find that this approach suffers from the Iceberg Effect, in addition to the dangerous waters you have to navigate through to avoid a Frankenstein app and other anti-patterns. I assumed it was the best way to go about doing things (for me) despite it’s shortcomings, and I continued on my merry little way… until this weekend.

What if you didn’t start with the View, or even the Model – and just went straight to the Controller. This way you could start on an app which knew from the ground up the best ways to interact with the Model and also the best ways to interact with the View.

The most essential moment in the development of an application I believe is when you realize how the users intent can be fulfilled, and since this is predominately Controller logic anyway, you’ve basically got the app in the bag. Here are a few pros to this approach:

  • You can construct a modular Controller around the users actions and not the nitpicky needs of the app infrastructure
  • You still have an understanding of what functionality the user will be able to use in the View
  • You don’t need to make any compromises with the design of your model
  • You won’t be a victim to the Iceberg Effect
  • Can construct unit tests right away for Test Driven Development
  • Less likely to paint yourself into a corner since you know the app’s logic and constraints up-front
  • You and the client have reasonably high visibility on the project

No methodology would be complete without it’s drawbacks though. Here’s a few which I think can come into play:

  • Longer delay in getting the interface ready means that there could be a small back-and-forth between Controller and View handshaking if the client makes repeated changes
  • More time needed up-front to flush out the design

So what do you think? Is this a steaming pile of balderdash, or do you think it’s a happy compromise in this day and age of app development? I will be trying it on my next project, and I’ll keep you posted with the results.


Why blogging, and why now?

11.02.2009 | 0 Comments

I’ve been on this earth for a while now, and I’ve had plenty of opportunities to start up a blog. I have lots of friends who do it, and I’ve been involved with web development for a little over a decade. But I’ve never thought about doing it until now. Here are a few reasons why I’m picking it up:

Sharing is caring.
Whenever I have an epiphany in thought, code or otherwise – I like to share! If ever I’ve hit a stumbling block and I couldn’t find the answer to a problem readily and I had to solve it on my own, I’d like to contribute my findings in hopes that someone who might be in a similar situation could use them to their advantage. The Internet is an excellent publishing mechanism, and I feel that as I’m starting to gain momentum in software industry, my ability to benefit others is increasing. I’m not a renowned artist, wordsmith or philosopher, but I believe that every bit of shared knowledge helps us as a whole.

The primary focus of this blog however is to highlight some of the current projects & research I’m working on, as well as some musings and any eurekas I might have pertinent to Software Engineering and Design in general.

I’ve accepted that I can’t always be right.
I’ve acknowledged the fact that whatever viewpoint I offer could turn out to be either completely wrong, embarrassing or both. It’s also very possible that I might change my mind as time goes on. In any case, I will strive to provide the most intriguing and correct information as I possibly can, and please don’t hesitate to voice your opinions on my thoughts too.

Learning by experience is huge.
All the intelligent people I know have learned from experience. When these people tell you something I’m often happy to believe them as they’ve probably been there before. When one of my parents, friends or colleagues suggest something, chances are they’re having flashbacks of the time when their car ended up in a ditch, or were called in at 2AM to fix a SQL injection issue.

And that’s exactly what I hope to offer. Anything I’ve learned whether it’s be found the hard way by mistakes or the easy way through complete luck will be accounted in turn. Take from it what you will, and I hope you enjoy.