Book Reviews

Pro CSS Techniques

Pro CSS TechniquesAPress is far and away my favorite tech book publisher. You’ll probably hear (read) my say that over and over again. When I need to learn a new technology or just get better at an old one, I always look to see what APress has in their stable before venturing out anywhere else.

I’ve used CSS like the next guy. I started off just adding an in-line style or two. Then, I learned about external .css files. Then, I discovered the CSS Zen Garden and realized that I didn’t know anything. However, I still just muddled along, piecing together what I could, trying my best to separate structure from layout.

There are several good resources online to learn about CSS syntax and a few “best practices”, but nothing as comprehensive as this book. Pro CSS Techniques takes you from the base syntax of CSS to tons of nuances included in the latest version (CSS 3 as of the writing of the book, I believe). Also included are tons of “gotchas” for dealing with browser compatibility in a very pragmatic way. I would venture to say that many developers do not inherently follow the advice in this book and struggle mightily for it.

Pro CSS Techniques also includes tons of “real world”-type examples so that you can see how to put this in action. The code examples are also built in such a way so that you do work one way, find out why that doesn’t work, then correct it. I find that more helpful than just showing only 100% correct code and giving a passing explanation as to why other ways aren’t correct.

If you want to become a better web developer, want to learn more about CSS, and you aren’t Eric Meyer or one of the authors of this book, I recommend you pick it up.

Code Tips

Code Tip: C# Coalesce

I have to admit something. I’m something of a Sql Coalesce() fan. I know that Sql Server has an IsNull() function, but there are two bad things about it. First, it is proprietary to Sql Server and I like to try to write my Sql as close to ANSI as I can so that I don’t build up too many bad habits that cause me to have problems when I have to work in other DB platforms. Secondly, IsNull() only takes one option (well, you could nest your IsNull() statements, but that is unwieldy). Coalesce() lets you give a list of items and just takes the first one of them to not be null. Apparently, IsNull() is also slower. All hail, Coalesce()!!!

Several months ago, I was doing some coding in C# and I was actually wishing that C# had a Coalesce function so that I could not have to do a bunch of manual null checking in my code. On a whim, I decided to Google C# Coalesce and see if someone had written one or if there was one hidden in the framework somewhere. To my surprise, I found that C# did have such an animal. Here is an example of its use.

// Checks the HTML Form for a value,
// if that wasn't submitted, use the value
// potentially set elsewhere in the code,
// if that is null, set the variable to
// a blank string.
string value = Request.Form["someField"] as string ?? someVariable ?? string.Empty;

I can’t tell you how much I love having this.

Code Optimization

A Speed Problem

SpeedFirst let me give you a little of the background. At work, we are building a web application. Among other things, we’d like it to be fast. We made many painstaking decisions to build it to be fast. My last post talked about some of the things that we were going to undertake to make sure that it was fast through the pipe.

However, we were having a problem. Page loads were taking over 5 seconds and that was after the initial hit penalty that ASP.Net gives you. I put tracing information in our handler and it turns out that all of our framework code was executing in .05 seconds. That wasn’t the problem. The step of getting the base handler (for the hand off to ASP.Net) however, was taking over 5 seconds.

We had another interesting problem. The ASP.Net Cache object didn’t work. It would be alive for the duration of a page hit, but on the next hit it was gone. My boss suggested that the pages were compiling every time, and we ultimately did see that in the %windir%\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files directory. The question was, “Why?”.

We had wanted the site files to be dynamically compiled for ease of updating, while our framework code remained in pre-compiled .dlls. To troubleshoot, I recommended that we pre-compile the website as well and see what happened. Page hits got down to half a second a piece. Interesting.

Shortly after, though, I got a brainstorm. We were writing log files into a folder in the bin directory (a holdover convention from a previous application) and every time that directory changed (on every page hit), ASP.Net would sense that the bin directory changed (since the log folder was in it and a part of it) and think that the site had changed and now needed a recompile. It makes perfect sense in retrospect!

We moved the log directory outside of the bin, went back to dynamic compilation, and got the same performance improvement that we got with the pre-compiled version – much to my relief.

Book Reviews

High Performance Web Sites

High Performance Web SitesI’m starting to get involved in this book, High Performance Web Sites by Steve Souders. My boss picked it up and read it and had really good things to say. Then the CEO read it and was really geeked about it. So, I decided that I’d better give it more than the cursory glance that I’d previously allotted it. I know that there is a lot of push to write one’s server code to run as quickly as possible, but I feel that the subjects that this book is covering are being largely overlooked.

Mr. Souders wrote the book while he was a Yahoo employee (he works at Google as of January 7th). He is also the creator of YSlow and an expert in web performance. However, you can actually get a lot of the tips if you check out this page and install YSlow onto your machine. YSlow is an addon for Firebug, itself a plugin for Firefox. If you are doing web development, you should already know about Firebug. If you don’t, run – don’t walk – to download it and you can thank me later.

When you run YSlow, it analyzes the current page for each of the 13 points that the Yahoo Developer Network has identified as major causes of web site slowness. It assigns you a grade to each item and gives the site an overall score. For instance, this blog scores a D (65). According to YSlow, I need to add an expires header, use GZip compression, and configure ETags in order to get this site up to par. As an experiment, I may very well dig into trying to get my score up to at *least* a B! If you aren’t sure what these points mean or what I’m talking about, you should check out the links above or get the book.

The book is very well written and is grouped in such a way so that it can be digested separately by different members of a team or by one person. The appendices of the book contain case studies of several major sites using the tools I discussed above and explains what each could do to improve user experience. At $20.00 on Amazon (and used from $11 and change), every web developer really should read this book, implement it, and keep it as a reference for future development.

Code Mash

Code Mash

Sorry this is a little late, but the last week was pretty hectic coming back off of my few days off for CodeMash.  It was worth it, though, if for no other reason than the goodies! I love free stuff!
CodeMash SWAG

I actually forgot to include my APRESS notebook, CodeGear pen, and a few other goodies that were in my laptop bag. However, what I did photograph there included a CodeMash t-shirt, a Visual Studio 2008 t-shirt, a Microsoft stress relieving ball, an Amazon stress relieving heart, a water bottle from TechSmith, a Sun Microsystems notebook, two can coozies, two footballs, a velcro wire tie, several pens, a magazine, a keychain pulley, an APRESS button, a bunch of CodeMash tattoos, and a plastic cup. I’m silly, but I’ll be a walking advertisement for just about anyone if they give me free goodies.

Now about the conference. I had heard that this conference was a bargain, and it really was. All around, from the room fee to the actual conference cost, my benefit FAR exceeded my company’s financial output. Breakfast and Dinner were catered by the hotel and lunch was a very fulfilling box lunch. There was also all the pop you could drink on hand throughout both days. In addition, there was a social event on Thursday evening with everyone’s first two drinks provided by Quick Solutions.

It wasn’t all about the free stuff, though. There was some tremendous content to be had, as well. On Thursday, I attended Ruby: Testing Mandatory, Crash, Smash, Kaboom Course in Python, LinqTo: Implementing IQuery Provider, and Refactoring for Testing. On Friday, we hit Real World C# 3.0, RESTful Web Services, a few Experts Zone sessions, and socialized. We also enjoyed the keynotes. My absolute favorite talk was Scott Hanselman’s Thursday midday keynote on IIS 7.0. I’ve been a reader of his blog for over a year, but had never heard him speak in person. He was very funny and made excellent points. I might just be developing a man-crush!

I am going to do everything in my power to go to CodeMash in 2009. I would recommend this conference to any developer in about a 5 hour driving radius. I’ve never been to any event like this and I think it is definitely in a league of its own in the Midwest.