Pete On Software

RSS Feed

Archive for August, 2010

The Importance of jQuery ajaxSetup Cache

Johnny Cache
Just a quick note to document a “gotcha” that cost me quite a bit of time today. I am currently working on my company’s second Asp.Net MVC 2.0 application. Our first one was a huge success and (to me) MVC is way more fun and productive than WebForms, so doing as much new development using MVC instead of WebForms is a no-brainer.

Being good MVC-ites, we are doing a lot of AJAX calls. Since we are extensively using the jQuery library, we do a lot of $.ajax() and $(someSelector).load() in our code to make calls. Today, I was calling code like the following:

That code will call the Edit action on the ProductController and pass in the id of the product to edit. The controller gets the product details and then returns a partial to the page, which is then inserted into the div. I was trying to debug the controller action, but after I had edited a product once, the breakpoint wouldn’t catch anymore. I figured that I was dealing with a caching issue and the method wasn’t even being called, but I couldn’t find where I even had output caching configured in MVC.

I knew that I wasn’t having this problem in our previous application, so I started comparing files and looking for answers. Nothing was really giving me any clues, and everything appeared to be set up the same way. Finally, in exasperation, I did a “Find in Files” in Visual Studio in the other solution for just the word “cache” since searching for “outputcache” had failed me.

I dug through tons of results and then finally came across this little gem:

I had seen that in the last application, had read the documentation on ajaxSetup, but I didn’t really understand all of the ramifications of it.

Apparently, jQuery in all of its awesomeness will actually cache ajax calls for you to speed up your page. That’s definitely awesome, but unexpected caching can certainly screw up your day.

Contented Cows

Contented Cows Give Better Milk
I got the paperback version of Contented Cows Give Better Milk 8 or 9 years ago when I was working for a large financial institution. It was popular at the time to buy these by the crate and give them to anyone who was responsible for people. So, I did like any responsible employee… and finally got around to reading it this week. Better late than never, right? I want to warn you that this post is going to run a little long because I’m going to include several quotes from the book after I share some general thoughts and before I conclude.

I’m not much of a “business book” guy. In my experience, too often these books are “educationally low fat” and more about stuff that just about everyone already knows. Even this book draws some conclusions that I had already reached, however I know that I’ve worked for many employers that still don’t “get it”. In my opinion, this books deserves the reputation it gained and I think if more employers followed its guidelines, the average worker would be considerably better off. It covers topics like employee hiring and retention, productivity, corporate reputation, and enabling employees to do something great. Let me let the authors speak for themselves. (My thoughts or interjections are in bold italic)

On Hiring

“Contrary to popular belief, there really is an ample supply of conscientious, hardworking, capable, honest people.”  “You can (and must) find others like them.  You’ve got to expend a little effort doing it because ‘eagles don’t flock,’ but they are out there.” – p.37
(I love this quote, especially the notion that “eagles don’t flock”)

On Training

“We have an earnings problem, so we’re going to work out way out of it by ‘dumbing down’ the organization with less skilled, less competent people! Now the only problem will be to find dumb customers to purchase our goods and services and even dumber investors to buy our stock!” – p.154

In talking about an organization’s fading training program for air traffic controllers…
“At some point this practice was amended in favor of a train-to-proficiency approach, and the end result is now that nobody ever gets sent home or, as our friend Alex Nicholas calls it, de-selected.  Instead, you wind up with a situation where people who would have washed out under the old system are still in training and on the job years later, and every day must have their work carefully overseen by an experienced controller.  A competent employee ends up babysitting an inept one, making them both, at best, marginally productive; and both are making the same money!” – pp. 160-161
How many of you have l i v e d this?

“Why is it that no one ever ‘flunks’ a corporate training program?” – p.165

On Corporate Policies

“If you believe that most people who come to work for you are lazy, stupid, untrustworthy, inept, and just downright contrary, that assumption can’t help but show up in the way you run your business.  You’ll have all kinds of rules and regulations designed for numbskulls who couldn’t pour milk out of a boot with the directions printed on the heel.  You’ll no doubt have a supervisor for every six or seven folks, and will inevitably attract just the kind of people who will live down to your assumptions.” – p.35

Talking about how companies make mistakes and how policies can ruin a company:
“We do it through policies that are just plain dumb; systems that treat intelligent people like they’re complete morons; and cultures which ensue that no mistake goes unpunished.” – p.168

“In their private lives outside of work, your employees are heads of families, civic leaders, army reserve officers, mortgage holders, and a host of other things. Day in and day out they somehow manage to feed themselves and their families, pay their bills on time, stay out of jail, and behave normally by most reasonable standards.  In short, they tend to be rather competent individuals with a clear picture of the difference between right and wrong.  Why then, when at work, must they face a continual barrage of not-so-subtle signs of our mistrust in them as individuals?” – p.183

“If you’re unwilling to give credence to the employer/employee covenant by taking this important step, then by all means save your time, money, and breath.  Go out and hire dummies whenever your company has a job vacancy, pay them as little as possible, and don’t even think about training them–just hire a supervisor to stand guard over every two to three people.” – p.192
Wow… I know some places where this is basically the policy!

“There was no correlation between the reviews and terminations.”  Only three out of 986 people let go for poor performance received poor ratings on their prior review. “Incredibly, roughly two-thirds of these same people had also received merit increases in the six months preceding their termination!” – p.101

On Reputation

“Organizations which don’t measure up tend to be viewed as an employer of last resort; nobody with any brains, ability, or motivation wants to work there!  When this occurs, only two things can happen.  Either the organization is forced to pay market-premium wages and salaries in an attempt to secure better applicants, or it must accept the lower quality applicants, or do both” – p. 25

“We submit that inordinately high wages, salaries, and unwarranted benefits not only aren’t the answer, they are often a large part of the problem.  Moreover, they are often used as a counter-balance or way of compensating for serious deficiencies elsewhere in the organization.” – p.93

My Conclusion

Certainly not every developer is going to have an opportunity during their career to define many of these policies at their organization. However, with that said, we should not also have our heads in the sand when it comes to business. We should also remember that a strong majority of us are not paid to make software for software’s sake. We are paid to solve a business problem. These principles can help us find good solid companies to work for as well as making sure that we do our part to make the company great while we are there via the software that we write.

Why Be Passionate?

Malcolm Gladwell - Image from http://en.wikipedia.org/wiki/File:Malcolmgladwell.jpg
“Absent love for your field, you can’t be a genius. You can’t.”– Malcolm Gladwell

Scott Hanselman posted this quote on the Internet last week and it really resonated with me. It is no secret that I work in an industry full of “geniuses” and we were all most likely the smartest kids in our schools and among our relatives. Some of us (full disclosure: I can definitely be guilty here) still like to occasionally hold a somewhat lofty view of ourselves among the ranks of “the geniuses”.

Mr. Gladwell has written some very good books about ideas, intuition, and observation. I generally enjoy his writing and here I believe he is right on. I keep coming into contact more and more with developers who are not passionate about what they do. By not being passionate, they are doing their employers and themselves a disservice by not maxing out their genius potential. There are several reasons for this lack of passion – I’d like to focus on two.

The first group to consider may have at one time been passionate developers, but have since burned out. I know for a fact that this is fairly common and have come close to burnout a few times myself. Preventing burnout is a broad topic for perhaps another post, but it is beyond our scope here. I don’t think that I’m breaking new ground to suppose that burnt-out developers aren’t blazing the genius trail.

Our second group is made up of those developers who only do this because they were pressed into service at their jobs or they entered this profession because it pays well. If these people suddenly became wealthy, coding is not how they would spend their time. What that means is they are likely also not spending their free time on this craft.

I’m not claiming that individuals in either group are bad people. They are not. At the same time, however, I believe that individuals who don’t love their field will never attain guru/ninja/genius status. You cannot just put in your 8 hours and expect to be on that “next level”. This goes for lawyers, physicists, and therapists, too. If you aren’t putting in your own time reading journals, blogs, attending seminars, or just “thinking the big thoughts”, you aren’t going to grow.

The bright side is that this love can be cultivated. Much like marital love, you can rekindle your love for your craft. The same principles even apply. A common recommendation in marriage counseling is that you really get to know your spouse. Find out things about who they are and who they’ve become that you didn’t know. Fall in love all over again.

In development, that means finding out different things about programming that you didn’t know before. For instance, if you’ve only ever done middle tier work, learn the UI. If you’ve only programmed application code, learn the database. If you’ve only ever worked the Microsoft stack, give Open Source technologies a try. Make the field new, exciting, and alive again.

Even if you are someone for whom life or finances has guided toward technology, you also have hope. Much like individuals in arranged marriages can “learn to love” or “grow to love” their spouses, you can learn to love your profession. Like the last group, branch out and find a niche you are passionate about. Computer science is a very broad profession. You may find you love writing compilers, embedded systems, device drivers, mobile applications, web, rich media, etc. However, if you only ever log your hours and go home, you’ll never know what is beyond your 9 to 5.

I don’t want to sound preachy, but I truly felt compelled to write when I read that quote. Remember the old adage that when you point one finger, you have the rest of them pointing back at you. I write as much for my current and future self as I do for my readership. While I am “on fire” and “in love” with programming now, the natural ebb and flow of life may take that away from me. When it does, my natural desire to compete and be great are going to remind me of this post and I will have to heed my own advice and find something new that excites me.

I hope you have something that excites you, too.