Scott Hanselman

Hanselminutes Podcast 55 - MonoRail as Alternative ASP.NET

March 16, '07 Comments [22] Posted in ASP.NET | Podcast
Sponsored By

My fifty-fifth podcast is up. In this episode I sit down with two developers, Aaron Jensen and Jacob Lewallen from Eleutian, who are using the MonoRail framework for their current (very large) project.

Check out their blog post called "The way we write programs," over at the Eleutian Blogs.

Mono is a clean MVC Front Controller-based framework for ASP.NET that promises to increase separation of concerns and offers a fresh (at least for .NET developers) perspective on developing .NET for the Web. Enjoy.

ACTION: Please vote for us on Podcast Alley! Digg us at Digg Podcasts!

Links from the Show

Monorail and the Castle Project (mt8)
Inversion of Control Containers and the Dependency Injection pattern (mt9)

Subscribe: Feed-icon-16x16 Subscribe to my Podcast in iTunes

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

Our sponsors are Telerik and /n software.

Telerik is a new sponsor. 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)

  • The basic MP3 feed is here, and the iPod friendly one is here. There's a number of other ways you can get it (streaming, straight download, etc) that are all up on the site just below the fold. I use iTunes, myself, to listen to most podcasts, but I also use FeedDemon and it's built in support.
  • Note that for now, because of bandwidth constraints, the feeds always have just the current show. If you want to get an old show (and because many Podcasting Clients aren't smart enough to not download the file more than once) you can always find them at http://www.hanselminutes.com.
  • I have, and will, also include the enclosures to this feed you're reading, so if you're already subscribed to ComputerZen and you're not interested in cluttering your life with another feed, you have the choice to get the 'cast as well.
  • If there's a topic you'd like to hear, perhaps one that is better spoken than presented on a blog, or a great tool you can't live without, contact me and I'll get it in the queue!

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 twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Managed Snobism

March 13, '07 Comments [29] Posted in Learning .NET | Musings | Programming
Sponsored By

There was a great comment on a recent post here last week where I was trying to get a Managed Plugin working with an application that insisted on its plugins being C++ DLLs with specific virtual methods implemented.

Here's the comment with my emphasis

Great article. It would be nice to see a little less "managed snobism". Personally, I don't need to use up 100MB of my memory with a framework just to let me generate 32x32 bitmaps. So I'm grateful that the managed route is not the default. Remember, 90% of functions in .NET are just wrappers around the underlying API functions, so in effect, all they do is slow you down, while giving you convenience.

This reminded me of an article I did a few years ago when folks were still asking silly questions like "Is your application Pure .NET?" The article was called The Myth of .NET Purity and was published up on MSDN under an article series called ".NET in the Real World." To this day I'm still surprised that they let me publish it.

The (interestingly anonymous) commenter says: "...so in effect, all they do is slow you down, while giving you convenience." Well, sure. Everyone knows this quote:

Any problem in Computer Science can be solved with another layer of indirection.

It's a great quote. As an aside, the quote is attributed to nearly every smart Computer Scientist. Including David Wheeler, Butler Lampson and Steven M. Bellovin. Lampson says it was Wheeler, but it was one of these three guys.

But a game developer at Sun adds a clever touché to the old adage:

The two software problems that can never be solved by adding another layer of indirection are that of providing adequate performance or minimal resource usage. - Jeff Kesselman

And he's right. Of course, .NET is a (most excellent layer of) Managed Spackle over the Win32 API. But it's really GOOD spackle. It's so good that we get collectively frustrated when a new API (SideShow, AzMan) doesn't have a good initial managed API (SideShow does now). A nice, clean managed API adds a fantastic amount of convenience in exchange for a very reasonable performance hit.

The performance hit - which I haven't personally measured - is no doubt less than even the most trivial of network calls. How much overhead is added? Not much.

Approximate overhead for a platform invoke call: 10 machine instructions (on an x86 processor)

Approximate overhead for a COM interop call: 50 machine instructions (on an x86 processor)

Gosh, that isn't much. Sure, there are always scenarios we conceive of that could add up, but that's what profiling on a case-by-case basis is for.

If .NET Purity is a myth, and the whole thing is just there to make our lives easier, then this is an easy trade off. I just remember that I can code in C#/VB.NET, for a small cost. I get speed of dev, and I give up speed of execution. I can code in C++, and give up speed of dev (a smidge) and gain (possibly) speed of execution. I can code in ASM and give up lots of productivity in exchange for my immortal soul and a really fast program. Or I can go to heaven, pursue beauty if I like, and give up so much performance to cause a scandal.

But it's not a simple trade off. Certainly not at the method or even component level. William Caputo makes a similar point with emphasis mine:

...this calculation is done unconsciously by those programmers who hear "we're trading efficiency for productivity." It's why they are reluctant to take a serious look at higher-level languages. A one-time productivity hit to get faster run-time performance certainly seems like a good trade-off, but the flaw in the argument is that productivity measurement is not reset with each task. It's cumulative. Unlike a programming assignment ("Implement Quick Sort Please"), productivity is measured across an entire solution (whether a build script or a trading system) -- and not just the first writing of the code, but throughout its useful lifetime (the vast majority of coding time is spent changing, or maintaining existing code).

In the real world, its not "write once, run forever", its "write a bit, run a bit, change a bit, run a bit", and so on. I am not saying that run-time efficiency isn't important. It is. The best way to compare run-time efficiency and programmer productivity is not at the micro level, but at the macro level.

Yes, .NET adds overhead. Certainly not enough to worry about for business apps, given the productivity gains. We're not writing device drivers here. In my original example where I want to write managed plugins for the Optimus Keyboard, since the max frames per second on the keyboard is 3fps, performance isn't a concern (nor would it be even if I needed 30fps).

If being a Managed Code Snob is wrong, I don't wanna be right.

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 twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

The CodingHorror Ultimate Developer Rig Throwdown: Part 1

March 9, '07 Comments [66] Posted in Musings | Tools
Sponsored By

I wonder if my wife will read this post and ask me about it. I think she'll say it's OK. I don't know about you, but over a (small) certain amount, all purchasing decisions are dependant on the WAF .

I'm going to use the money from Google Adsense that's been sitting in my Paypal account and get a new computer. My current one is a Frankenstein's Monster and it sounds like a Jet Plane.

There's lots of talk on the net, and no end to the free advice you can get on how to create the "World's Greatest Gaming Rig" and they use lots of acronyms like SLI and words like Northbridge and terms like Quad-Core or Octo-Core or whatever.

I used to be The Man™ when it came to building my own machines. Used to be. If you wanted a field of DIP memory chips put onto an ISA card, I was the guy. Now, I built all the machines in my house, and had fun doing it. I am proud that my system didn't cost that much because it was built one piece at a time, over time. However, I don't revel in the building. I just want it to work.

Sure, one (not me) could go to Dell or Alienware or whoever, give them US$6000 (or more) and build the Ultimate Gaming Rig, but it'd likely be loud, and it certainly wouldn't be loved. Plus, I'm not that big of a gamer. That's what my Xbox is for.

Who loves this stuff? Atwood. He wallows in it like a pig in slop. He's what we call an Overclocking Fundi.

He's going to break his self-imposed rule (of not building for friends) for me and create The Ultimate Developer Rig.

Here's the priorities, in order:

  • Fast. Wicked fast.
    • As fast as I am (if you've ever seen me demo live). I want this computer tuned to Alt-Tab as fast as possible. As Jeff says: "You want max speed right, damn the torpedoes?" D*mn right.
  • Fast. Did I mention fast?
    • I don't want have time to THINK about what it's doing while I wait. I wait, in aggregate, at least 15 minutes a day, in a thousand tiny cuts of 10 seconds each, for my computer to finish doing something. Not compile-somethings, but I clicked-a-button-and-nothing-happened-oh-it-was-hung-somethings. Unacceptable. 15 minutes a day is 21.6 hours a year - or three full days - wasted.
  • Overclocked but Stable. I appreciate that machines are clocked to a certain speed for a kind of conservative stability, but I want it to be fast.
    • Quad Core if possible.
  • Quiet. Any schmuck and go to their local computer store and build a computer.
    • But building one that's fast AND quiet is an art form. Overclocking and staying low noise is hard. Staying quiet and running fast is what separates pros from, well, me. That's where we install aftermarket coolers, and line the case with silencing materials, use sorbothane to damp the drives. That's Craftmanship 2.0.
      Hell, let's suspend the Hard Drives with rubberbands from the inside of the case. 
  • Reliable. It'll be fast, but I need it to not freak out just because it's been running 100% for a few days. (I'll find it work, trust me.)
    •  I want to pick a good video card, and good RAID, etc, but the drivers need to be known to be reliable. Two striped Raptor X 10,000 RPM SATA drives are useless if their RAID driver isn't also well thought of.

What else, Dear Reader, do I need to consider while we build The CodingHorror Ultimate Developer Rig? Should I got x64 on Vista or wait? We're aiming for machine (hopefully much) less than US$3000 that'll compete with any US$6000 Dell.

This is not a gaming rig, this is a Productivity Rig. What's it need?

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 twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Hanselminutes Podcast 54 - Squeezing Continuous Integration

March 9, '07 Comments [2] Posted in Nant | NCover | NDoc | NUnit | Podcast | Programming | Tools
Sponsored By

My fifty-fourth podcast is up. In this episode we continue the discussion started in Episode 4 - Continuous Integration. We're fortunate to be joined by Jay Flowers, maker of CI Factory, a Continuous Integration Accelerator that lets you get a continuous integration build running in minutes, not days. It's a generator that creates build scripts, CruiseControl server files, project structure and more. Take a look at version 0.8 and the screencast on installation and setup. We believe that there's more to just Build and Test...you can automate everything and even have your build server pop out ISO images, CDs, or complete configured Virtual Machines. Enjoy.

ACTION: Please vote for us on Podcast Alley! Digg us at Digg Podcasts!

Links from the Show

Jeff finally gets with it (mm0)
Backup Package (mm5)
How to make a CI Factory Package (mma)
Code Churn, Predicting how may bugs (mm1)
Playing for Real, More Than a Scoreboard - Threshold Package (mm6)
CI Factory Installation (mmb)
VSTS Integration (mm2)
Analytics Package - Xsl exsl:document or multi-output (mm7)
Phil Haack A Comparison of TFS vs Subversion for Open Source Projects (mmc)
Updated AsyncExec stuff (mm3)
Analytics Package Screen Capture (mm8)
Traceability and Continuous Integration (mmd)
AsyncExec stuff (mm4)
A Recipe for Build Maintainability and Reusability (mm9)

Subscribe: Feed-icon-16x16 Subscribe to my Podcast in iTunes

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

Our sponsors are Telerik and /n software.

Telerik is a new sponsor. 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)

  • The basic MP3 feed is here, and the iPod friendly one is here. There's a number of other ways you can get it (streaming, straight download, etc) that are all up on the site just below the fold. I use iTunes, myself, to listen to most podcasts, but I also use FeedDemon and it's built in support.
  • Note that for now, because of bandwidth constraints, the feeds always have just the current show. If you want to get an old show (and because many Podcasting Clients aren't smart enough to not download the file more than once) you can always find them at http://www.hanselminutes.com.
  • I have, and will, also include the enclosures to this feed you're reading, so if you're already subscribed to ComputerZen and you're not interested in cluttering your life with another feed, you have the choice to get the 'cast as well.
  • If there's a topic you'd like to hear, perhaps one that is better spoken than presented on a blog, or a great tool you can't live without, contact me and I'll get it in the queue!

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 twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Screencast: Writing Managed .NET Plugins for the Optimus Mini Three Keyboard

March 8, '07 Comments [9] Posted in Coding4Fun | Learning .NET | Programming | Screencasts | Tools
Sponsored By

Here's a screencast demoing writing Managed .NET Plugins for the Optimus Mini Three Keyboard.

I'm a fan of the Optimus Mini-Three Keyboard for its potential. It's a harbinger of things to come, like someday a complete keyboard with screens for keys. Their hardware is wonderful. But, as a design shop with a specialization in hardware, not software, their software plugin model leaves much to be desired.

When I did my video on an Optimus Mini Three post in managed code, I ended up P/Invoking into their library, bypassing their plugin model and opting instead for a command line experience. Bummer, right?

The Optimus Configurator is pretty, to be sure, but it's programming model is obtuse and trapped in the C++ world. And not the nice OOP C++ world, the nasty part of that world.

The "implement these dozen virtual methods that tunnel strings via magic indexes" world:

virtual BOOL Paint(int button, HDC hdc) = 0;

// to collect INFO_* values from plugin 
virtual LPARAM GetInfo(int index) = 0;

 Meh. When your unmanaged C++ plugin gets called, the configuration app will call your GetInfo at least 20 times, passing in different magic numbers to get information about your plugin like name, webpage, version, etc. Not only are there these internal semantics to grok, there's a whole get/setProperties state bag thing to manage as well.

It's a common pattern for plugins though, especially when you as the host want to provide persistence to your plugins. The Windows Live Writer plugin model is similar...I had to maintain state for my Insert Amazon Links WLW Plugin via the same pattern.

On the other hand, the Paint stuff is very clever, actually. You get an HDC (handle to a device context) passed in, you paint to it, and they handle getting the resulting image over to the Optimus via their USB to Serial Bridge.

Screencast of managed Optimus Mini Three Keyboard PluginsBut, their plugins aren't managed code, and I believe that this more difficult model explains the fact that while the device is selling well, there are only (as of the writing of this post) three 3rd party plugins.

Harald Röxeisen went off (he says after reading my post...Cool!) and has released an alpha of a .NET library for Optimus Support. However, rather than supporting managed plugins in the Optimus Configurator, he's written his own configurator from scratch in .NET, and built a plugin model on top of that. It's basic, but a fantastic start. He proves my point about writing plugins, as even his alpha include THREE all new plugins written against his managed API. Excellent.

For me, I've done the inverse of Harald, and got managed plugins to work inside the existing configurator. After my last post, I got great ideas from Matt Davis of DocumentCommand and Jason Copenhaver. Jason's was managed/unmanaged C++ that would provide a bridge, and Matt's used COM and the .NET COM Interop stuff as a middleman. For me, Matt's was faster as I know that stuff pretty well.

Here's the general idea...Matt's shim implements the C++ virtuals that the configurator expects and calls CoCreateInstance on a known ProgId, in my example it's "Optimus.Nothing." Could be whatever. You'll need one shim and one ProgId per managed plugin as far as I can see. That call to CoCreateInstance is actually activating a .NET assembly that is implementing Matt's COM interface (that we might want to make even more COMish) created via TlbImp. Since we're .NET, the runtime and we get loaded, and wackiness ensues. 

We're in a no-man's land between managed and unmanaged code (and I'm sure we're leaking like a sieve) but we do things like Marshal.StringToHGlobalAnsi(managedString).ToInt32(); and

static int i = 0;
public int Paint(int button, IntPtr HDC)
{
    i++;
    DebugWrite(button);
    using (Graphics g = Graphics.FromHdc(HDC))
    {
        Brush b = ((i % 2 == 0) ? Brushes.Blue : Brushes.Red);
        g.FillRectangle(b, new Rectangle(0, 0, 96, 96));
    }
    if (i > 100) i = 0;
    return 1;
}

...for example. But, happily, we seem to not be noteworthy because the Mini Configurator loads us just fine.

I've approached Harald and perhaps we'll figure out a better bridge for .NET plugins where I could write a plugin that supports his managed API and use it in either his configurator, or the original configurator from Optimus. If I'm going to be promoting writing these plugins, we'll want the interface to hide a lot of the dispatchy stuff, more like the plugin model Bryan Batchelder and I did for the USB Security Key Fobs.

In Harald's .NET configurator, the abstract class you derive from to create a "Harald plugin" is very clean and includes new features like OnKeyHold and OnKeyDoublePress that the Optimus software doesn't make easy. He also, of course, uses BCL types like Bitmap over HDCs.

public abstract class OptimusMiniPlugin
{
    protected OptimusMiniPlugin();
    public abstract void Initialize();
    public virtual void OnKeyDoublePress();
    public virtual void OnKeyDown();
    public virtual void OnKeyHold();
    public virtual void OnKeyPress();
    public virtual void OnKeyRelease();
    public virtual void OnKeyUp();
    public abstract void Repaint();
    public void RequestNextUpdate(TimeSpan interval);
    public abstract void Terminate();
    public abstract void Update();
    public void UpdateImage(Bitmap image);
}

I'm excited to see the possibilities for this little device. Perhaps between my stuff and Haralds (and someone elses?) we can get a Windows Vista Side Show driver working for this thing...probably time for YAGCP (Yet Another Google Code Project). For now, here's what I've got. I'll do a Coding4Fun article on this in much more detail this weekend perhaps, for now, it's just scribbles and it works on my system. ;)

I wonder if the Optimus Keyboard folks care...I hope so. I'm convinced that writing managed plugins is easier than unmanaged (on Windows or in Mono). Is this even worth debating?

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 twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

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