Sunday, April 27, 2014

Dealing with ASP.NET MVC Device Output Caching Issues

ASP.NET MVC output caching supports variability by device. This is a useful feature to have when building a mobile version of the desktop site, for example. However; there has been a persistent bug in the output cache support. It was fixed for a short time, but it has mostly remained broken and still is even today (MVC 5.1). Instead of waiting for a fix, and having it break again like before, you can go around this issue.


Here is a relatively easy and transparent way to get around this bug:
  • Use VaryByCustom output cache parameter for the actions.
  • Use the cache profile support to implicitly inject your VaryByCustom parameter to your output cache.
  • Implement the custom parameter handling in your Global.asax.cs
Use VaryByCustom output cache parameter for the actions.

This is repetitive, so we want to avoid sprinkling this custom attribute everywhere. We can use the cache profile support in your Web.config to add this attribute implicitly. (Just set the timeouts in your config).

So, now your OutputCache annotation becomes:

Finally, we implement the custom cache handling in the Global.asax.cs:

Tuesday, April 8, 2014

Should Everyone Learn to Program?

In the last couple of years, there have been calls to "learn how to program", and that "everyone should". Here's my take on that topic.


I was thinking what the root motivation for this call-to-action is. 
  1. Technology is suddenly cool.
  2. Geeks are suddenly cool.
  3. Some tech companies are becoming as big as big oil.
  4. Apparent lack of talent.
  5. The jobs pay rather well.
  6. Many other high paying low skilled jobs are vanishing.
  7. Erosion of middle class, eliminated by globalization and automation.
There is a definite smell of a bubble with the tech fervor. Investors and companies are paying huge sums for token enterprises that seem promising. I really wonder how much of that is viable in reality. This whole image is kept alive by the huge cash reserves that bigger tech companies now sit on, and you'll notice how Google, Facebook, Apple etc. are gobbling smaller start ups and paying big sums for them - because they can.

Just recently the big tech companies were embroiled in a wage fixing ring limiting engineer pay. The pay is reasonable, but the lack of talent is quite palpable so the employee poaching is a fear that these companies have. So, what to they do instead? They pay huge sums for companies with promising tech, but all the same, they are equally interested in the software developers and their talent that they are acquiring. Poaching by acquisitions. It is just as important to vacuum the talent away from your competition before they get to it. The price goes up, up, up. Hence the bubble.

The other end of the equation is the quick erosion of well paying low skilled jobs, and even medium skilled jobs. What is left is creative high skilled jobs. What still pays well? Being a doctor, lawyer, and some other limited occupations... and then there is energy, technology, engineering and programming. Here in Canada, 75% of people make well less than $40K per year, but programming jobs get you to top 10% rather easily and even much higher.

Dreams and Realities

Politicians and policy makers have caught on this. This is the new opportunity to create a high amount of well paying jobs and revive the ailing job market, and then collect tax revenues. Anyone can build an App and make millions! Only if we got every school kid to program!

The well meaning thought process is idealistic. I give them that. I even favor basic level programming becoming part of school curriculum, as part of general technology education. It's basic knowledge that people should know when they enter this new world.

But, that does not guarantee that now people will flock to programming as the new promised land. Even if we had an avalanche of new IT graduates, the problem is that programming is really not the skill that is the key. 

Programming is just a means to an end. Programming solves problems, so your key skill is problem solving, not programming. Creativity, critical thinking, organization, concentration, relentless learning about various things. This is all the stuff that comes from "book-worming" all your life. Natural ability is required, so is relentless practice.

If you have high tolerance for solving problems that are so removed from most real life activities, so infuriatingly mundane that defeats even a patient person, and you are OK with the fact, and even enjoy it, then you might have a mind for programming. Stubbornness is a requirement.

There is also a point about the whole "App" thing. You can spend several life times writing Apps without making a buck in the process. You will get far more success with stable jobs in established companies.

Teaching and Schools

The whole problem of teaching programming is quite well explained here: Separating Programming Sheep from Non-programming Goats. The research paper that it is based on crudely concludes that very large portion of Computer Science students are beyond hope to be taught to program. Mind you, this is CS students, and not general population! Also, consider that out of those people who could become programmers, many do not ever enter the field in the first place, but they may go to other engineering disciplines and so on. We are really looking at a paper thin portion of the population here.

The fact that most people are never fit to be programmers is not a big surprise and why should it be? You can teach me singing all you want, but I never ever will be a singer no matter how hard I try, and same is true for most people.

If you want to teach anything to kids, it is creativity, free thinking, problem solving. Those are fluffy esoteric things that are hard to squeeze to school programs, so it means you need creative top notch teachers and mentors. The fact is that most good programmers are still self taught, motivated by their own curiosity and drive. And that is fine, as long as they have creativity, problem solving and free thinking skills.

Career Issues

There are also many problems that plague this field. Age racism being one of the major problems. It is hip to be young and cool, but the problem is that there are not enough programmers around if all you want is the young and hip. But, I think this is changing, and has changed already. Try hiring, and you'll find out. And, what you will often (not always) find out with the young and hip is the Dunning-Kruger effect. You still need experience, you need mentors, you need leaders.

The second problem is the fast pace. Your skills are always at the brink of being obsolete. You need to be a life long learner, and it needs to be second nature to you. You may be forced to switch jobs to find the things that keep you in business. Any environment that does not allow you to keep up, is poison to you. I have seen a number of examples with 'experienced' people who have done nothing relevant in years because they sat in some big corporation doing routine maintenance on some obscure system that nobody cares about. Any smart developer will leave a company that is not investing into their skills.

Third, long hours in the office. I don't know what made developers free game for ridiculous demands and silly time lines that have nothing to do with reality. Gladly, even this is changing, but there are still bottom of the pit jobs in this industry that expects the moon and the stars. It is often the expectation of 'non-techies' that you can throw developers on the problem like monkeys, and multiply by 10. Unfortunately, programming is a creative high skill empirical activity, not a production line in a factory.

And what happened to women? There are hardly any women in the field. That's a failure in its own right that makes everything more difficult. The field needs women.

The whole pay thing is a powerful driver, but ultimately the pay is more of a consequence of the points I mentioned. It will always be a job for the few and not a solution to the structural changes that societies will face. Programming is not an easy job that people might expect it to be. You need to be a business expert, subject matter expert, project coordinator, communicator, team player, and then - for heavens sake - you also need to write code. That is asking a lot and the pay starts to look reasonable if not quite modest.