Welcome to AspAdvice Sign in | Join | Help

Book: Freakonomics

I've been a bit behind on blogging but I'm trying to catch up this week.  I wrote earlier that I've just finished an excellent software development book (with a very unfortunate title), Working Effectively With Legacy Code.  Freakonomics is an entirely different kind of book, and one I actually finished reading last year but just haven't gotten around to writing about.

Freakonomics is a New York Times bestseller, so I'm hardly the first person to read and discuss it.  If you're one of the three people who haven't read it yet, let me explain the concept.  Steven Levitt is an economist and Stephen Dubner is a journalist.  Together, they tackle some interesting (at least to them) questions by applying statistical methods typically used by economists on somewhat more mundane scenarios.  From the book's jacket:

Which is more dangerous, a gun or a swimming pool?  What do schoolteachers and sumo wrestlers have in common?  Why do drug dealers still live with their moms?  How much do parents really matter?  How did legalization of abortion affect the rate of violent crime?

The book is broken down into a chapters that each cover a particular question.  It's very easy reading, and most of the topics are quite interesting as well.  It's interesting to look at these questions and how the authors have found data to support their conclusions.  If nothing else, this is an excellent "cocktail party" book, in that it will give you some interesting things to say at the next party you attend.

The authors found some interesting patterns among children's names over time and across racial and economic boundaries.  They also looked at a variety of different contributing factors to children's test scores, and noted which did or did not have a strong correlation (note: not necessarily a causal relationship).  For example, four(of 8 described in the book) factors that are strongly correlated with test scores are:

  • The child has highly educated parents.
  • The child's parents have high socioeconomic status.
  • The child is adopted.
  • The child's mother was thirty or older at the time of her first child's birth.

Four (of 8) factors that are not correlated with test scores:

  • The child's family is intact.
  • The child frequently watches television.
  • The child's mother didn't work between birth and kindergarten.
  • The child's parents read to him nearly every day.

It's interesting as a parent of two children (one adopted) which pieces of the puzzle, statistically speaking across a large sample size, tend to matter and which do not.  Obviously at the individual level, every family and every child is different, but having some kind of data to go on can provide some insight into priorities one should assign to things.

The current edition of the book also has about 100 pages of bonus material from the Freakonomics blog and some of their newspaper publications, which include coverage of things like Wikipedia and a diet that looks at appetite from an economist's perspective, and introduces a very simple way to suppress appetite (and in turn, lose weight).  The diet article is interesting in its simplicity, and one that led me to pick up a book on the subject (which I'll blog about when I have some time).

I enjoyed the book; it's great discussion fodder.  Some of the information might actually be useful (for instance, the parenting chapters and perhaps the diet one), but for the most part it provides some entertainment value and a new perspective on a wide variety of subjects usually untouched by anything resembling scientific research (at least not in an approachable format - scientific journals are not fun reads).

Posted by ssmith | 1 Comments
Filed under:

Visual Studio Team System 2008 White Papers

Microsoft has published a set of white papers which provide a good technical overview of the features available in Visual Studio Team System 2008.  They're available individually for download: Visual Studio Team System 2008 Capabilities White Papers.

The papers cover the following subjects, corresponding to features sets and design goals of VSTS 2008:

  • Communicate and Collaborate
  • Drive Predictability
  • Ensure Quality Early and Often
  • Integrate Work Frequently
  • Making Real-Time Decisions
  • Managing Team Workflow
  • Using Familiar Tools

I wrote the Integrate Work Frequently paper, which describes some of the new build system features, including the capability to implement Continuous Integration easily.  We've been using Team System since its 2005 introduction at Lake Quincy Media, and I've been a longtime fan of continuous integration, as well.  I was very glad to see its inclusion in VSTS 2008, and I'm sure it will be a big help to a lot of software shops.

Posted by ssmith | 2 Comments
Filed under: ,

Black Belt ASP.NET Performance Techniques

Last night I presented at the Cleveland .NET SIG on Black Belt ASP.NET Performance Techniques, which is a talk I'll be giving in a few weeks at Tech:Ed Developers in Orlando.  I was asked a couple of weeks ago if I could give a talk in May and I decided to do it so I could practice for TechEd.  Since this is a new talk for me (though its material is familiar), I had to put together a new set of demos, and having this user group meeting was a good way to keep me from procrastinating until June to get my demos working.  The talk covers performance metrics, load testing, and some performance tips (and shows their relative impact on a realistic application using load testing).  It also covers some advanced topics like asynchronous programming techniques, both on the server and via the client.

I think there were about 70 people at the meeting.  I flipped through the evaluations afterward and for the most part folks seemed to enjoy the presentation.  I had one person note that I spoke too fast, which is fair since I was trying to get through the material quickly since the room was quite hot.  Apparently, the building the Microsoft office is housed in (which hosts the meetings) automatically shuts off its A/C at 6pm each evening.  So, by 7pm the room full of 70+ heat generating mammals had gotten rather uncomfortably warm.  I was able to wrap up my talk by about 7:15 or so, and I was as happy as everyone else to get out of the sauna at that point.  I'm not sure if anything can be done about this issue, but it will only be worse in the hotter summer months, I'm sure.

As promised, slides and demos have been posted.  Again, both have some rough edges still as this was a practice for TechEd.  Look for updated slides and demos after my talk June 5th.

Slides and Demos

Posted by ssmith | 2 Comments

Book: Working Effectively With Legacy Code

I've just finished the above book, which was recommended to me by Jeffrey Palermo a few months ago.  It is one of the most useful software development books I've read since Code Complete.  I wish I'd read it years ago, and I'm finding myself refactoring and rethinking my approach to current systems I've been working on for some time to make them more testable and easier to work with -- and I'm already seeing improvements.  Seriously, if you're writing software, you should buy this book and move it to the top of your professional reading list.  It's the book that Refactoring should have been, in that it is a very easy read with great examples that also serves as an excellent reference.  I just bought copies for all my full time developers.

Why are you still reading this?  Go!  Read the book!

Posted by ssmith | 1 Comments

Speaking in Cleveland May 13th

I'll be speaking at the Cleveland .NET SIG tomorrow night.  The topic is Black Belt Performance Tips for ASP.NET, which will be a dry run for a session by that same name I'll be giving next month at Tech:Ed Developers in Orlando.  Some of the primary areas covered will be advanced caching techniques and asynchronous programming techniques (for ASP.NET).  The user group meets at the Microsoft office in Independence, Ohio from 5:45pm to 7:30pm and usually is pretty crowded.

Posted by ssmith | (Comments Off)

Comments in Code Indicate Functions Trying To Escape

I interviewed a couple of college students earlier this week for internship positions with Lake Quincy Media, and one of them reminded me of my own college days when we were graded in part based on how well commented our code was.  In school, comments are typically there as a "check the block" measure to ensure that the professor doesn't take off points for not having them, but in the real world comments can actually serve a good purpose.  One of the things you learn with experience is the difference between comments as a waste of space that clutters up your code files and comments that are actually meaningful.  However, for the purpose of this post, I'm going to look at a specific case, which is comments that indicate an Extract Method refactoring is needed.

Consider the following code fragment:

// format the label based on balance
if(Customer.Balance >= 0)
{
    CustomerBalanceLabel.ForeColor = "Blue";
}
else
{
    CustomerBalanceLabel.ForeColor = "Red";
}


This is somewhat contrived but it's an example of the kind of minimal commenting one often sees as a sort of "I'm supposed to add comments so here's one to meet that obligation" style.  Really anyone reading this code should be able to figure out what the if block is doing in short order, but the comment is useful at least inasmuch as it lets you know this is all about formatting.  One disadvantage of this style of comment is that it doesn't indicate where the formatting code ends.  Presumably there will be another comment later on, beginning a new set of logic, but often that's not the case and it's up to whomever is reading the code to figure out the scope of the comment.

In this case, the comment provides a big clue as to the method name of the method we'll extract.  We might choose to call it FormatCustomerBalanceLabel() and pass it in an instance of Customer if required (if it's not already scoped to the whole class).  After refactoring, the code might look like this:

FormatCustomerBalanceLabel();
...
 
private void FormatCustomerBalanceLabel()
{
    if(Customer.Balance >= 0)
    {
        CustomerBalanceLabel.ForeColor = "Blue";
    }
    else
    {
        CustomerBalanceLabel.ForeColor = "Red";
    }
}

 

The original version required 9 lines of code in the original method and a comment to explain what was happening.  The refactored version requires only one line of code and no comment is necessary since the name of the function makes it obvious what the code is doing.  Something I notice most new graduates (and students) tend to do is create very large functions, and this refactoring is one way to get away from that.  Ideally, you should be able to view any function in your application on your screen in its entirety without scrolling.  If you have to scroll (or, God forbid, print it out on several pages) to read the entire thing, odds are good that it's difficult of understand and you're going to spend more time than necessary trying to comprehend it (and you'll be more likely to introduce bugs).  And don't even get me started on the testability of small, discrete functions versus huge monolithic functions.

Posted by ssmith | 6 Comments

TECHbash is Coming to PA

In just 10 days (May 10th, 2008), TECHbash 2008 will kick off in northeastern Pennsylvania.  The show has been around since 2005 and will include several hundred developers, IT professionals, and industry experts from PA and surrounding states.  Joe Stagner from Microsoft will be giving the keynote and my company, Lake Quincy Media, is one of the sponsors of the show.

Speakers will include MVPs Miguel Castro, Sam Gentile, and many more.  Jason Gaylord (who runs the .NET Valley User Group) is one of the primary organizers of the event and has done a very good job.

Posted by ssmith | 1 Comments

DevConnections Spring Slides and Demos

Last week I gave three presentations at the DevConnections spring show in Orlando.  I received a lot of great feedback from attendees which I definitely appreciate, especially since I was feeling a little bit bad about having run out of time in my first two talks (and overcompensating a bit on my last one, which ended a few minutes early).  I definitely try to err on the side of too much content, with the idea being that if I can't fit it all in, at least the slides and demos are there for attendees to reference, and I'm happy to answer emails with questions about any of the material.

What's New in ASP.NET 3.5

Slides and Demos

My first talk was on What's New in ASP.NET 3.5, and it was well-attended for a Tuesday 8am talk.  I did make it through everything that's actually new in ASP.NET 3.5 and VS 2008 that I had prepared - the only things I had left that I couldn't get to were actually things that are still pre-release, like Silverlight 2 and ASP.NET MVC which I very briefly showed.  There was a lot of interest in LINQ as well, and there were some good questions about LINQ-to-SQL and how to fit LINQ into existing N-Tier architectures.  The recurring theme of "Are DataSets dead?" was interesting as well, and I'm sure some of the other speakers had similar discussions (I hope some of the attendees interested in the topic went to some of the LINQ-specific talks).  The main content for this talk was the ListView and DataPager, along with some simple LINQDataSource stuff and LINQ demos using LINQPad.  I also showed off some VS2008 new features like nested master pages and JavaScript debugging and Intellisense.

 

Pragmatic ASP.NET Tips, Tricks, and Tools

Slides and Demos

The second talk was a tips and tricks talk, which drew from my own experience as well as a variety of blog posts and other similar talks which I tried to credit in the slide deck.  One attendee came up to me at the attendee party Tuesday night, while I was standing with three other speakers, and gave me a nice ego boost (while simultaneously embarrassing me).  He exclaimed that he was extremely grateful for my tips and tricks talk because it had made the conference worthwhile for him, and that "it was good to see a speaker who brought some real technical content to their presentation" or something close to that.  This, with three other very good speakers standing there...  I thanked him and introduced him to the other speakers and suggested he check out their excellent talks on Wednesday.

At any rate, I apologize again for running out of time with this one.  I know I crammed way too much material in for a 75 minute talk, and next time perhaps I'll consider giving a 2-part talk.  Many attendees came to this one and then also went to my third talk, and since I had a few minutes left after finishing that one I actually completed the tips and tricks presentation then, for about 20-30 people who had asked for it.

 

Improve User Experience with Asynchronous Processing

Slides and Demos

My third and final talk for Tuesday was on asynchronous processing in ASP.NET.  I basically covered three scenarios and did so with a minimum of tangents and user discussion, allowing me to get through the material a bit quicker than expected (plus I really didn't want to go over 3 times in one day).  The first scenario was async fetching of files by the browser (increasing the number of files the browser can fetch simultaneously).  The second one discussed async on the server, within ASP.NET requests, and showed a couple of different techniques for achieving this with web services and web requests.  This is an important technique for both scalability and performance.  The third scenario demonstrated how to defer loading of long-running user controls to the client by rendering the page quickly with empty DIVs which populate themselves using AJAX callbacks.  This was the meant to be the high point of the presentation and shows an extremely cool way to achieve great usability.  I didn't get a standing ovation or anything, so I'm not sure that I effectively demonstrated how cool it is (I've shown it at user groups with much greater response).  Perhaps by 5pm on the 2nd day of the conference everyone was worn out.  I still need to write up these techniques for ASPAlliance.com but I still haven't had a chance.  For now, download the slides and demos and check it out.

Twitter as Smoking Cessation Aid

I was talking to a couple of friends and occasional smokers today, and both were commenting about how nice it is that Seattle is almost entirely non-smoking now, so they didn't light up while in town for the MVP Summit.  I've never smoked, but listening to them, clearly they were not addicts in the hard-core packs-a-day kind, but they would smoke socially or just to be doing something.  So it occurred to me, especially given that the three of us had just spent half of lunch each individually checking various Twitter feeds (and email) on our phones, that perhaps Twitter and similar apps on mobile devices are having a positive health impact.  Why light up a cigarrette when you can keep your hands busy with your phone checking Twitter, texting friends, or scrolling through emails on your Blackberry Windows Mobile Device?

Any smokers care to affirm or deny that this effect exists?  Now if only the constant use of mobile phones didn't come with its own social costs, especially with significant others...

Posted by ssmith | 6 Comments
Filed under:

Triskaidecaphobia

Office 13 is going to actually be called Office 14, since there are some people who assign some negative significance to the number 13 (see Triskaidekaphobia).  Since this is clearly a significant concern in the world of computing, it seems natural to me that other areas of Microsoft's platform should work harder to avoid this unlucky number.

On a slightly related note, I was glad to see that the Westin Seattle actually is honest about the numbering of its floors, and does *not* label the 13th floor 14 in an effort to appease people's superstitions.  Scott Cate and I stayed on the 13th floor this week, and even had the super-duper unluck of having 13 on our door twice (in a palindrome!) in room 1331.  However, we were somehow able to escape the imminent doom this would normally portend.

Back to the subject at hand, though, let's find some other areas in which we can eliminate fear of the .NET framework.  To start with, arrays and enumerable collections should automatically skip the 13th index and label it 14 instead.  Thus something like this:

string[] myStrings = new string[20];

foreach(int i=0;i<myStrings.Length;i++)
{
   Console.Write(i + " ");
}

would output

0 1 2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19

To get this to work, you would need to update the CLR or the IEnumerable functions in the base collection classes, but it would be worth it to avoid the evil 13.  To implement this yourself, you would need to add in special logic:

if(i<=12||i>=14)
Console.Write(i + " ");

This would still pass the FxCop rule "thou shalt not have the number 13 anywhere in your code" that will need to be added, but really users shouldn't need to write this themselves.  However, static analysis and style warnings really aren't sufficient to address the importance of something like this.  We really need to entire system to grind to a halt at the very mention of the unmentionable 0xD.  Thus, we'll need a new exception, the Triskaidexception.  Its use might look like this:

if(value > 12 && value < 14)
{
  throw new Triskaidexception("Evil number detected!);
}

 

But seriously, since the actual product isn't going to carry the lucky number 13, I think it's pretty silly to eschew this incremental number in order to avoid superstition.  All that does is breed ignorance and superstition further, and in the 21st century, from a company full of a lot of very well-educated and intelligent people, I would hope to see less fear of the potential marketing detriment of others' superstitions.

Microsoft Cloud Services

One of the quietly announced (at MIX - WMV here) new things coming from Microsoft "soon" is SQL Server Data Services (SSDS).  The SSDS team has a blog on MSDN.  Ryan Dunn discussed it with me recently and also has been blogging about it.  Last week he announced the release of PhluffyFotos, a sample site built on top of SSDS.  You can sign up for the beta of SSDS here.  Roger Jennings has some comments here.

So, what is SSDS (read the FAQ)?  Essentially, it's a way for you to access data from "the cloud" providing a highly scalable and globally available data access story.  One scenario that benefits greatly from this approach is the application that suffers from extreme spikes in activity punctuated by lengthy lulls.  For instance, a ticket sales company that has millions of requests within the hour that some tickets go on sale, and then just thousands of requests the rest of the month.

Amazon and Google are both pushing cloud services and clearly this is an area that Microsoft is moving into as well.  SSDS is the first of what I expect will be other such services, and it will be interesting to see how the various offerings compare.  If nothing else, the competition between the various companies should drive pricing down, both for these services directly as well as for traditional application hosting solutions.  Eventually, I expect a developer could upload an application and configure its data source requirements and host the entire thing "in the cloud" paying some metered rate for the various resources (disk, cpu, bandwidth, and extra services) consumed by the application.

Posted by ssmith | 1 Comments
Filed under:

ASP.NET AJAX Download Performance Improvement Request

I'm a big fan of ASP.NET AJAX in general, but one concern I have and something that has forced me to use other technologies is the size of the library.  It's about 85kb when compressed and unfortunately that is quite large if you're trying to include it on most every page on a site (or, much much worse, every advertisement in a large Microsoft developer advertising network).  One can certainly argue that this will be cached, and that is true, but for many sites that get most of their traffic from search engines (ASPAlliance gets over 70% of its traffic from this), you have to assume that many users will not have the .js file cached, and that is a significant increase in the total page size.

I would like to suggest (and have done so previously, but less publicly) that it would be a good thing if the ASP.NET AJAX javascript library were hosted by Microsoft as an option.  This would involve some slight changes to the coding (specifically I would add a property to the <ScriptManager> control to enable using the Microsoft provided library), and would require that Microsoft make a commitment to having the .js file available via their infrastructure.  In practice this would not be very different from the distribution model that they are currently using for Silverlight deployment, but would be much smaller (per file - 85kb vs 4mb).

The chief advantage of this approach would be a huge reduction in the number of downloads of the AJAX javascript file required for clients, and an increase in performance across the board as a consequence.  The likelihood that any given browser would have a cached version of the AJAX javascript would be much higher if a large number of AJAX-enabled sites referenced the Microsoft hosted AJAX library.  The cost (in bandwidth) to use AJAX would go down.  The performance for all AJAX-enabled web applications would go up.  Clients that do not wish to cede control of the distribution of the download could continue hosting the files themselves without any change.  The change in behavior of ScriptManager could easily be rolled out in an SP or as part of vNext, and would make AJAX more attractive when compared to alternate (lighter weight) JavaScript frameworks such as jQuery.

Posted by ssmith | 13 Comments
Filed under: ,

Extract Control for ASP.NET in Visual Studio

I've been posting about some feature requests for ASP.NET/Visual Studio, so here's one more in that thread.

One nice feature of Blend is the ability to select a chunk of XAML and choose to "Extract User Control".  The result works very nicely, creating the separate control and inserting the reference to that control into the original XAML document.  It would be very cool if ASP.NET had this same notion, wherein one could select a chunk of ASPX markup and choose "Extract User Control" and have it create the .ascx file for you and insert the reference to that control into the original page.

Another nice addition to take this another step further would be the ability to convert an ASCX file into a compiled control.  I wrote an article and did some talks a few years ago about the evolution of controls from ASPX to ASCX to .CS (.VB).  This is pretty much all a manual process and progression (it was then, and it is still today), but it would be nice if this were a bit easier via a VS tool or even a third party refactoring tool.  Perhaps this already exists, in which case I'll look for comments from the Resharper/RefactorPro guys shortly... (like last time) :)

Posted by ssmith | 3 Comments

2008 Goal Progress Update

If you just read my blog for technical stuff, you can skip this one.

So at the start of the year I set a few personal goals.  Since the best way to achieve goals, I've found, is to break them down into smaller and smaller pieces (as in "The journey of a thousand miles begins with the first step"), I thought I would assess my progress on the five goals I set for myself.

Goal 1 - 200 Blog Posts in 2008.  That breaks down nicely into 50 per quarter, and in the first quarter I published 52 posts, just barely on track.  February was pretty light with only 9.  I'm sure if it had had 30 days in it I could have written a lot more posts.  Of course, if it had had only 28 days, I might not have had nearly as many...  We'll call this one 25% complete.

Goal 2 - Lose 17 pounds.  So far I've lost 10 pounds.  That's pretty good, and definitely on track, although I'm still hovering around where I was for most of 2007 (I basically lost what I gained over the holidays and maybe a tiny bit more).  So, it's definitely good but I know the next jump will be harder.  And then keeping that all off as of 1 January 2009 will be hard.  But I'm on track.  This goal is about 58% complete.

Goal 3 - Write a Silverlight book.  Progress has been slow.  I have two chapters due this month and the whole thing should be turned in for the first draft by mid-June.  So I need to make a lot of progress this quarter.  If I do another update around the start of July, this goal should (had better be) close to complete.  Right now it's probably only around 5%.

OdinGoal 4 - Get a puppy.  Done!  We got an English Mastiff puppy named Odin in January.  He was about 8 weeks old when he came home and around 20-25 pounds.  Now he's about 4 months old and 60 pounds.  It's amazing how fast these guys grow.  This was the easiest of my goals to achieve, and is now 100% done.

Goal 5 - Achieve next belt in karate.  I've been practicing regularly, which probably has helped with Goal #2.  I don't expect to test for my next belt until Fall, but I think I'm on track, so we'll say this one is 25% done at this point.

If nothing else, putting these out for public consumption helps motivate me to work toward them, since now if I don't achieve them, the whole world knows about it.  My apologies to those of you who simply don't care.  Why did you keep reading this far?

Posted by ssmith | 2 Comments
Filed under: