Code Tips

Git Error : (does not point to a valid object)

A friend of mine IMed me the other day to ask if I had ever seen an error like the one below:

error: unable to find e291a84831b445ba982539cc63a418126f0b5364
error: refs/heads/master does not point to a valid object!
fatal: Couldn't find remote ref master
fatal: The remote end hung up unexpectedly

I had not, but it seemed plain enough. It appeared that the head of the master branch was pointing to a commit that didn’t actually exist in the repository. I don’t know for sure how this happened, but my friend’s team suspected a disrupted internet connection on push as one theory.

I Googled the error and found suggestions like “make a new remote” and “clone to a new branch, push, delete master, rename new branch”. This seemed like just too much work. There had to be an easier solution.

I was unable to clone the remote to my own machine (I got that same error on trying) and the team was in another state, so – short of a screensharing session – I couldn’t easily work with them on the problem.

I had the developer who had done the last known valid commit before this error send me the most recent 5 items output from the “git log” command and got the following (edited for privacy):

commit b65f24a64e78b38d193aa545d7b184fe26330a4c
Author: Joe Developer <joed@somewhere.com>
Date:   Fri Jul 27 10:05:53 2012 -0400

    Moved foo.jar to libs folder

commit 32b15424509881760667a77b615cc91e8e31afb9
Author: Joe Developer <joed@somewhere.com>
Date:   Thu Jul 26 21:45:46 2012 -0400

    Load swf files

commit bfac8d86c20ebbcac22af4e599e5815b0586f3d0
Author: Joe Developer <joed@somewhere.com>
Date:   Thu Jul 26 19:18:25 2012 -0400

    Navigation bug fixes

commit 60c5ff87435861157e56d948e09c63ad2f4db520
Author: Jane Developer <janed@somewhere.com>
Date:   Thu Jul 26 15:52:36 2012 -0400

    post merge

commit 1a97d137a51c6cd34825e4c9bc705620dfff7712
Author: Jane Developer <janed@somewhere.com>
Date:   Thu Jul 26 15:24:40 2012 -0400

    initial commit

Because Git is based in the file system, I could literally navigate to the remote file system and go to the ProjectName.git folder and into the refs/heads/ folder and find the master file (no extension). Inside was one string, the offending e291a84831b445ba982539cc63a418126f0b5364. I just replaced that string with the hash of the latest valid commit – b65f24a64e78b38d193aa545d7b184fe26330a4c – and then saved.

After that, I could clone the repo and the developers could pull, merge, and push their own changes. They were using DropBox in this instance as a “poor man’s remote” and upon further reflection, I have to wonder if that is what caused the conflict. Perhaps there was a problem with DropBox syncing all of the files and maybe a race condition at some point that resulted in a corruption? I know DropBox isn’t a perfect “remote server” solution, but a lot of people use it for certain circumstances, so this might be something to look out for.

If anyone else has seen this error and has a better fix than the one described here, then please leave a comment and let me know.

Code Tips

C# Extension Methods on Null Objects

Here is something that I just learned yesterday that I didn’t know. This was one of those fun things where I knew every piece of the puzzle, but had never “realized” or “made the connection” between all of them.

If you aren’t sure what extension methods are, I wrote a blog post about them back in 2008 that you can check out here.

Here is an example for today:

    public static class ExtensionMethods
    {
        public static bool IsEmptyStringArray(this string[] input)
        {
            if (input == null) return true;

            return !input.Any();
        }
    }

What I’ve done is just create a method that allows you to call .IsEmptyStringArray() on any string array to find out if it has any items in it. I realize that this is a fairly useless example, but it is contrived for the sake of the demonstration.

Now, if I call a “framework” method on a null string array, I get an error. So, doing something like this:

string[] nullArray = null;
var hasItems = nullArray.Any();

Results in the error “Unhandled Exception: System.ArgumentNullException: Value cannot be null.”

However, I *CAN* call my extension method on that null array.

string[] nullArray = null;
var hasItems = !nullArray.IsEmptyStringArray();
Console.WriteLine(hasItems);

This code produces the following result:
Result of calling an extension method on a null string array

How does that work? This is what I had neglected to put together in my mind. When you write an extension method, what actually gets compiled is this:

call bool CodeSandbox2010.ExtensionMethods::IsEmptyStringArray(string[])

The “syntactic sugar” part is that you aren’t actually calling a method on the null object at all. You are just calling your method and passing in the parameter, just like any other method. I really like that because it gives you a concise way to write your code without the same null check over and over and over again throughout your codebase. You can just check in the method and then get on with what you’re doing.

Rant

Nerds Don’t Get It

CluelessRaymond Chen recently wrote a blog post (now removed) where he talks about blocking shutdown in Windows versions since XP, and – being Raymond Chen – also the history and the why of certain decisions coming out of Redmond. This blog post was picked up on Reddit and people are slamming Windows for every possible thing.

What is interesting is that these people, who are suggesting that “Linux never had to do this”, just don’t get it. Linux is getting better, but it is *still* not user friendly. 90% of the people that work at companies that I’ve worked at could not run Linux without a lot of help. My grandparents couldn’t use Linux without a lot of help. Windows is generally easy to use.

If I generalize a bit, it almost seems like operating systems have their own “magic triangle”. You can have inexpensive, stable, or easy to use… pick only two. Linux is inexpensive and stable. It is free for the operating system and it runs on almost any hardware you can get, but it is NOT easy to use for the average “non geek”. Mac is stable and easy to use. It is known for all of its “user experience” and “it just works”, but it is not inexpensive. Once you own Mac hardware, upgrades to the OS are inexpensive, but to run the OS, you need expensive hardware. There is no good $300 Mac option.

Windows, on the other hand, is inexpensive and easy to use. It is growing more stable, but it still has a lot of quirks, particularly due to being able to support tons of hardware and tons of decades-old software. But easy and cheap is a tradeoff that many users are going to take. Because of that, Windows is going to have a place in the market for years to come, even if its marketshare will continue to erode as the marketshare of the desktop itself erodes.

But my theories about operating systems aren’t the point of this post, they are merely the backdrop. The point is that “nerds” (programmers, sys-admins, geeks, and all computer-savvy types) don’t sympathize enough with the average user. The computer elite just dismiss the average user as “dumb” and wonder why they can’t just remember to type “sudo apt-get install flashplugin-installer” to install flash on their system.

Remember, there are users that take classes on how to use Microsoft Word! They need lessons in “Saving a Document”, “Performing Cut and Paste”, and “Changing the Document’s Font”. I’m not mocking them for this, I’m pointing out the reality that these people are dealing with. To ask them to understand “sudo” and “apt-get” or scavenging the web to find some “driver” for their video card (“what’s a driver”, “what’s a video card”) is asking too much. They just want to get on Facebook, do their taxes, check their email, and watch movies or YouTube. What makes sense for we Nerds does not make sense for them.

Building up that sensitivity to the plight of the average user will make you a better IS/IT person. As long as the prevailing opinion of computer geeks is that the user should be able to perform these <my_sarcasm>easy</my_sarcasm> tasks, people that sympathize with the user are always going to have an easy time finding employment.

I’ve said this before, but I feel like it is one of the most important things I can say to the professional developer/IT pro: “We are in the business of solving other people’s problems”.

Solving other people’s problems doesn’t mean solving them with what works for us. It means giving the best solution for them. It doesn’t matter if you work for a product company or in-house enterprise development. You need to create solutions that meet your customers where they are. The sooner we realize that these things are not always in alignment, the sooner we will delight our customers with the solutions that we suggest and build.

Rant

James Whittaker Hates Search

My Opinion of Your OpinionA blog post came onto my radar today after it made the rounds on Hacker News. It was by James Whittaker and it was titled “Why I Hate Search“. Full disclosure is that James works for Microsoft, so some people have the notion that he is just hating on search (and therefore Google) because it is in Microsoft’s best interests to do so. I am someone who typically takes someone at their words and – in cases like this – prefer to examine the argument based on the facts at hand.

James’ post starts off by talking about the entire notion of search is negative and is only actually positive when the search has concluded and you’ve found what you were looking for, be it car keys, a missing person, etc. He further argues that in “real world” searching, you learn from your searches and don’t have to start from scratch every time. For instance, if I lose my keys often enough, there are four or five places that I’ll check first and likely find them. His argument is that web search is a “start from scratch every time” proposition.

James claims that it is not in search companies’ best interest to make this problem better. Those that make money from ads (hi, Google), want you searching and spending time on results pages, generating impressions and click-throughs, and whatever else they make money on. In his estimation, the alternate to this kind of product is a “find engine”, like Siri. He points out that Siri comes from a company that doesn’t have a stake in search (Apple). His quote that summarizes this position is, “There’s no more reason to expect search breakthroughs from Google than there is to expect electric car batteries to be made by Exxon.” He says that “Search is dead. The web doesn’t need it and neither do we.”

It could be that I’m entirely too stupid to understand this post or that I’m not forward thinking enough. Siri barely works if you get outside of a very small comfort zone. The way that I use Google every day is that I search error messages, and bits of quotes or lyrics, and generic problems that I can barely phrase coherently. Things like “what is the default LDAP port for Active Directory”. I just asked Siri that and she did capture my question correct with voice recognition, but her response was “I don’t know that. Would you like to search the web for it?”. In the end, it was a Google search that was performed that gave me the answer of 389.

That example is a COHERENT question of mine. What about when I need to search for something like examples of calling a SOAP web service from Android? I Google “SOAP Android” and find answers. Even if I form that into a coherent question, “How do I call a SOAP web service from Android?”, Siri says, “I don’t see Soap Web Service From Android in your address book, should I look for businesses by that name?”. Siri heard “call” and thought telephone and then screwed up the rest of the message, even though SOAP and Web Service should have given the AI a semantic clue.

I don’t want to belabor the point, though. Natural language processing will get better. However, I think that it is a pipe dream to expect that I can ask my question and Siri or the great great great great granddaughter of Siri will just give me my answer. Often in my searches, what is the answer for me is not the answer for someone else. I just can’t fathom a reality in which I can ask one question and not have a list of answers (yes, search results) to pick from. Even on Star Trek: TNG, for the hard questions, Data would ask the computer a question and have to search through tons and tons of information flowing past the screen to find the results he was looking for.

Search isn’t dead. In fact, more and more products and companies are starting to get rid of boxes where you have to search with “context” (put the first name here if you know it, the last name here if you know it) and instead moving to “Google-style” searches. The “single search box” is here whether it is Bing, Google, Stack Overflow, Sharepoint, Wolfram|Alpha, or even implicit ones like on Siri. The only difference I see between James’ imaginary future and our present is the ability for someone to give you the “one answer” that you are looking for, instead of results.

I’ve learned one thing by watching users and that is that people SUCK at search and they SUCK at asking questions, too. As long as people can’t form coherent questions or at least isolate the important parts of their inquiry, I don’t think search will ever change from the lineage that we are on.

Agile

Why I Hate Agile

Okay, now that I got the link-bait title out of the way, I am going to rant just a little bit. I imagine that I’m like most of you and I think that some flavor of agile (little a) is really the best way to develop software.

I think that collaborating with the business and getting things in front of them as soon as possible so that you can make changes to it as you go is a very valuable model. I am also very much for the short release cycles that most agile shops prefer.

What I despise, however, is what I call “Agile as Snake Oil”. There are a lot of disreputable companies that are putting the word out there that all you have to do is hire them and they can “sprinkle a little agile” on your project or your company and you will magically get everything you want.

Uncle Bob's Agile BookThey crow that Agile means that you can not make up your mind on what you want until the last minute because Agile Developers have to do what you say and are bound by the Laws of Agile to always change the software for the client. They want their cake and to eat it, too. They want all of the spec changes and none of the timeline changes or compromises.

Oh, that they would actually read something like Robert C. Martin’s book, Agile Principles, Patterns, and Practices. I’ll tell you what, I think that if people only read the end of the book, where Uncle Bob tells a tale of two cities, a project where the team does a “traditional waterfall approach” and the same project where the team practices an “agile approach”, it would make a world of difference.

As you can imagine, the waterfall approach ends in disaster, with stress and hard feelings abounding. In contrast, people are satisfied – almost happy – with the agile approach. The HUGE takeaway from the agile story, however, is that it was not a 100% win for either side. They did not hit their original deadline with 100% functionality. Features had to be traded in if the timelines could not move. However, the business stakeholders were the ones who went ahead and made that call.

I covered this in my last “Agile” post over a year ago, but I think that it bears repeating. Every agile project should do these steps

  1. Gather requirements
  2. Estimate requirements to determine length of project
  3. Work requirements in iterations
  4. Gauge velocity in coding requirements against estimate
  5. Determine whether your velocity requires you to either cut requirements or extend timelines
  6. Lather, rinse, repeat

Developers always get a bad rap for number 5 and it is always largely based on our lack of skill at number 2. Estimating is something that developers really should improve on, however, the business needs to understand two major things. Number 1, those timeline estimates are based on developers being able to work on the project at “perfect world” capacity – meaning 75-80% of their time. If developers are interrupted with conflicting priorities, original estimates and timelines are null and void.

Second of all, those who live in glass houses should not throw stones. If the original requirements are so ill-planned that they need to be drastically refined or changed, then developers should be able to refine and change estimates, too, since they are basically working on a different project than the one they started with.

There are obviously no perfect people in this world, so that means that there is no perfect system. Any system will invariably break down because of those imperfect people going around and “being human”. That being said, the best way to get to nirvana is to act like the participants in Uncle Bob’s Agile Story and rely on the two C’s, “communication and compromise”.

Compromising is the original agile. Be retro.