Tag Archives: rant

When Does Counting Lines of Code Make Sense?

ALERT: I’m not pulling any punches with this one. If you are looking for a balanced argument including thoughts on some potentially good reasons to measure LoC, you won’t find it here. The best reasoning I can give for the existence this article: it gives me something to point people to when they ask for my opinion on the topic.

Counting Added Lines of Code as a Measure of Productivity

“Any process or procedure that incentivises based on creation or destruction of lines of code is missing the point entirely.”

David Adsit
Software Craftsman – Pluralsight

Counting LoC drives bad behavior and is easily manipulated. It leads to developers being less concise and writing code that is difficult to maintain. There are so many ways to write code less efficiently and these are exploited in a scenario where LoC are measured for productivity.

Here is one extremely simple example of code inflation:

Arrays.fill(array, -1);

and

for(int i = 0; i < array.length; i++)
{
  array[i] = -1;
}

The above examples logically equivalent in Java. They both work. They both do the exact same thing. In C# the first could look like the following:

array = Enumerable.Repeat<int>(-1, array.Length).ToArray();

We could also write our own C# extension method to match the simpler Java method and use it throughout the code in future improving readability and maintainability.

public static void Fill(this int[] array, int fillValue)
{
  for(int i = 0; i < array.length; i++)
  {
    array[i] = fillValue;
  }
}

Once complete, it would be executed as follows:

array.Fill(-1);

This approach would lead to a couple of additional lines when it is first written ONCE and then only one line to do the same work forever after. Assuming of course that people know the extension method exists and they use it… another discussion perhaps.

One of the reasons we use modern programming languages is because they are expressive and easy to read. Even in a current modern language, older and more verbose approaches are still valid in code (to enable us to customize better approaches on our own that are not supported by the framework) and can easily be exploited by developers looking to boost their LoC written.

Counting Added LoC as a Measure of Productivity Must be Based on False Assumptions

“[Counting lines of code as a measure of productivity] presumes that each day or week or month is the same as the last day, week, or month, and that the thought stuff we actually get paid to do doesn’t matter.”

Dwayne Pryce,
Senior Software Engineer Microsoft Research

Measuring added LoC also assumes the work completed before, after, and during the coding process to determine best/cleanest/most maintainable/efficient approaches are meaningless and that testing to verify that the code does what is was intended to do is a waste of time.

Additionally, less-experienced junior developers are always going to write more lines of code than senior people for a variety of reasons.

  1. Junior people often take the easiest, most brute force approach because they haven’t learned to do it better. Yet.
  2. Junior people are given less complex tasks to solve that can be done more quickly.
  3. Progressively more experienced people have additional increasing responsibilities (for example mentoring and training less experienced people, doing more code reviews, being involved in architecture/design discussions, taking on difficult roles like security guild, creating documentation, etc.

1 and 2 are arguably best solved by pair programming. Another discussion. Another time.

Counting Removed LoC as a Measure of Paying Technical Debt

“Simplicity is the ultimate sophistication.”

Leonardo da Vinci

Same as measuring added LoC, counting removed LoC drives bad behavior and can lead to developers writing code that is intentionally overcompact and difficult to read. However, in a large and unwieldy application, we want to remove lines that serve no purpose at every opportunity while maintaining the same functionality. If this were trivial, we could simply automate programming and developers would no longer be needed. Making things simpler is, simply put, not easy.

Counting LoC as a Measure of Quality

In the history of computer science, there has never been a valid correlation between LoC and quality in any programming language in existence. Check the textbooks, the internet, or anywhere else you can think of. This correlation does not exist.

The Burden of Unnecessary LoC is Non-trivial

“Measuring programming progress by lines of code is like measuring aircraft building progress by weight.”

Bill Gates

I’ll use a slightly exaggerated example here, but it isn’t too far off, so please bear with me. Let’s assume we have two people attempting to solve a difficult problem.

Persona A

  1. may be less experienced or expert beginner
  2. just get’s it “done”
  3. tends to solving problems hastily without concern for introducing bugs
  4. often works quickly and on their own without taking time for design discussion, planning, and refactoring
Persona B

  1. may be more experienced
  2. cares about quality and hates bugs
  3. aims to understand the scope of the problem before starting to solve it
  4. involves others (seeking real input) to suss out design flaws and make take more complex problems to a mentor

I’ve seen real life scenarios where Persona A will solve a similar problem in 2000-3000 LoC where Persona B would solve it with 200-300 LoC. That may not seem so bad. Maybe Persona A finished their effort in less time than Persona B. Now consider, from the time this code goes into production until it is replaced/removed/refactored/decommissioned, we have to pay to maintain the code that was written. When we want to make a change in the behavior of the

Maybe Persona A finished their effort in less time than Persona B. Now consider, from the time this code goes into production until it is replaced/removed/refactored, we have to pay to maintain the code that is written. When we want to make a change in the behavior of the code or add a new feature, Persona A’s code may require days of review to understand and will also require many changes to achieve. To make a similar change to Persona B’s code, it could be understood in an hour, perhaps. The changes should take considerably less time depending on their complexity.

When we want to make a change in the behavior of the code or add a new feature, Persona A’s code may require days of review to understand and will also require many changes to achieve. To make a similar change to Persona B’s code, it could be understood in an hour, perhaps. The changes should take considerably less time depending on their complexity. Of course, this scenario is hypothetical. This is my one apology for rhetoric.

Coda

For clarity’s sake, I’m in no way arguing against hiring junior people. Fresh blood is vital for tons of reasons I won’t go into here. However, the effective incorporation of junior people must be accompanied by the correct structure and support from more experienced people in order for them to succeed. I AM against hiring expert beginners who’ve been doing this work for many years and thinks the “just get it done” approach is the best/only way.

 

Movies: Physical Or Digital Media (Legally?)

The Problem: Physical Versus Digital Media

Let me begin by saying I’m a programmer and we are, by definition, lazy. I despise physical media for its inefficiency and general in-the-way-ness. DVDs, CDs, cassette tapes, VHS, etc. The only real exception here is books. Something about holding a dead tree… but I digress.

digital media

I’ve gone out of my way to digitize everything possible for many, many years and it hasn’t always been easy. Recently, laws have been passed that say you can’t even make a copy of your own physical media for backup or viewing on your computer or media device. I’m certainly as willing to pay for digital content as the next guy. You just have to make the value proposition worthwhile. That’s all I ask.

Why Is Getting A Copy Of Digital Media So Hard?

The first time I tried to redeem a copy of a Blu-ray in digital media format via UltraViolet (http://www.uvvu.com/) was a couple years ago. It was some movie we had bought and I’m not sure I even remember why… probably just because we wanted so badly to support the people who made it. I get that way sometimes. Great work should be encouraged with cold hard cash.

Frankly, the UltraViolet process was TERRIBAD. Account creation was a joke and once I finally made it through that travesty, I couldn’t get the movie to register in the system. I tried again at some point not too far in the future (due to an unrealistic sense of optimism) and was again devastated by the total lack of anything resembling working software from UV. I downloaded a copy of the movie through alternative means at this point and forgot about the whole thing.

A New Experiment

Fast forward to last week… I am in the unique position of having my electronics infrastructure spread around the United States and I find myself buying DVDs/Blu-Rays more frequently than I normally would given the lack of available alternatives. Couple that with the fact that the missus had a flight to California scheduled and wanted to watch the copy of The Hobbit we just purchased on her Kindle Fire. Staring down the possibility of shelling out cash for a digital copy direct from Amazon, and paying AGAIN, I found myself gazing upon the UltraViolet sticker on the dragon-hoard pilferer’s Blu-ray and thinking to myself:

There is no possible way this will work, but I have to try.

The digital rights for the movies are kept by UltraViolet but it turns out that I can actually redeem them through Vudu (http://www.vudu.com). Vudu also works on iOS, Android, PC, and a ton of other devices as well. I’m vaguely familiar with Vudu because there is an app for it on my PS3 so I figure, “cool, I’ll be able to watch it there as well if by some freak chance it actually happens to work”.

I begin the registration process on Vudu and… it. is. surprisingly. simple. It asks me to link my UltraViolet account OR it will go ahead and create one for me if I don’t have one. I choose life:

It lets Vudu do the work so it doesn’t get the hose again.

This seems to be going okay but I’ve yet to enter the code for the movie. I search for the movie regarding the adventures of the esteemed Mr. Bilbo Baggins, click the button to redeem my UV copy, and presto-chango! I now have a digital copy of the movie that I can either download or stream through Vudu… apparently at will! I click play and the movie queues up as fast as anything on Netflix. No complaints there.

Next I navigate to “My Collection” on Vudu and find that they have gifted me with 10 other random movies that are now synced to my  UltraViolet account as well. Some of them are even good!

Now, some of you may see the problem that I ran into next… there doesn’t appear to be a Vudu app on the Kindle Fire.

Facepalm.

Some quick Googling reveals that I could sideload the Vudu app from Google Play but that doesn’t seem to be confirmation that this will actually work. The alternative is to create a Flixster (http://www.flixster.com/) account, attach the UltraViolet account to it, and watch the movie through that app which IS available on the Kindle. My sense of foreboding returns as I can only imagine that using the UV account with more than one movie vendor is going to cause a giant charlie foxtrot… if you take my meaning.

Strangely the process is pretty smooth. To my delight, the Flixster account now has access to not only the short, round, furry-footed fellow from The Shire, but also all of the free movies I received from the Vudu signup process. IT’S LIKE MAGIC THAT ACTUALLY WORKS WHERE IS THAT WIZARD HIDING AND WHAT IS HE UP TO?!

digital media

Now my wife has plenty of entertainment for her trip and I’m kinda stoked about this whole thing. I grab the few other movies I have laying around my temporary residence and find that they are added to both Vudu and Flixster with ease as well.

This is giving me warm feelings because I’m generally happy to pay for media that I love as long as it isn’t more trouble than the alternative. I’ve long since traded in my mp3 collection for a Spotify Premium membership and generally watch anything and everything available on Netflix before looking for another source. It seems I may actually have a viable way to own the movies I really enjoy without the hassle of living on the edge of the law. If only the Television industry would make shows instantly available and do something about the prices of their series I could get behind that as well.

One final thing: Vudu and Flixster are both offering another tempting option. You can purchase digital media copies of every physical movie you own for 2-5 dollars each. This is making me pretty glad I still have that considerable DVD collection!