Scott Hanselman

ASP.NET MVC - WebForms Unplugged

January 24, 2008 Comment on this post [38] Posted in ASP.NET | Microsoft | Musings
Sponsored By

Acoustic Guitar As a new Microsoft employee, I like the new-found pragmatism at the Microsoft Developer Devision, typified by projects like the ASP.NET 3.5 Extensions and MVC. Certainly we all know MVC as a concept is nothing new, but it is new as a philosophy for the ASP.NET team (IMHO).

Remember that ASP.NET WebForms render using a Control Hierarchy which is fundamental to the whole gestalt of what we think of as ASP.NET. You put an <asp:label> inside an ASPX page and as soon as you mark it 'runat="server"' you've added it to the Control Hierarchy. Any string literals around your control also become part of that hierarchy of objects. The PreRender event is an opportunity for you to affect that tree of controls before the Render event fires and they turn into Angle Brackets (usually HTML). ASP.NET represented a swinging of the needle, as it were, from the Classic ASP way of doing things to an artificial event model that gave us state where there was no state. It added layers and production value and it sounded good, and still sounds good to lots of people.

However, this leaves a gap in the music. Sometimes I just want to control the stream myself. I want the system to step aside and let me get down to it. Not all the way aside, but certainly out of my general field of view. MVC Frameworks with View engines like ASP.NET MVC and Monorail's many template options and the Django template language and HAML...

(Note to self, write HAML view factory for ASP.NET MVC. UPDATE: Crap! The brilliant Andrew Peters made NHAML this last month and added it to MVC Contrib. New Note to self, crush Andrew Peters for being too awesome.)

…provide a fresh clean new sound to the same old angle-bracket-based music of the past. Clean, simple, lightweight.

Is it MVC that makes this possible? Partially, but we mustn't forget the huge influence of sites like http://www.csszengarden.com and the minimalist markup aesthetic promoted by CSS folks and standards wonks changed the way we think about markup and what can be accomplished with a few H1s and a UL/LI or three.

In a recent MVC design meeting someone said something like "we'll need a Repeater control" and a powerful and very technical boss-type said:

"We've got a repeater control, it's called a foreach loop."

Zing! That's so cool. Get out of my way and let me make some angle-brackets. Again, not for everyone, but for enough people that matters. Open Source projects like MVCContrib and hopefully a bunch of 3rd party component vendor types will drink in that simplicity and the power of statements like that and create helper methods and controls that we want, need and can use, and not just <mvc:TooBigDataGrid/>.

This is a not just a different tune, but a whole different band playing all new music. Not everyone will like the music, and that's why the world has more than one band. This is a Good Thing.

I like to think of ASP.NET MVC as the raw, acoustic version of the more heavily produced and multi-layered ASP.NET WebForms we use today.

I hope the pure intent and zen-like simplicity of a nice clean MVC design stays that way. Sometimes I want to listen to Kanye West, but sometimes I want to listen to John Legend. Or, insert your own musical analogy here. Either way, it's ASP.NET Unplugged as far as I'm concerned.

Related Posts

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Best Mobile Websites for Tiny Browsers

January 24, 2008 Comment on this post [25] Posted in Microsoft | Musings | Tools
Sponsored By

htc-excalibur-s620-4 I'm getting ready to setup an HTC Excalibur and I wanted to post my list of favorite sites to visit with my Mobile Browser and a list of the apps I really need to install to make my Windows Mobile Smartphone complete.

  • Amazon Mobile - http://m.amazon.com - A basic, but very usable site, focused on search, that lets folks who've setup their Amazon account ahead of time purchase directly from the phone. Nice if you have Amazon Prime Free Shipping.
  • BBC PDA - http://www.bbc.co.uk/mobile/pda or http://www.bbc.co.uk/mobile - BBC has a mobile site and a PDA site, but the PDA site looks best on Smartphones or Blackberries. The best of the BBC on my phone. The mobile site would look good on an old black-and-white WAP Nokia.
  • CNN Mobile - http://m.cnn.com - Same here, mobile CNN, some pics, I use this site a lot.
  • Engadget Mobile - http://m.engadget.com - My favorite tech and gadget blog, now with mobiley goodness. I wish I could see comments though.
  • Hanselman.com - http://www.hanselman.com - Ha! See what I did right there? Back in the day, we taught dasBlog about mobile devices and if you hit hanselman.com from a Blackberry or Windows Mobile browser (and a number of other tiny browsers), we'll detect it and give you a mobile experience. Yay!
  • Facebook - http://m.facebook.com - In terms of pure functionality, I'd say that Facebook's mobile site is, hands-down, the most functional. It feels like you can most everything you'd ever want to using only Tiny HTML. This site and this company continue to impress, probably because it's running entirely on Red Bull and 20-year-olds.
  • Flight Stats - http://mobile.flightstats.com - This fine site has saved my tuckus a number of times while traveling. Their Airport Chatter section is interesting also.
  • Google - http://www.google.com/xhtml - The Tiny XHTML version of Google includes location specific searches and personalization with News, Weather, Movies, etc.
    • +1-800-GOOG-411 (+1-800-4664-411) - If you're able to call this number, either domestically or internationally, it's worth a try because it's amazing. Much better than the "1-800-Tell-Me stuff back in the day, but still of the same vein. I use this a LOT.
  • Microsoft Live - http://wls.live.com or http://m.live.com - If you hit wls you'll get your browser detected and possible prompted to download a nice applet for your phone. If you hit m.live.com you'll get tiny Windows Live Search.
  • Gmail - http://m.gmail.com - If you hit gmail with your phone you should get detected and sent over to the mobile version. If not, you can hit m.gmail.com or https://mail.google.com/mail/x/ where the x is magic. If you're running Google Apps for Your Domain (GAFYD) you can hack that URL also.
  • Joystiq - http://m.joystiq.com - Tiny Gaming Site. Interestingly, while they use (I think) the same back end as Engadget, sometimes the fonts are all wonky.
  • Mobile MSN - http://m.msn.com - A decent mobile portal and good jumping off point. The mobile stocks are particularly good.
  • MSNBC - http://www.msnbc.msn.com - It's astonishingly LAME that you can't get to this site from http://m.msnbc.com but perhaps they'll read this and make that DNS change, because this is a really good tiny news site.
  • Alarm.com - https://www.alarm.com/pda - I use Alarm.com to manage my security systems at the house and our rentals from my phone. If you've got a service available over the web, you really ought to have a minimal mobile website so kudos to them for having one.
  • Twitter - http://m.twitter.com - Does exactly what it says it does...mobile twitter, although I'd like to be able to see Direct Replies in the interface.
  • Wapedia (Mobile Wikipedia) - http://wapedia.mobi/en - Very useful for winning arguments with the wife self-edification, it's the mobile Wikipedia.

I think it's funny that folks thought that the ".mobi" top level domain extension was a good idea and that the internet just changed "www.foo.com" to "m.foo.com" and saved the registration fee. Plus, I don't have to tap out the "obi" which saves me, like minutes.

What are your must-have mobile websites, Dear Reader?

Related Posts:

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

The Weekly Source Code 13 - Fibonacci Edition

January 23, 2008 Comment on this post [135] Posted in ASP.NET | Microsoft | Programming | Source Code
Sponsored By

iStock_000000237891XSmall If you're new to this, each week I post some snippets of particularly interesting (read: beautiful, ugly, clever, obscene) source and the project it came from. This started from a belief that reading source is as important (or more so) as writing it. We read computer books to become better programmers, but unless you're reading books like Programming Pearls, you ought to peruse some Open Source projects for inspiration.

And so, Dear Reader, I present to you the thirteenth in a infinite number of posts of "The Weekly Source Code." Here's some source I was reading this week. I wanted to see what a Fibonacci number generator looked like in a number of different languages.

Remember (from Wikipedia) that the Fibonacci sequence looks like this:

...after two starting values, each number is the sum of the two preceding numbers. The first Fibonacci numbers also denoted as Fn, for n = 0, 1, … , are:

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, ...

Here's a few implementations I thought contrasted nicely. There's also a great writeup on Fibonacci related things on Dustin Campbell's blog.

F#

  • Here's a basic Fibonacci function in F#.
    let rec fib n = if n < 2 then 1 else fib (n-2) + fib(n-1)
  • Or, if you want input and output as an F# console application:
    let fib_number = int_of_string (System.Environment.GetCommandLineArgs().GetValue(1).ToString());;
    let rec fib n = if n < 2 then 1 else fib (n-2) + fib(n-1);;
    Printf.printf "\nThe Fibonacci value of %u is: %u\n" fib_number (fib fib_number);;
    exit 0;;

Ruby

  • Here it is in Ruby, from RubyTips.org:
    x1,x2 = 0,1; 0.upto(size){puts x1; x1 += x2; x1,x2 = x2,x1}
  • But that's really hard to read and kind of smooshed onto one line. A more typical console app would look like this:
    class FibonacciGenerator   
      def printFibo(size)   
        x1,x2 = 0, 1   
        0.upto(size){puts x1;x1+=x2; x1,x2= x2,x1} # note the swap for the next iteration   
      end  
      f = FibonacciGenerator.new  
      f.printFibo(10) # print first 10 fibo numbers   
    end  

C#

  • There's many ways to do this in C#, so let's start with a basic C# 2.0 implementation.
    static int Fibonacci (int x)
    {
       if (x <= 1)
          return 1;
       return Fibonacci (x-1) + Fibonacci (x-2);
    }	
  • Now, here's a great way using C# 3.0 (actually, .NET 3.5 and System.Func from the new System.Core:
    Func<INT , int> fib = null;
    fib = n => n > 1 ? fib(n - 1) + fib(n - 2) : n;

Scala

  • Lots of folks are excited about Scala, and many are calling it "the latest programmer's shiny object." It's interesting not just for its syntax, but it's full interoperability with Java.  Here's a recursive Fibonacci in Scala.
    def fib( n: Int): Int = n match {
        case 0 => 0
        case 1 => 1
        case _ => fib( n -1) + fib( n-2)
      }

Erlang

  • Here's Fibonacci in Erlang, and you can find many other implementations at LiteratePrograms.org, a great site for reading source!
    fibo(0) -> 0 ;
    fibo(1) -> 1 ;
    fibo(N) when N > 0 -> fibo(N-1) + fibo(N-2) .

Which is your favorite? I like the C# 3.0 one and the F# ones. Also the Ruby double variable swap is pretty cool. They just feel right, although a close runner-up is the LOLCode implementation of Fibonacci from a few weeks back.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Hanselminutes Podcast 97 - ADO.NET "Astoria" Data Services with Shawn Wildermuth

January 23, 2008 Comment on this post [3] Posted in ASP.NET | Microsoft | Podcast | Programming
Sponsored By

shawnwildermuthMy ninety-seventh podcast is up. It this episode I talk to the ADOGuy, Shawn Wildermuth, about ADO.NET Data Services codenamed "Astoria." We discuss Astoria and how it's *not* just exposing your database to the Internet. We delved into REST and how Astoria and Silverlight are a good mix for the right application.

Subscribe: Subscribe to Hanselminutes Subscribe to my Podcast in iTunes

If you have trouble downloading, or your download is slow, do try the torrent with µtorrent or another BitTorrent Downloader.

Do also remember the complete archives are always up and they have PDF Transcripts, a little known feature that show up a few weeks after each show.

Telerik is our sponsor for this show.

Check out their UI Suite of controls for ASP.NET. It's very hardcore stuff. One of the things I appreciate about Telerik is their commitment to completeness. For example, they have a page about their Right-to-Left support while some vendors have zero support, or don't bother testing. They also are committed to XHTML compliance and publish their roadmap. It's nice when your controls vendor is very transparent.

As I've said before this show comes to you with the audio expertise and stewardship of Carl Franklin. The name comes from Travis Illig, but the goal of the show is simple. Avoid wasting the listener's time. (and make the commute less boring)

Enjoy. Who knows what'll happen in the next show?

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Standing on their shoulders and paying it forward

January 22, 2008 Comment on this post [34] Posted in Musings
Sponsored By

It's my birthday! I turn 0x22 today, beginning the downward slide to 0x28, and then death. ;) Seriously, it's an interesting birthday because I'm definitely not a "young hotshot" any more. (It's possible I haven't been for 10 years, but I can dream, right?)

It's funny how these things happen. I didn't think I'd be a Computer Person. In high school I was into Theatre, doing a number of plays, a few as the lead or co-lead, and I'd always assumed I'd be on TV by now. Of course, Ryan Reynolds has my career, so I can't do much about that. Heh, maybe I'm still in theater and I don't realize it?

Anyway, before high school, my 5th grade teacher called a meeting with the superintendent and principal and said "if we don't challenge this kid, we're going to lose him." This is teacher-speak indicating that I was a bit of a rambunctious child, likely to be convicted at some point of a white-collar crime.

The idea they came up with changed my life. They agree to let me and my dad "steal" the school's computer (there was only one at the time) on Friday nights by backing my dad's truck up to the school, so I could use it over the weekend, as long as I got it back before Monday morning. Mind you we're talking about $2500 in the early 80s here, so this was a significant risk she was taking. That risk started me on the road I am today. If she hadn't taken that chance, who knows what would have happened?

I think about the chances that various people took with me over the years and the trust they placed in me, without which I wouldn't be here. I think of the people, like my parents, who love me unconditionally, and for that I am grateful.

I remember when I was 15, in a particularly nasty teenage phase when my father said to me "Son, I love you dearly, but I don't like you very much right now." What a powerful statement that is and nearly 20 years later I remember it. It's important to be able to make a statement like that, and it's a testament to one's love to be that honest.

I'm sure my parents wanted to throttle me (and still do) a number of times, but they stuck with me and my brother - their two boys, now men with families of our own.

And now, at 34, I have two boys of my own. These tiny men who put their trust in me and my wife to do the right thing, stick with them, and take some chances in order to give them the very best opportunities and propel them to heights we haven't dreamed of.

I think about my wife, and the ridiculous decision she made in marrying me. We had a date on July and were married that October. That's a three month-long courtship, talk about taking a chance. That was over 7 years ago. I hope she renews me for another seven! ;)

All these people have helped and continue to help me, and only now as a man of 34 am I mature enough to look down and realize that I've been standing on their shoulders all these years. For this, I thank you all. I will repay you all the best I can by paying it forward.

If you have a blog, Dear Reader, why not take a moment at the beginning of this new year to write a post about the people that helped you get where you are? Parents? Teachers? First bosses? Friend? Spouse? Whose shoulders are you standing on?

Related Posts

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.