Sacramento Software Development

BlogEngine.NET Comes to The Workbench

Posted by John Lockwood on October 2nd, 2009

As I’ve started to develop a modest control for displaying ASP.NET certification exam questions and some other bits and pieces of code that I haven’t written about yet, it got to be pretty obvious that writing about ASP.NET on a PHP blog was a lot like trying to get married on top of a backhoe. Yes, it’s possible in principle, but for most purposes it’s probably best avoided.

More concretely, I want to be able to roll exam questions into a blog post and let folks comment on them, while still having a database of questions and being able to develop the exam logic independently of the blog.  Also, I want to write ASP.NET code and be able to display it in the blog.  Some of that’s certainly doable using tricks like Web Services, but that’s not a lightweight approach to the problem.

So tonight while the old body was begging me for a nap, good programmer that I am I threw some caffeine at the problem and put up a quick BlogEngine.NET blog on AspWorkbench.

What – no ParticleWave theme yet?  Hey man, I just installed it.  Chill.

Given that I’ve never installed a BlogEngine.NET instance on Godaddy before, it wasn’t too awful – I’ll try to write some tips tomorrow while they’re still somewhat fresh in my mind but when I’m a bit more coherent.  There are several quirks that need polishing.  For example, although I got the test email to succeed after some searching, neither the contact form nor the “Send email when someone posts a comment” feature have decided to join the party.  The installation was something of a pain having been through several successful “Wordpress famous fifteen minute” installs, but some of that was first time learning curve.  On the plus side, Live Writer connected and worked with no trouble at all, which is a big deal for me because I’m a Live Writer junkie.

Most importantly, I’m now in a position to integrate more ASP.NET into my blogging about ASP.NET – go figure!

Posted in ASP.NET | Add a comment »

What’s So Funny About the UpdatePanel Control, Love and Understanding?

Posted by John Lockwood on September 21st, 2009

I recently reported that I had a domain for an ASP.NET site to hack around on with nothing on it yet.  Since then I’ve made some progress and had some fun coding some ASP.NET, so I can now show off a minor feature on a new web site, the Featured ASP.NET Certification Question.

This isn’t exactly Google or even StackOverflow yet, to be sure, but there were nevertheless a fair bit of learning and practice goals along the way to this simple looking page. 

The Site and The Control

First, I ported the master page from this site, so that was worth remembering how to do.  Master pages can also expose properties to their content pages, which I haven’t done yet, but perhaps I’ll get into that when I add authentication to the site. 

The next steps were to set up a brain-dead and stubbed out custom control, ExamQuestionControl, while on the lower decks working out the database structure and connection strings for development and production and testing along the way using NUnit tests (Yes, Dan, NUnit Tests).  Once those were in place I began testing out the Plain Old CLR Objects and a simple, one method repository consisting of “QuestionFindByID”, which was all I needed at this point.  I implemented the repository using very basic (and hence certification-friendly) calls into the ADO.NET Connected Classes (one of which forms the basis for my first Featured Question).  Once NUnit had lifted the database up by its bootstraps, It was quite a simple matter to un-stub the formerly brain-dead ExamQuestionControl. 

Once the control was more or less working, I decided (as if setting myself up to take a look at the AJAX chapter) that I didn’t like the fact that the “Show Answer” button posted back the entire page to the server.  Microsoft’s UpdatePanel control provided an elegantly simple way to AJAX enable my control to avoid a full page refresh.  No seriously.  If your hatred of Microsoft is interfering with your Buddhist practice, sit still and contemplate the UpdatePanel control, and you’ll be filled with loving kindness.

Early Hiccups

In the earliest stages of the work, getting the hosting set up and so forth, I ran into a few noteworthy hurdles.  One was that I needed to compile the site and bin deploy the code-behind pages.  Other problems involved deploying an MVC site to godaddy.com, but as you can see from the link, a kind fellow traveler provided the solution.  Before I found that link, I had to re-code the master pages to inherit from System.Web.UI.MasterPage instead of System.Web.Mvc.ViewMasterPage.  Once I found that link, however, I was able to restore the ViewMasterPage with no problems.

What I would recommend to your attention when you get to the deployment phase of your project is to right click on your project and check out the “Publish…” menu option.  As others pointed out in the earlier link, the easiest thing to do turned out to be to publish to a local directory and upload files.  The link above shows you how to bin deploy MVC, and that trick no doubt works on other weird dependency issues.

Once I’d played with that a bit I decided to clean up what I’d originally uploaded, and noticed then that Visual Studio’s publish doesn’t copy over image files referenced in your CSS if you select the option to only copy what’s needed.  Copy those, end of problem.

image

Posted in ASP.NET, ASP.NET MVC | Add a comment »

Mixing ASP.NET and ASP.NET MVC in the same project – A Visual Studio Starter Project

Posted by John Lockwood on September 16th, 2009

There are lots of good reasons to dive into Stephen Walther’s ASP.NET MVC Framework Unleashed.  I won’t go into all of them now – perhaps I’ll write a review when I’m further into it.  My short recommendation is to go buy it, especially if you’re going to do so by clicking the link at the right, whereby I’ll make a whopping 29 cents or whatever it is.

And meantime, in a paradox that proves once again that information doesn’t always need to be perfect to be useful, I believe one of Walther’s weaker chapters (in terms of eloquence) was simultaneously one of his stronger chapters (in terms of usefulness).  This is the chapter on deployment, which deals (in part) with how you can add ASP.NET MVC to an existing ASP.NET application.  This was a really useful chapter in its broad outline, even if the layout of the file “diffs” left a lot to be desired, leaving some of the details a bit sketchy.  The short version is that you sit down for a couple of hours over coffee and merge files and add dependencies.

I used the information Walther provided to put together a starter Visual Studio 2008 project that allows you to use ASP.NET “classic” web forms together with ASP.NET MVC models / views / controllers in the same project.  (I also chose the unit testing option so there are tests built in).  I’ll try to do some more pounding on it before you read this, so it should be workable enough that the only thing you’ll want to do is rename all the namespaces and so forth from AspNetStarter to whatever you want to call your application.

Anyway, I hope you find it useful.  If so I put it together.  If not, I had nothing to do with it.  Here it is as a 389 Kb or so zip file.

Posted in ASP.NET, ASP.NET MVC | Add a comment »

Microsoft ASP.NET MVC: A Glimmer of Hope for Ruby Programmers (or is that ASP.NET Programmers?)

Posted by John Lockwood on September 2nd, 2009

Late born head case that I am, I vibrate between programming languages like a sort of high tech lady’s toy.

Analyze that.

Thus it is that I wrote an article recently comparing ASP.NET and Ruby on Rails.  In that article I mentioned Microsoft’s pathetic support for the Model View Controller pattern.  This was based on work I’d done an eon ago in programming time, 2006 or 2007 or so.  With that I was able to declare:

This may have changed since I last looked at it, but on my last ASP.NET contract they had an MVC implementation that completely broke browser navigation and was a nightmare to code to.

Well I don’t have all the details yet, but I’m happy to report that since that glib dismissal Microsoft has had Ruby in its sights in a big way, and has further refined something they were no doubt working on when I made that dated statement.  (You know what print journalists bag on us bloggers for – we’re light on our fact checking).  Enter Microsoft MVC complete with a 15 minute podcast by Stephen Walther.  Look familiar?  It should.  Of course this is straight out of the Ruby on Rails 15 minute podcast, which in turn was lifted whole cloth from the pioneering work of Cobol on Cogs.

Cobol on Cogs was obviously a parody of Ruby on Rails, and I’m sure there are Ruby programmers who probably consider ASP.NET MVC to be in the same category, though interestingly enough, the official rails blog mentions Cobol on Cogs but not ASP.NET MVC.  Much of what you can find there are bashes of ASP.NET (like this and this) that were absolutely legitimate in 2005 but might be getting a bit obsolete by 2010.

I’m going to take a look at ASP.NET MVC, and in case I end up hating it, let me be the first to call it this:   Cobol on Cogs 2.0.

Meantime I certainly wouldn’t count out Microsoft’s ability to steal someone else’s ideas, market them, and provide me with a job in the process.  C Sharp, after all, is “Java run through a thesaurus”, and Redmond has the law suits to prove it.  I suspect we’re in the next phase of this, and I find it exciting.

So I’m going to spend another hour or two on the coolest programming web site ever, which incidentally is written in ASP.NET MVC.

Posted in ASP.NET, Ruby on Rails | Add a comment »

Review of Stephen Walther’s ASP.NET MVC Framework Unleashed

Posted by John Lockwood on August 31st, 2009

This is a reprint of a review I did on Amazon.com.

I bought Stephen Walther’s ASP.NET MVC Framework Unleashed after several months of working on a legacy C and C++ project which looks nothing like Walther’s book.  Following that I spent many a happy Saturday and Sunday ramping up on Ruby on Rails, but finally giving up to revisit my Microsoft skills.  ASP.NET MVC is a serious attempt by Microsoft to lure wayward Ruby on Rails types like me back into the fold, and I consider myself re-folded.

Given my background, any halfway decent book on ASP.NET MVC would probably have been welcome, but Walther’s book is especially welcome because it makes a serious attempt to treat ASP.NET MVC in the context of Test Driven Development.  Well, all of that is what you’d expect if you take the cynical view that Microsoft is competing for developer mind share against Ruby on Rails, where the tests are "baked right in" (of course they all pass by default, but that’s another story).  But Walther’s book is far more than a cheerleading book about TDD, and actually gets you into how to structure your code to support it.  Using a generic repository class and relying heavily on the dependency injection pattern, Walther leads you through setting up your code so that it’s loosely coupled, testable, and (presumably) easily refactored.

Admittedly, it sometimes looks like Walther’s approach takes too much manual lifting compared to Ruby on Rails — and that’s especially true when you run into Microsoft annoyances like not being able to refresh an Entity Data Model from the database.  On the other hand, it’s hard for an experienced software developer not to take a skeptical view of the magical rails "we can build a blog in 15 minutes" approach to the world.  But still I feel that the techniques Walther talks about are the kind of thing that I really need to try out on an application or two.

I gave the book four stars because there were a few sections that I thought could have been explained better.  For example, I used his chapter on deployment almost immediately to create an application that supports both "legacy" ASP.NET and ASP.NET MVC, and the information there worked great, but I felt the file differences could have been narrowed down a bit more.  Also in his discussion of the generic repository, I felt like we lost sight of the model there for awhile.  Since there was a lot of ground to cover, a general overview discussing how the Entity Data Framework, the model, the repository and the service layer were all going to tie together might have been helpful.  My final quibble is that I felt there could have been a bit more material on the relationships among the Entity Data Framework, LINQ, and LINQ to SQL.  I think Walther’s book gave the impression that the EDF and LINQ are orthogonal, whereas other Microsoft sources lead me to believe they’re more complimentary.

Despite its flaws, however, I want to leave you with the title of my review, that this is one of the best programming books I’ve read in a long time.  It’s the kind of book that expands your horizons and makes you want to try things out the way the author has outlined.  To be sure, Walther’s book is not the book you want to read if you goal is to hack together an unstructured ASP.NET MVC application in record time.  But if your goal is to learn ASP.NET MVC while becoming a better programmer along the way, this book merits your serious attention and you should be pulling your credit card out now.

Posted in ASP.NET, ASP.NET MVC | 1 Comment »

ASP.NET versus Ruby On Rails

Posted by John Lockwood on April 19th, 2009

My friend and college housemate Daniel Steinberg stopped by  recently and caught me red-handed in yet another heinous act of last week’s marketing.  By “last week’s marketing”, I mean that I should know better than to say this site is about a specific platform / language/ technology.  This is generally the wrong approach for a computer-linguistic gadabout to take.  John Lockwood putting up a web site about a programming language is like Madonna putting up a web site about her one true love.  The next words out of her mouth are bound to be:  “Woops, no I mean my other one true love.”

So with those other strange bedfellows out of the way, we now turn our attention to a comparison of ASP.NET and Ruby on Rails from my point of view as a fellow without a firm entrenchment in either technology.  This isn’t meant to start or feed a language war because, as I say, I’m not passionately committed to either technology.  I do think that both environments offer a lot that’s good, and both have more than enough things that bug the heck out of me.  So this article quite simply is my list of what I like and don’t like about each environment.

What I Like About Ruby on Rails

  • Prototype
    Rails has excellent baked-in support for two great related JavaScript libraries — Prototype and Script.acul.us.  It’s about this hard to get started:
    <%= javascript_include_tag :defaults %>.  Well, OK, it’s a little harder than that, but I found that with Prototype’s beautiful documentation, I was able to go from zero to productive in a few hours.  What’s more, I actually found myself liking JavaScript for the first time since — oh, who am I kidding, I always hated it.  Prototype could change my mind, though.  I wrote something that started to look pretty good in Firefox, then fired up Internet Explorer fully expecting half the page to re-materialize in a particle accelerator in Switzerland.  But lo and behold, it worked the way it did in Firefox. You’re kidding, right?  JavaScript did that?

    But then I saw her face.  Now I’m a believer.
     

  • link_to_remote
    How easy can we make AJAX?  Does a single function call work for you?  It does for me.  Here’s a tip though from someone who knocked his head briefly against this wall:  unless you’re updating multiple DOM elements (and maybe even if you are), then forget about RJS.  Something in this format:  “your_response.html.erb” is your friend.
     
  • Lots of Other Stuff
    If you’re a Rails programmer, lest I lose the goodwill from the next section, let me say this first: overall, I think Ruby on Rails is the bee’s knees, or perhaps the cat’s pajamas.  Well, either way, it’s something cool that belongs to some critter. I’m not sure I can frame why exactly, but it’s a lot of fun to program in.  There’s something about the way it all fits together that’s very satisfying.

What I Don’t Like About Ruby on Rails

  • Smugness and Sleight of Hand
    Rails is an utterly cool framework, but that doesn’t mean that there aren’t parts of it that aren’t either smoke and mirrors or mere social gushiness.  For example, if you have a phrase that goes Don’t Repeat Yourself with the clever acronym of “DRY”, then you probably shouldn’t say it over and over and over and over and over again.  Honestly.  Shut up already.  Even Assembly Language had macros.  We get it.  Give it a REST already.  Oh, and speaking of REST, remember your other catch phrase, You Ain’t Going to Need It?  Well, guess what:  you still have sessions, and so regarding REST, you ain’t.
     
  • What, No Windows?
    Apparently Rails runs a lot better on Linux than it does on Windows.  I say apparently because I haven’t bitten the bullet yet to set up an Ubuntu partition, but it seems to be the gist of the literature.  I have no reason to doubt it given that as of a couple of weeks ago my no-model unit test framework (which at the time barely beat “Hello World” in terms of complexity) took 13 seconds to load and run.
     
  • You Call This Documentation?
    Unlike the Prototype documentation (which as I said, is beautiful), the documentation for Rails falls into two categories, as near as I can tell:

    • Web pages that link to things that aren’t there any more, as though the framework were trying to bury the competition beneath the sheer weight of 404 errors.
    • Function documentation that looks something like this:my_rails_function(object, gizmo, options = {}, html_options = {} )
      object:  some well defined object that the documentation describes in depth
      gizmo:  some gizmo that’s also pretty well defined but fairly self evident
      blah blah blah lorem ipsit dolor yada yada.

      Where’s the discussion of “options” and “html_options”, you ask?  If you’re lucky, they’re somewhere else on the same page, twenty lines down or under the discussion of some related function.  More likely they’re in the source.  Apparently if you’re a Rails programmer, a side benefit of saying Don’t Repeat Yourself over and over is having function parameters handled only in the source and not in the documentation.

So much for the pros and cons of Rails.  Let’s see if we can come up with some similar virtues and trash talk for Microsoft’s ASP.NET.

What I Like About ASP.NET

  • Visual Studio
    Visual Studio is a competent and mature Integrated Environment, with an outstanding debugger and great features such as code completion.  Now, before you say, “But John, Rails has that, too!”, I should point out that, yes, I tried out RubyMine (in Beta) and Aptana Studio, and so far I’m a bit underwhelmed.  Yes, Chris Williams was totally nice when I entered a bug wherein the code completion didn’t work, and he put a fix in for 1.3.0 within 24 hours of me entering it, and yes I appreciate that.  But 1.3 isn’t out yet, and in Visual Studio, it just works.  Admittedly, Microsoft’s tool has been around a lot longer, and yes, they have huge resources, the comparison is unfair, etc.  But if you’re going to lure me out of Visual SlickEdit and the command line, you’d better have great code completion and an awesome debugger, because otherwise I’m comfortable already.
     
  • MSDN
    Remember those missing options and html_options from the Rails doc?  Well, if I’m sitting at my keyboard, say “Go”, give me twenty seconds, and I’ll rattle off all the parameters for CreateWindowEx and what they mean, including acceptable values for multi-valued parameters.  The MSDN documentation for ASP.NET is as good as the Rails documentation is poor.
     
  • Jobs
    The last two times I looked, the number of jobs for ASP.NET developers was beating the number of jobs for Ruby on Rails developers by a factor of about 11 to 1.  If you look at the pyramid for Abraham Maslow’s hierarchy of needs, you’ll see that employment (in “Safety”), comes well before Esteem and Self-actualization.  The Beatles presciently wrote about the allure of Rails versus the hegemony of Microsoft thus:

    Your lovin’ gives me a thrill
    But your lovin’ don’t pay my bills.

  • NUnit
    What can I say.  I’m a tramp for cheap visual thrills.  I like to see the bar turn green.

What I Don’t Like About ASP.NET

  • High Cost of Ownership
    I mentioned jobs before, but in some respects this is a moot point or at least not the only point, since what I have discovered about myself long ago is that the guy I really like working and writing code for is me.  SQLServer and .NET hosting simply don’t have the same sorts of economies as the LAMP world, and I’m sure Rails is on a path to being that cost effective even if it’s not quite there yet.  Thus, to me much of the debate breaks down into a personal decision between entrepreneur versus employee.
     
  • Vendor Lock
    As slow as Rails is on Windows, as far as I know the only implementation to date of LINQ to SQL (which one might nickname “ActiveRecord for Microsfoties”) is against SQL Server.  Yes, it’s cool that LINQ works with native objects, XML, and SQL, but to date I haven’t yet needed to do a right outer join of my Employees table and my HttpRequest object, and I don’t anticipate that changing.
     
  • Their Model View Controller Support is a Disaster
    This may have changed since I last looked at it, but on my last ASP.NET contract they had an MVC implementation that completely broke browser navigation and was a nightmare to code to.  I’m not an MVC snob, so I’m quite happy with some pages and code behind talking to a well defined model interface if that’s how you want to do things.  However I do think that if you’re going to use the MVC pattern (or any other design pattern), it should work better than the absence of it does.  Rails forces MVC on you, but it works just fine.  MVC is an optional nightmare in ASP.NET, unless your manager is of that all too common variety that prefers buzzwords over common sense — in which case it becomes a required nightmare.

Thank you for hanging in there for this completely idiosyncratic view of some of the pros and cons of Ruby on Rails versus ASP.NET.  I’ve barely scratched the surface, I’m sure, but when it comes to language wars, that’s probably all one should do.  In my opinion, programming always represents a certain dynamic tension between “How cool is that?” and “Who’s cutting me a check this week?”  Go out and code something, folks.  What if they gave a language war and nobody came?

Posted in ASP.NET, Ruby on Rails | 4 Comments »