Could Code Rot be Useful in Decision Making?

P7060031

Yes. Maybe. Allowing the codebase of FlyLaTex to “rot” for about 7 months enabled me make better decisions on what features to add and what features to remove. It does seem contradictory. It seems like code rot should always have an adverse effect on your codebase. It should break stuff, right. Well, it depends on how you define code rot. My definition of code rot is a little fine tuned, I must admit. Let’s step back a little.

Defining Code Rot: It’s harder than you think

You’ve probably heard of code rot in different contexts, mostly hinged on the concept of legacy PHP code. Wikipedia defines code rot as the “slow deterioration of software performance over time or its diminishing responsiveness that will eventually lead to it becoming faulty…” [1] Robert Martin wrote an article called Principles and Patterns in which he lists the 4 signs of code rot: rigidity, fragility, immobility, and viscosity. On the other hand, a lot of people are still ambivalent on or confused  about the definitions of code rot.

These definitions are fine. But none of them recognize the power of active waiting (for programmers, of course. Not this) and its influence on feature adoption in software development. Most definitions of code rot just show how bad code rot is, how we recognize code rot, and how we can avoid it. Well, maybe we can harness the ROT. I think I did.

Code Rot in FlyLatex

I started developing FlyLatex for two reasons:

  • I noticed that collaborating on LaTex documents was painful. But no free LaTex collaboration environments were available. So I set out to create one.
  • The HackNY demofest was fast approaching. I knew I couldn’t demo the product I was developing at Trendrr. FlyLatex was a good enough product for the HackNY demofest.

I started developing FlyLaTex around early July and had to finish (for the HackNY demofest) by late July. As a result, I spent less than 4 weeks developing the product. It was 2nd priority (after the product I was working on at Trendrr).

During the development process, I had to make some quick decisions on how the LaTex writing and compilation flow should work. Where should the documents be stored after compilation? Should a user be able to compile LaTex documents remotely or not? How should the compilation errors be presented to the user? I had just learned about Amazon s3. My gut feeling at that instant was to store the compiled PDFs on s3 (via mongoose-attachments) to ease remote hosting. It seemed OK at the time.

This meant that to use FlyLatex, you’d have to have an s3 account. BAD IDEA.

After a couple of minor iterations, I had a working product. FlyLatex v-0.5.0 Beta was born (Beta in this context meant–use at your own risk). My demo at HackNY was pretty successful (except for some minor hiccups, of course). People seemed to like it. I was OK with the product. But no one used the product, I noticed. I got pretty discouraged because of this.

HackNY passed. Sad moment. My internship at Trendrr passed. Fall semester began. I was studying abroad in Budapest during the Fall.

The Hiatus

From the beginning of September to the end of December 2012, I didn’t contribute a line of code to any of my github repositories. I was too engulfed in the rigor of the Budapest program (plus, the wonderful scenary of Budapest and the rest of Europe).

hiatus

This is when the code rot started! It ended a week ago (on the 17th of March).

Harnessing the Code Rot

A week ago, I pondered using FlyLatex to collaborate with a classmate on an abstract algebra project. I tried to run it. It broke, spewing several errors. I was stunned. The last time I ran FlyLatex, it had no problems.

I spent some time trying to trace the main source of the error. It came from the mongoose-attachments.js include. Apparently, mongoose-attachments.js had changed significantly. The developers of the library decided to separate the amazon s3 upload functionality from the rest of the features. That change broke my code.

whatthinking

Then the epiphany came.

I wandered why I decided to use amazon s3 to store compiled PDFs in the first place. What was I thinking?! It’s much easier for the users to store the compiled PDFs in a directory on the current server anyways. [2] I decided to store all PDFs in a subdirectory of the FlyLatex repository by default.

It took me less than 30 minutes to change the source code (and the README correspondingly) so that PDFs would be stored in the local filesystem and not in an Amazon s3 bucket.

After the change, I posted a link to the repository on HackerNews. People seem to like it.

Should you need to make some major (or even minor) decision about your software, maybe all you need is to allow your codebase rot for a little bit.

[1] http://www.cincomsmalltalk.com/userblogs/buck/blogView?entry=3320476400

[2] This is one of the many perils of developing code alone. Had more than one developer been working on FlyLatex with me, I feel we should have to the later conclusion a long time ago.

CADglasses: Augmented Reality for Architecture Use

CADglasses is a Business Idea developed by me, Barnabás Szászi, and Endre Varga for our Entrepreneurship class at AIT-Budapest. During the class, we developed the strategy for CADglasses sales and marketing by creating marketing messages for Pioneers, Visionaries, and Pragmatists (3 of 5 tiers of the Technology Adoption Cycle, according to “Crossing the Chasm” by Geoffrey A. Moore). We also presented a Business plan on CADglasses on the last day of our Entrepreneurship class. CAD stands for Computer Aided Design. 

The Product

Problem: Imperfect and slow process of implementation of CAD designs

Well-known professional architects usually spend enormous amounts of time making graphical CAD illustrations of their building designs. But many architects still have to sometimes manually and routinely ensure that disparities between the field implementation and the building CAD designs are eliminated. However, many mistakes in the field implementation still go unnoticed until the building is inhabited. This could have adverse effects on the financial and legal prospects of some architects if the mistakes are discerning. As a result, the architect spends enormous amounts of time trying to make sure that there are not so many mistakes in the implementation of his CAD designs. But yet there’s no means or tool that the architect can use to verify that the entire building design has been wholly and perfectly implemented on ground.

Solution: Focus on CAD designs; implement faster and perfectly with CADglasses

Instead of spending enormous amounts of time making sure that his/her computer designs conform to the field implementation, the architect can use CADglasses to check for field mistakes in augmented reality. CADglasses will aid the architect not only to identify the mistakes quicker but to also implement his CAD designs on field much faster. At the end of the field implementation, the architect can use CADglasses to prove to his/her clients that there are absolutely no mistakes in the field implementation. In other words, CADglasses can be used to audit the ground implementation, therefore, improving the architect’s financial and legal prospects.


CADglasses is state-of-the-art software for viewing Computer Aided Designs in Augmented Reality on Google Project X glasses. It is targeted towards professional architects and Engineers as a productivity tool to:

  • Identify mistakes during and after the implementation of their CAD building designs
  • Chronicle the progress of the field implementation
  • From any particular position, view different angles of future construction
  • Make it easier to view, compare, and contrast past, present, and future construction models. For example, the architect might want to compare design of 1 year ago to design of 1 week ago easily without going through a lot of papers and CADs

CADglasses can be used to view CAD designs in augmented reality in any CAD format including:

  • CAD data exchange format
  • ArchiCAD library format
  • AutoCAD DXF

It works as follows:

  1. The CAD Designer (Architect, Engineer) makes a CAD using any CAD software (ArchiCAD, AutoCAD, for example).
  2. The CAD is transferred into the CADglasses product.
  3. The Designer can now view his design in augmented reality (in different dimensions, size, and time – past, present, and future). Augmented reality superimposes the CAD designs on the current view of the Designer.


There are two versions of CADglasses:

  • CADglassesBASIC is a visualization tool with minimal augmented reality features useful for professional architects and designers, urban planners, industrial engineers, civil engineers and real estate agents; and
  • CADglassesPRO has more specialized augmented reality features and more sophisticated GPS and GIS systems that help the professionals identify mistakes in the field implementations. The PRO version is mainly targeted towards architects, real-estate surveyors, Urban planners, and Industrial Engineers. It would be sold at a higher price than the basic version of CADglasses

Overall, our business idea was received well by our classmates and our Professor. The only problem with this idea is the risk of planning on creating a product (CADglasses) contingent on another (Google Project X glasses) that is not yet available in the market.

An Application of Linear Programming in Game Theory

I took the Combinatorial Optimization class at AIT Budapest (Aquincum Institute of Technology) with David Szeszler, a Professor at the Budapest University of Technology and Economics. We touched on some Graph Theory, Linear Programming, Integer Programming, the Assignment Problem, and the Hungarian method. My favorite class in the course was focused on applying Linear Programming in Game Theory. I’ll summarize the most important aspects of that class in this blog post. I hope this piques your interest in Game Theory (and in attending AIT).

Basics of Linear Programming

First, I want to touch on some topics in Linear Programming for those who don’t know much about setting up a linear program (which is basically a system of linear inequalities with a maximization function or a minimization function). You can skip this section if you are confident about the subject.

Linear Programming is basically a field of mathematics that has to do with determining the optimum value in a feasible region. In determining the optimum value, one of two questions can be asked: find the minimum point/region or find the maximum point/region. The feasible region in a linear program is determined by a set of linear inequalities. For a feasible region to even exist, the set of linear inequalities must be solvable.

A typical linear program is given in this form: max\{cx: Ax \leq b\}. c is a row vector of dimension n. A is an m \times n matrix called the incidence matrix. x is a column vector of dimension n. This is called the primal program. The primal program is used to solve maximization problems. The dual of this primal program is of the form min\{yb: yA = c, y \geq 0\}. b, A, c are the same as previously defined. y is a row vector of dimension m. This is called the dual program. The dual is just a derivation of the primal program that is used to solve minimization problems.

Having introduced primal and dual programs, the next important theory in line is the duality theorem. The duality theorem states that max\{cx: Ax \leq b\}  = min\{yb: yA=c, y \geq 0\}. In other words, the maximum of the primal program is equal to the minimum of the dual program (provided that the primal program is solvable and bounded from above). Using this “tool”, every minimization problem can be converted to a maximization problem and vice versa (as long as the initial problem involves a system of linear inequalities that can be set up as a linear program with a finite amount of linear constraints and one objective function).

There are linear program solvers out there (both open-source and commercial). Most linear program solvers are based on the simplex method. I acknowledge that the summary of Linear Programming given here is devoid of some details. Linear programming is a large field that cannot be  wholly summarized in a few sentences. For more information on linear programming,  check out this wikipedia page.

Sample Game Theory Problem

Suppose that I and my roommate Nick are playing a game called Yo!. The game rules are as follows: if we both say Yo!, I get $2. If I say Yo! but Nick says YoYo!, I lose $3. On the other hand, if we both say YoYo!, I get $4. If I say YoYo! but Nick says Yo!, I lose $3. The rules are summarized in the table below:

Daniel
Nick Yo! YoYo!
Yo! $2 $-3
YoYo! $-3 $4

The values make up the payoff matrix. When Daniel gains, Nick loses. When Nick gains, Daniel loses. A negative value (e.g. $-3) indicates that Daniel loses but Nick gains. Now the question surfaces: is there a smart way of playing this game so that I always win? Of course, if I could predict Nick’s next move all the time, then I’ll certainly play to win. But I can’t.  I must come up with a strategy that reduces the risk of me losing to a minimum and increases my chance of winning. In other words, I want to maximize my minimum expected value. So I wish to know how often I should say Yo! and how often I should say YoYo!. This problem is equivalent to trying to find a probability column vector of dimension 2 (for the two possible responses Yo!, YoYo!). Such a probability vector is called a mixed strategy. For example, a mixed strategy for Daniel could be the column vector: (1/4 \ 3/4)^T. This translates to saying YoYo! three-quarters of the time and saying Yo! a quarter of the time. My expected value is then 1/4*2 + 3/4*(-3) = -7/4. This mixed strategy doesn’t seem optimal! In fact, it’s not as we’ll see later!

This kind of Game Theory problem where we wish to obtain an optimal mixed strategy for the Column player (in this case, Daniel) and an optimal mixed strategy for the Row  player (in this case, Nick) is called a Two-player, zero sum game. A mixed strategy for the Column player is an n-dimensional probability vector x; that is, a column vector with nonnegative entries that add up to 1. The i^{th} entry of the mixed strategy measures the probability that the Column player will choose the i^{th} column. In any Two-player, zero sum game, the problem is to maximize the worst-case gain of the Column player which is equivalent to finding

max\{min(Ax) : x is a probability vector \} where A represents the payoff matrix

Analogously, the problem of minimizing the worst-case loss of the Row player is equivalent to finding

min\{max(yA) : y is a probability vector \} where A is the payoff matrix

There’s a theorem that states that max\{min(Ax) : x is a probability vector \}min\{max(yA) : y is a probability vector \} = \mu.  We call \mu the common value of the game. This theorem is called the Minimax Theorem.

Minimax Theorem

The Minimax Theorem  was proved by John von Neumann (one of the greatest polymaths of all time, I think). It states that “For every two-player, zero sum game the maximum of the minimum expected gain of the Column player is equal to the minimum of the maximum expected losses of the Row player”. In other words, there exists the optimum mixed strategies x and y for the Column player and the Row player respectively and a common value \mu such that

  1.  No matter how the Row player plays, x guarantees an expected gain of at least \mu to the Column player and
  2. No matter how the Column player plays, y guarantees an expected loss of at most \mu to the Row player

Solving the Two-Player, Zero Sum Game

Now let’s try to solve the Yo! game. First, we aim to obtain the mixed strategy for the Column player. Let x be the mixed strategy where x = (x_1, x_2)^T for which x_1, x_2 \geq 0 and x_1 + x_2 = 1. We wish to find the maximum of min(Ax) where A is the payoff matrix. To make this into a linear program, we can say \mu = min(Ax). So \mu is worst-case gain of Daniel. We wish to maximize \mu. Since \mu is the minimum possible value of Ax, we obtain the following linear constraints

  • 2x_1-3x_2-\mu \geq 0
  • -3x_1+4x_2-\mu \geq 0
  • x_1 + x_2 = 1
  • x_1, x_2 \geq 0

Solving the linear program gives us x_1=7/12, x_2=5/12 and \mu = -1/12. So the optimal mixed strategy for the Column player is x = (7/12 \ 5/12)^T. This translates to saying that if Daniel says Yo! 7/12 of the time and YoYo! 5/12 of the time, his worst-case gain will be -1/12. In other words, Daniel will lose at most 1/12 the value of the game no matter how Nick plays. According to the minimax theorem, this is optimal.

Note that this doesn’t mean that Daniel will always lose the game but that he can lose by at most 1/12 the value of the game. If Nick doesn’t play optimally (Nick doesn’t use his optimal mixed strategy), Daniel will most likely win!

Nick could obtain his optimal strategy by solving the dual of the primal program to obtain the vector y which will be his optimal mixed strategy.

The minimax theorem is an interesting and very useful application of Linear Programming in Game Theory. Two-player, zero sum games can also be solved using Nash Equilibrium which is very closely related to the minimax theorem but applies to two or more players. Nash Equilibrium was first proposed by John Nash. There are many Two-player games including Poker, Card games, Betting games, and so on. As a result, Linear Programming is used in the Casino!