Tuesday, June 28, 2011

Developing software is a lot like solving a Rubik's Cube. I know that software --> Rubik's Cube analogies are overused, but allow me to make my case:

Ripley Rubik is a customer who approaches your company, Cubits Solutions, and explains he has a problem. His company, Rubik's Polychromatic Six-Sided Wooden Enjoyment Cubes, uses a wooden block as part of their manufacturing process. Each side of the block is comprised of 6 colors: green, red, yellow, blue, white, and orange; with one side having a seemingly random mix of all 6 colors. He explains to you that his employees currently have to search all over the block to find all the blue parts, then all the red parts, and so forth until all parts of each color have been found. The problem is, this takes a lot of time and employees, and he's looking for a way to speed up the manufacturing process and cut down on costs. You think you can help Ripley out, so you schedule a meeting with your chief architect, lead developer, interface designer, and project manager.

During the meeting, everyone decides that having more of the colors grouped together would definitely speed up the process. Since a cube has 6 sides and there are 6 colors, it's decided that having no more than 3 colors on each side would significantly reduce the time spent searching for all the colors. Ingrid, the interface designer, creates some drawings based on this, and you show them to Ripley.

Ripley immediately rejects this idea and tells you that, while he likes the idea of grouping together the colors, your design won't work because the center portion of each side can only be one color, and each side has to have a different color at the center. You return to the drawing board, and the team comes up with a new design: each side would have a single color at the center, and the 4 corners of a side would also be the same color as the center.

Ripley likes this idea, but he's concerned that it will still take too much time to search for all the colors. Ingrid suggests that there could be only one color per side, and everyone loves the idea. She creates another set of mockups and shows them to Ripley. Unfortunately, Ripley says this won't work because the layout is all wrong - his process requires that white be on the front of the cube, with red on the left side, orange on the right side, green on the top, blue on the bottom, and yellow on the back. You suggest that, instead of a cube, you create a suite of squares, one of each color, so that Ripley could orient them however he likes. He rejects this idea because he knows his budget would never allow for the maintenance of six separate tools, and he'd really prefer a single cube so that a single employee could use it if necessary.

With these new requirements in mind, the team goes to work on writing a requirements specification. Ripley signs off on the design, which says something to the effect of "The product must be a wooden block with six sides (a cube). Six colors must be represented on the cube: green, red, yellow, blue, white, and orange. There can only be one color per side, and each side must be a different color. The colors must be oriented as follows: white on the front-facing side, red on the side to the left of white, orange on the side to the right of white, green on the topmost side (above white), blue on the bottommost side (below white), and yellow on the rear side (opposite of white)."

Now that the requirements have been specified, Archie, your chief architect, goes to work on the technical design. His first suggestion is to build a new layer on top of the current design (the random assortment of colors) - he could paint a solid color onto each side rather than build the entire project from scratch. However, Lenny, the lead developer, points out that this solution would end up leading to more problems down the road because the underlying colors could still cause problems if they bleed through to the top layer. Percival, the project manager, agrees this could be a problem, and he also asks Ripley if his budget allows for a complete rebuild, or if he'd rather they adapt his current wooden block.

Ripley decides it would be too costly to build an entirely new block, so the team will have to build upon the current design. Since the requirements have changed again, Percival amends the requirements specification to read "The product must build upon Rubik's Polychromatic Six-Sided Wooden Enjoyment Cubes' current wooden block."

Archie goes back to work on the architecture, and comes up with a plan to divide the cube into smaller squares. Each square would contain a single color, and these squares could then be moved around to their proper side. In order to facilitate the movement of the squares, he comes up with a system based around a central core, where each square would be able to pivot around on screws and springs. He first divides each side of the cube into 5x5x5 squares, but decides this is too complex and reduces it to 3x3x3.

Lenny likes this idea, but he's concerned that the wood will be very difficult to affix screws and springs to (in addition to being difficult to maintain later down the road), and suggests they look into a new technology called plastic. Percival brings this idea to Ripley, who decides that the initial cost of remaking his cube out of plastic is indeed worth saving maintenance costs later on. Percival amends the requirements again to replace all instances of "wooden" with "plastic", and Cubits Solutions hires a new developer who's an expert in plastics.

Lenny and Archie design a system of rotations to put the blocks into place. They come up with some algorithms for moving the squares around, and decide that they will only rotate one side at a time. They decide to call the sides L, R, U, D, F, and B, for left, right, up, down, front, and back, respectively. They create a new framework called Solve which specifies individual operations which can be performed on a section of squares: CW and CCW, for clockwise and counter-clockwise rotations. In order to perform an operation, a developer would write "LCW" to indicate that the left side should be rotated clockwise.

With the new cube fully designed and planned out, development can begin. Percival plans out a workflow for the developers, and it's decided that 6 developers will each work on an individual color/side. With the guidance of Lenny and Archie, he decides that each developer will first align the corners of their side, and then move on to the other squares. Developers will spend the day writing down the steps needed to align their colors (FCCW, UCW, RCW, etc), and at the start of the next day, they'll take turns rotating parts of the cube and spend the rest of the day writing down new instructions. The developers write down the first day's instructions and then go home.

At the start of the second day, Bluto, the developer assigned to blue, performs all of his rotations and aligns the corners. However, once Rory, the developer for red, performs his first rotation, it's immediately clear there's a problem - blue's side is no longer aligned! Percival sits down with Lenny, Archie, and the developers, and they start to come up with a new plan. They decide to only operate on certain sections of the cube at a time, and Solve's algorithms are refined to allow more complex operations which preserve the structure of other parts of the cube. A new development plan is written that allows developers to take turns performing operations instead of doing a large set of operations at once.

Furthermore, they implement a test plan to be used after each operation: each side would be checked to ensure that no pieces were moved unexpectedly. Additionally, once a corner or section was put into place, developers would verify that the colors were still aligned correctly.

Percival continues to oversee development while keeping Ripley updated on the project's progress. After two weeks, all sides of the cube have been aligned to a single color, and the team checks this against the requirements to ensure that everything is as it should be. Ripley is pleased with the product and happily writes a check to Cubits Solutions. Success!

So there you have it: an unnecessarily long story which both attempts to explain software development in terms of a Rubik's Cube while also demonstrating my ignorance about how solving algorithms actually work =)

No comments: