May 26, 2008

Hello World 2.0

The new standard starter project for any web-based code library is creating a Flickr gallery widget. It’s Hello World 2.0.

April 19, 2008

Creating Partial Views in ASP.Net MVC

Filed under: HowTo, DotNet, Development, ASP.Net MVC | Lindsay @ 6:56 pm

I have been coming up to speed with ASP.Net MVC recently and I have to say that it makes me very happy, warm and fuzzy. I had been out of the Microsoft camp of web development for almost a year and a half and using Ruby on Rails in the mean time. Now that I’m “back in the saddle again” with Microsoft technologies, I’m ecstatic that I can use ASP.Net without WebForms, Postbacks and ViewState. The MVC framework is so much cleaner and easier to follow in my opinion. Yeah, it might not be popular with a lot of ASP.Net developers because you have to do more HTML from “scratch” and don’t have the crutch of server controls but that gives you so much more control over what’s going on and takes the “magic” out of it. And it’s also much easier to test (TDD, baby!) and debug when you really understand what’s going on under the hood because you wrote the engine.

So anyway, I’m playing with ASP.Net MVC which is still only in a “Preview 2“, meaning there’s lots more to come. But I want to use it now and there was some functionality missing that I really wanted: the ability to render a view in a view, basically to have the ability to do a Rails-style partial view. I figured out a way to do it by creating an extension on the ViewPage class, though there’s a bit of a hack involving getting the view directory route.

using System;
using System.Linq.Expressions;
using System.Web.Mvc;

namespace Lindsay
{
        public static class Extensions
        {
                public static void RenderPartial<T>(this ViewPage vwp, Expression<Action<T>> action) where T : Controller
                {
                    T controller = Activator.CreateInstance<T>();
                    System.Web.Routing.RouteData rd = new System.Web.Routing.RouteData();
                    // must include the controller name without "Controller" to match
                    // the Views subfolder name there has to be a cleaner way to do this…
                    string viewFolderName = controller.GetType().Name.Replace(“Controller”, “”);
                    rd.Values.Add(“Controller”,viewFolderName);
                    controller.ControllerContext = new ControllerContext(new RequestContext(vwp.ViewContext.HttpContext, rd), controller) ;
                    var ex = action.Compile();
                    ex.Invoke(controller);
                }
        }
}

I know there’s probably a way to use ViewLocator, or maybe some way to figure out which route to use and avoid the controller name hack but I haven’t been able to do that yet and this works for my standard circumstances. If anyone knows a better way please let me know!

To use this, put the code above in it’s own class and then use the namespace in your view to call it from. The call should look similar to this:

<% @Import Namespace=“Lindsay” %>
<% @Import Namespace=“MyMVCApp.Controllers” %>

<div>
         <% this.RenderPartial<MyController>((mc => mc.MyAction(myData))); %>
</div>

Partials are a hotly debated topic, but personally, I don’t see how you can really create an Ajax website without them. There is an implementation of “View Components” using ComponentControllers in the current ASP.Net MVC, but it requires you to use a specialized controller and also put your views in a special folder structure. I want to keep my controller code for an entity in one controller as well as all my views in one place and be able to use them as pieces of a page (through Ajax) or a whole page if I prefer. Creating the RenderPartial extension does that for me. Maybe someone else will find it useful as well.

In the spirit of full disclosure: I had the idea to create this extension when I found this solution to fix a bug with RenderComponent. Ironically, modifying that for RenderPartial allowed me to no longer have to use my view components!

» » » »
, , ,

May 24, 2006

It’s a Fugture!

Filed under: Development, My Life, General Geekiness | Lindsay @ 9:44 am

Yesterday a friend of mine coined a new term that will be one of my favorite words for a while. I was doing some testing of a functional area of the website we’re working on and found some unexpected behavior that at first I thought was a bug but on more thought, and realizing that it had some benefits, determined it might actually be a feature that we just didn’t document very well for the user.

I IMed my friend who’s managing the project and explained my thoughts…

Friend: interesting… what’s the cross between a bug and a feature? beature? fugture?
Lindsay: heh.
Lindsay: I like fugture
Lindsay: or fug for short :)
Lindsay: beature is too much like beautiful… and a fugture is anything but beautiful!!

So it’s all Fugtures now, baby!

New terminology can make old problems into their own solutions! Instead of spending hours working out the fixes for the mile long list of change requests you inherited with maintaining someone else’s old code, just tell the client that it’s fine the way it is…call it Fugture-Rich!

Too bad it doesn’t really work that way… oh well, back to searching for some more fugs to squash.

» » » » » » » »
, , , , , , ,

May 15, 2006

Technical Interview 2.0

Filed under: Development, Brainstorm, General Geekiness | Lindsay @ 2:27 pm

I read a great article by Kathy Sierra of “Creating Passionate Users” fame this morning. She brought up the point of how glib talking people usually get their way more often then their less-articulate counterparts. While it is not always true that the fast-talkers are wrong, the problem comes in when the deep-thinkers are overlooked when they might be right.

Kathy’s article was in the context of making business decisions, having meetings about development issues and deciding on a course of action. But the discussion made me think about another conversation I had recently with a developer friend about interviews for development jobs.

It seems as if technical interviews are definitely stacked in favor of the glib. Considering the fact that many of the best developers (at least in my experience) are often the introverts and don’t like to rush into things headfirst, they are at a disservice with the typical method of interviewing.

It usually goes like this:

  • You get the “Tech Screen”: a 30-45 minute phone barrage of very specific (to the point of “Trivial Pursuit”) questions on code syntax, platform terminology and even IDE menu options. Under pressure, its often difficult to recall that kind of information, and questionable whether much of it is worth knowing off the top of your head. That’s what Google, intellisense and your ability to point and click are for. Frankly, I’d be suspicious of people who do know the name of the 3rd item under the Tools->Debug menu as either being obsessive compulsive or “cheating”. And just because you do know all of the trivia doesn’t mean you have problem solving skills.
  • If you can get past that stage you’re typically brought in to interview in a conference room with one or more people warily (or wearily, depending on how many interviews they’ve already done that day) staring at you from across the table who briefly explain some super difficult business problem that has plagued them for several years and expect you to come up with a watertight solution with about 10 seconds of forethought. Either that or you get the “Mensa from hell” type of “logic” problems involving gas stations and blenders that you may or may not have the worldly experience to figure out in the limited amount of time you have to spit out your answer. Cross your fingers, turn on the glib and buzzwords and hope your stream of consciousness answer is somewhat acceptable.

It’s amazing that any introvert developers get hired!

A developer’s job is about solving problems, but not instantly. Its about learning new technologies and methodologies to solve those problems if you don’t already have the appropriate knowledge. Its about becoming aware of your environment and working within those constraints. And its about efficiency: using whatever tools you can find to save you time, reusing things you and other people have developed to keep you from reinventing the wheel and leveraging whatever knowledge resources (search, books, friends) you have available to you to get the job done. But all of that takes time, and those skills are not accurately measured in the typical kinds of interviews that I and other developers I know have been exposed to (or given!).

Wouldn’t it make more sense if you were given a set of reasonable project requirements with the tools and environment you’d be using at your potential employer (see virtualization) and access to whatever personal tools you’d use if you were working there (ie, internet access, IM, phone, your library of code snippets, your favorite books), and allowed to take 8-24 hours to complete the project to the best of your ability. Then your potential employer could review your work and call you in for a code review so you could justify your choices. Someone who got through that process in good standing would stand a lot better chance of being successful in your company in the long run. It would give people a chance to be judged on what they DO and not what they SAY. And it would get rid of the fast-talking BSers.

“But what if you had your buddy code the whole thing for you?”, the interviewers might say. It doesn’t really matter if the code review process is implemented well. Since one more aspect of development is to be able to understand code that other people write, its still an appropriate test of someone’s ability. Who cares if you really wrote it if you can step through each part and thoroughly explain it to the interviewer’s satisfaction. If there’s still a question of aptitude, the interviewee could expand some functionality during the course of the interview. I have a whole network of developer friends with different areas of expertise that I call on when I need help with some concept I haven’t had to deal with before. And they call on me when I have knowledge that they need as well. We share code snippets all the time. It’s another tool. It’s another method. It’s just part of being a good developer. But in the end it’s all about whether the interviewee really understand the code that they’re presenting. If they didn’t write it this time but they understand and can explain it, they’ll be able to write it next time.

I would rather have someone come onboard at my company who had already demonstrated their capability with problems similar to what they will be expected to work with in my environment than take the chance that the silver-tounged person who knew all the answers can’t produce. That’s the risk you take with the standard tech interview process that’s all based on talk. Time for a newer approach!

» » » » » » » » » » »
, , , , , , , , , ,

May 12, 2006

Dabble DB: All the cool kids are doing it…

Filed under: Development, Reviews | Lindsay @ 9:52 pm

A few weeks ago I got a beta invite to Dabble DB. I tried it out and I was simply blown away. I haven’t been so impressed with the comprehensive usefulness and ease of use of an online application in a long time.

Its so easy that my nine year old son, Avynn, was able to create a database to track his test scores for the Accelerated Reader (AR) program at school with minimal assistance from me after we had a 15 minute conversation about what a database is. He created a table (termed a Category in Dabble) of books and one of his AR test scores, set up the relationship between the tables and created a view that grouped and totaled the results by quarter (displayed below). It took us about 45 minutes to build including the painfully slow data entry skills of a third grade typist!

Avynn's AR Database on Dabble

I had already played with Dabble DB for a while before the experiment with my son and managed to create a database application to maintain a customer database for a friend of mine with 6 tables each with relationships, some with more than 1 per table, and 11 views with grouping and aggregation in under 4 hours. It’s something that my friend would easily be able to make immediate use of and easily add any missing data fields and relationships. The orientation, learning curve and jotting notes for feedback took up the majority of the time I spent on it. I could easily recreate the entire application in about 1.5 hours if I needed to do it again. I was amazed at how easy it was.

Here’s part of the email I sent back to the developers (Avi Bryant and Andrew Catton) after that project:

First I want to say thanks for the invite! And second I want to say OH MY GOSH this is an awesome application! I am so very impressed. And I’ve beta tested a lot of things. This is the most useful, functional and well thought out beta I have seen maybe ever, especially among the class of app it is. Relational databases are not easy things to create and maintain, but you guys have done a really excellent job making it simple, quick and even fun (in an extremely nerdy way)!

I’ve been playing with it for a few hours today, setting up a project that I’ve had in mind to do for a friend of mine and I’m amazed at what I have after my relatively small amount of effort. During the whole experience, I kept saying, “well, X is cool, but I wish it could just do Y… that would make it even better.”, and to my amazement, after poking around a few minutes more, I’d find that I can do Y!! I started out with a big list of enhancements and by the time I was done whittling out the stuff that was there anyway, I’ve only got 5! You guys rock!

Dabble DB came out of beta last week and I think that it is a great alternative to anyone who’s now using more than one Microsoft Excel spreadsheet or a Microsoft Access database to keep track of their information. Dabble DB is friendly enough that anyone who can handle creating a spreadsheet and certainly someone who’s using an Access database can easily set up their own Dabble applications. Heck, if my son can do it, then just about anyone can! No longer will small business owners need to rely on their brother-in-law’s programmer friend to set up a small database for them. As one of those potential programmer friends, that’s probably not good news for me wanting to pick up some side work, but oh well, more time for my own pet projects. Of course Avynn’s leet database services are for hire if you need them after all!

» » » » » » » »
, , , , , , ,

December 28, 2005

I want to go!!!!

The Future of Web Apps: “One-day conference focusing on the development technology you’ll be using tomorrow.”

… sigh. Too bad I don’t live in London! :(

December 21, 2005

How to configure WordPress on an IIS 6.0 shared host

Filed under: HowTo, WordPress, Development, Systems Engineering, Configuration | Lindsay @ 11:10 am

I have a confession to make. Linux intimidates me. And I am also afraid of using a hosting service other than my favorite, Crystal Tech, because they have given me outstanding service for more than 6 years. So when I decided that I wanted to start blogging again and was convinced that WordPress was the best option, I knew that I needed to find a way to make it work on my account at Crystal Tech.

(more…)

» » » » » » » » » » » » » »
, , , , , , , , , , , , ,