Archive

Archive for March, 2008

Weekly update

March 28, 2008 2 comments

I’m going to start off by saying that this is a totally lame post, but I resolved to post at least once a week, so here it is.

Site Change

Scott Hanselman had an interesting post this week that got me thinking about how I judge the success of this blog. Like he mentions, I check in on it several times a day. I like to see how traffic is faring, which pages and topics are getting the most interest, and as I’ve posted before I’m fascinated by the Search Terms that drive people here.

What interested me about Scott’s post is that he judges success by the number of comments and participation, not the traffic. I have to admit that I think he is right. I have always wanted to see more comments, questions, and discussion here, but even when I have asked for it there has been very little in the way of community participation. In a perfect world, this would be because I’m such a brilliant writer that people have no questions or arguments with my musings. Since we do not live in such a world, however, it is probably because my topics are too basic, mundane, obvious, or even down right boring.

But it could also be because people don’t want to register on yet another site. On other blogs I managed in the past, comment spam was a downright kill-joy, so I wanted to make sure that the comments people made were serious and real. To that end, I configured the site to require registration and log in before being allowed to post a comment, which, as of this writing, has been the only benefit of registration. I plan on changing this in the future, but for now it is a pretty weak reason to register, so I can easily believe (perhaps deluding myself in the process) that this may be one reason why comments are few and far between.

So, in Grand Announcement Fashion, I would like to say that registration is no longer required to post a comment. I have an appropriate Comment Spam plug-in enabled, so we’ll see just how bad it gets. If it becomes a problem, I can always go back to the original configuration. But for now, I’d like to ask for your help in testing the new configuration: just leave a comment, innocuous or otherwise, to this post.

ASP.NET MVC

I have spent the bulk of this week coding away at my new ASP.NET MVC web site, and I am still high as a kite over the project. I’m planning a couple of articles about some specific topics, but overall I feel as though I have finally found a way to integrate my traditional HTML control-freak issues with my C# and .Net skills. I spent a few days developing oodles of backend code, but the last couple of days have been a flurry of web page activity, and I can actually begin to see and feel the results. Next week will mostly be spent “prettyfying” the site and distributing it to our webserver.

Categories: Miscellaneous

ASP.NET MVC Source Code Released

March 21, 2008 Comments off

ScottGu has just announced the release of the ASP.NET MVC Source Code. You can download the code from CodePlex. It is important to note that this does not mean MVC will be open source (or that it won’t be), just that they are sharing the code during development so that we do not need to wait for their releases to correct bugs locally. So while you can create a custom implementation, you cannot distribute it, and I wouldn’t want to rely on it.

Categories: ASP.NET MVC

The Birth of the Cubicle

March 21, 2008 Comments off

According to Timm over at DevTopics, this year is the 40th anniversary of the much maligned cubicle. Since that time, cubicles have been reviled, scorned, berated, ridiculed, and generally hated. According to the article though, 70% of American office workers spend their work time in a cubicle. Other than spreading gossip, surfing the Internet, and drinking coffee, ANYTHING that so many Americans do at work every day is going to be hated.

I spent the first three years of my professional life in a Cube Farm. At the height of my employment, there were almost 800 of us crammed into the 5×5 boxes (or were they 4×4?) This particular company was a little different in that the cubes were not arranged in a grid, but rather at an angle. This meant that most of the cubes had open backs where you could easily roll out into the walk way. This had the benefit of feeling more open and promoting communication. On the downside, it was more open and promoted communication, most of which was inane and unnecessary.

Blissfully, I escaped such confines in 2000, and I’m typing this from my private office with the door closed. I am also blessed that we have a receptionist who actually screens my calls. Unfortunately the walls are paper thin, and even with the door closed I can hear the conversations of the two offices on either side of me, not to mention all the office chatter and ambient noise from the kitchen and the upstairs. *sigh*

The Zone

Timm also talks about getting in “the zone”, something to which most programmers can easily relate. All these minor complaints aside, when I get into the zone none of these distractions exist. I had two experiences just this week that perfectly illustrate this. I was testing some of the new ASP.NET MVC project I’ve been feverishly working on, and after a particularly rewarding success I did a little fist pump celebration (come on, you all know you’ve done it!) Immediately following, I literally jumped in surprise when I noticed someone sitting in one of the guest chairs by my desk. Apparently, one of the partners had come in, tried to get my attention, and failing to do so had patiently sat down to wait for me. I don’t know how long she had been there, but apparently it had been a little while.

Yesterday, a co-worker came to my office door (which I mistakenly had left open) and stood there for a moment. After waiting a few seconds for me to notice him, he asked if he could bother me for a moment. I said “no, not really”. He thought I was kidding and started talking about whatever issue it was he had. I gruffly stopped him and said “No, REALLY”. He then realized I was not kidding, apologized, and moved on. He apologized again this morning, and truthfully I had to think hard to even remember the incident. When you are in the zone, anything outside is unwelcome.

So what is the lesson in all this? Don’t mess with the zone, baby.

I think non-programmers really misunderstand the zone. Quality programming time is fleeting. Some days you have it, some days you don’t. Most of my days are a mix of the two: usually long hours of relative dormancy punctuated by brief periods of intense productivity. This is hard for a lot of people to understand or appreciate, especially non-technical managers of technical people. They see us reading, chatting, emailing, spending oodles of time on blogs and forums, etc., and to them we are just slacking or surfing the Internet. What they don’t get is that we can do a lot more in 2 hours of zone than in 8 hours of drudgery. Extended periods of zone will actually wear me out physically. I’ve had a few of those the last couple of weeks, where by 2pm I am just toast, but man have I done some serious coding!

Any programmer who has done this for a living for more than a month has come to truly cherish zone time. Zone time is gold. This is why we are so intolerant of interruptions. Some of us handle them more diplomatically than others (I had one mentor who would literally throw things at you until you left his cubicle), but we all share the same goal: prevent the loss of the zone. Once the zone is lost, who knows when it will return.

Wrapping it up

So what does the Zone have to do with the lowly cubicle? Well, Timm wants us to comment on our preference for offices or cubicles. For me, working in a cubicle and getting in the zone are almost mutually exclusive, especially in a busy place with a lot of distractions. You can certainly be distracted in an office, frequently by yourself. Truth be told, this blog is a bit of a distraction for me, as is keeping up with all the others I subscribe to. But I find outside interruptions (the phone notwithstanding) to be a lot fewer, especially when I shut my door.

One last thought: the zone is really what we get paid for. Sure, what we know and can do is important, but the zone is when we actually produce. Barry Bonds can hit Home Runs, but that isn’t why he gets paid: he gets paid because when he gets in the zone he actually hits them.

So jump on over to DevTopics and post your preference. You have time, you’re obviously not in the zone right now…

Categories: Miscellaneous

Using Object Initializers on Dictionary

March 13, 2008 2 comments

I’m still going strong on the ASP.NET MVC development, and I wanted to experiment with HtmlHelper.Select rather than hard coding specific values into my View. To that end, I am building a supporting class that will retain static properties (which I’m sure will be cached once I figure out how to do that). Some of these properties are lists of information, like product types and prices, that could be fed from a database table. Others may be static lists with the potential to become database driven, like state codes and names. Ultimately, where they come from does not matter, but in my coding today I came across something interesting.

To begin this process, I decided to populate a static Dictionary<string, string> with a list of codes and values. This is a small list, so for initial testing I just wanted to hard code the values. It has become a habit for me to use Object Initializers whenever possible, so naturally this seemed a perfect fit. But let me ask you: have you ever tried this? I have to admit that at first I was a little stumped. I first tried to build a method tree (a concept that really doesn’t exist in C#):

BusinessTypes = new Dictionary<string, string>()
.Add("APP", "Appraisal")
.Add("GOV", "Government")
.Add("INS", "Insurance")
.Add("LAW", "Legal")
.Add("LEN", "Lending")
.Add("REL", "Real Estate")
.Add("RES", "Research")
.Add("OTH", "Other");

Even though I didn’t really expect this to work, I thought it would be interesting to see what happened. [This could be a good candidate for a future language enhancement.] Naturally it failed, but in an unexpected fashion. The first call to .Add passed the compiler, but the second call to .Add threw the following error:

Operator ‘.’ cannot be applied to operand of type ‘void’

I also tried adding the method call inside the Initializer block, but since you can’t put method calls inside of Initializer blocks I pretty much knew that wouldn’t work either.

So I looked at it some more and asked myself “what is the Dictionary looking for?” My answer was “a KeyValuePair”, so I tried that next:

BusinessTypes = new Dictionary()
{
    new payday us fast cash loan,fast cash payday loancash till payday loan,cash loan payday,advance cash cash loan payday paydayloan oneclickcash paydaycash fast loan paydaycash advance loan illinois,5 advance cash illinois loanfull pay video pokerbest video pokerinternet casino craps,internet casino,internet casino gambling gamefree online casino gamblingduces wild video pokercasino link online suggestno deposit bonus online casino,free online gambling casino bonus,online casino bonusplay blackjack online freefree video poker gamescraps free online play,casino craps free gambling online,free online crapsfree online casino,online casino,top online casinoplaying blackjackplay free casinofree casino cash bonus,casino cash,free cash casinofree video poker gamereal money backgammonplay roulette onlinefree casino moneytriple play video pokerfree roulette,free roulette download,play free rouletteroulette gambling,best gambling online roulette,online roulette gamblingplay black jack online freeonline gambling casino,gambling casino online bonus,free online casino gamblingcasino download,free online casino download,download online casino gamemicrogaming casino bonusbaccarat card game,baccarat game,baccarat the internet casino gamecasino no deposit bonus code,online casino sign up bonus,casino bonusvideo poker for winnersvideo poker strategy,free video poker,video pokerkeno gameplay slots,play for fun online slots,free slots play for freecraps rulesplay free slots,free slots,free online slots gameinternational online casinovideo poker machineshand held video pokercraps gambling strategy,craps gambling game,gambling crapsbest casino bonus888 black jackfree online slots no download,no download free slots game,free slots no downloadblack jack downloadplay casino game onlinetournament backgammon888 poker,888 poker info,888 poker tournamentbest online casino bonus KeyValuePair<string, string>("APP", "Appraisal"),
    new KeyValuePair<string, string>("GOV", "Government"),
    new KeyValuePair<string, string>("INS", "Insurance"),
    new KeyValuePair<string, string>("LAW", "Legal"),
    new KeyValuePair<string, string>("LEN", "Lending"),
    new KeyValuePair<string, string>("REL", "Real Estate"),
    new KeyValuePair<string, string>("RES", "Research"),
    new KeyValuePair<string, string>("OTH", "Other")
};

That also threw an error:

No overload for method ‘Add’ takes ‘1’ arguments

But the error pointed me back to my original idea: somehow I needed to use Add(), but how? And then it dawned on me: what the message is really telling me is that I was already using Add(), I just didn’t realize it! Since we use curly braces to denote Initializers, I decided to try that within the context of the parent Initializer to send parmameters to the Add method:

BusinessTypes = new Dictionary<string, string>()
{
    {"APP", "Appraisal"},
    {"GOV", "Government"},
    {"INS", "Insurance"},
    {"LAW", "Legal"},
    {"LEN", "Lending"},
    {"REL", "Real Estate"},
    {"RES", "Research"},
    {"OTH", "Other"}
};

This compiles fine and now I have successfully used an Object Initializer on a Dictionary<TKey, TValue> object. I was curious about why this works, so I hit the Google pavement and found this article on MSDN from October of 2006. In it, the author has this to say:

Our resolution to this is to refine our understanding of collection initializers a little bit. The list you provide is not a ?list of elements to add?, but a ?list of sets of arguments to Add methods?. If an entry in the list consists of multiple arguments to an Add method, these are enclosed in { curly braces }. This is actually immensely useful. For example, it allows you to Add key/value pairs to a dictionary, something we have had a number of requests for as a separate feature.

From previous text in the article, we find that any IEnumerable with a public Add method will behave this way. As such, we should be able to use this construct in almost all the generic Collection classes.

This is definitely useful, and yes I should have searched for a solution before I spent the entire 3 minutes trying to figure it out. But sometimes, I just like solving the puzzle.

Categories: .NET 3.5, C# 3.0

Sitepoint's new HTML Reference

March 12, 2008 Comments off

I recently blogged about SitePoint.com releasing its CSS Reference. Today, they released the next great addition to their online reference material, the HTML Reference.

Again, I am impressed by their offering.? It is clean, well thought out, and easy to use.? It is also pretty neat to look at the source code for it: a good model of simple and unencumbered HTML.? The developers at SitePoint really know their stuff!

If you have been following the blog recently, you’ll know that I am very much a nuts and bolts guy when it comes to developing web sites (hence my recent love affair with ASP.NET MVC).? Even so, I frequently forget details when it comes to obscure HTML tags and attributes.? Intellisense support in VS2008 for HTML has been a real help, but you still have to know what the intended results should be. To that end, I expect that I will be visiting this new reference many times.? If you have to write, read, or understand HTML,this resource should definitely be in your library.

Categories: Web Development

ASP.NET MVC Wish List

March 10, 2008 4 comments

Last Updated 03/12/2008

This morning I watched a video from Mix08 of Scott Hanselman’s session on ASP.NET MVC. I enjoyed the presentation, although I’m sure I will have to watch it several more times. The Routing capabilities are phenomenal but they will take a little while to get my head around. For now, the default Routing mechanism should suit my purposes just fine. I can also see that I am going to have to learn about Unit Testing, so that (in Scott’s own words), I don’t “suck”.

I have been developing a site using the new MVC approach, and overall I ahve to say I finally feel right at home in ASP.NET. I still get all the C# and Framework goodness I am used to, but I can now do it in the close-to-the-HTML way that I am familiar with. Let’s face it, until ASP.NET, WordPad was my web IDE of choice.

In the video, Scott asks us to blog and post about what we would like to see done differently in MVC, so that is the purpose of this post. I will use it as a running tally of my MVC Wish List. My first item was addressed in Scott’s presentation: I wanted the ability to route all non-conforming traffic to a default page rather than relying on the web server configuration and 404 files, and all that ugliness. Well, apparently you can already do this by declaring a *catchall Route. When I figure out the mechanics of this I will try to post a sample.

The Wish List:

1. Make UrlHelper.Action() Static

Make appropriate UrlHelper methods (and probably also HtmlHelper) available in a static context. I wanted to add standard navigation to my page in my custom MasterPage, but I could not use the Url.Action( action, controller) method because at that point there is no ViewPage instantiated. I think this would provide a uniform approach to Url writing.

2. Supply a pre-action Controller Event – added 3/11/2008

I think it would be great to have a generic event (or maybe a partial method?) that would execute before the controller begins the action method. This behavior could be simulated now, but each action would need to explicitly call the method. Implementing it this way would ensure that it was executed every time the controller was called. I think this could be great for things like caching, session management, security, logging, etc.

Update: Scott commented below about a possible solution to this already in place. I don’t think it is exactly what I had in mind, but I will experiment with it when I can and report back.

3. Add a TableRow method to HtmlHelper added 3/12/2008

I’ve been playing with Html.Form<T> and BindingHelperExtensions.UpdateFrom for building and processing form elements. I think both of these are very cool, and I will be posting about them shortly. Since Form elements are frequently presented in a Table, it would be good to have something like Html.TableRow<T>(inputType, label, T.Property) [obviously this is psuedo-code] that would create a simple table row based on the property with two elements:

<tr>
  <td>label</td>
  <td><input type="text" name="Property.Name"
    value="Property.Value"></td>
</tr>

The main benefit of this would be automatically generating the correct property name, so that it lined up perfectly with the UpdateFrom functionality. Another benefit would be to have it automatically populate the Value attribute with the current value of the Property. InputType above would ideally be able to accept the results of Form.Select, Form.Textbox, etc., or could be overloaded with an enum and some additional parameters.

OK, so that is the short (and boring) list for now. As I get further into the project, I’m sure I will find more, but as of now I have a lot more to rave about than to complain about. Keep up the great work fellas!

Categories: ASP.NET MVC

ASP.NET MVC Preview 2 Released

March 6, 2008 Comments off

In another case of DGT (Darn Good Timing), in my inbox this morning was my copy of theToques 3320 baixar toques para celular Gratis, toques. Developer Fusion Community Newsletter, and the first item was this announcement. Being a very recent fan of the project, I immediately downloaded and installed the new Preview.? Here are the Release Notes. There are a few breaking changes, mostly object renames, but a little refactoring should take care of the bulk of it.

I spent some time yesterday playing around with it, and I am very happy with what I see. I plan to spend most of today reading Scott Guthrie’s excellent Tutorials.

ASP.NET MVC

March 5, 2008 Comments off

As I posted previously, I’ve been struggling with ASP.NET.? Over the last couple of weeks, I’ve come to acknowledge that at the heart of my struggles is a failure to grasp the logic behind the ASP.NET approach. Of course, begin constantly bitten by newbie bugs is very disheartening for someone with almost ten years of web development, but I have tried to put my pride aside and just come to grips with it. This has been increasingly difficult to do as my frustrations mount, although finding the Wizard control alleviated some of it.

I have been in the process of learning about Data Caching in ASP.NET, which I think will address one of my (many) concerns, but such study requires frequent breaks, during which I usually read some other technical information. It was during one of these breaks yesterday that I picked up the Jan/Feb issue of CoDe: Component Developr Magazine, and doing so may have saved my relationship with ASP.NET.? In it, I came across an article by Jeffrey Palermo entitled “Use the ASP.NET MVC Framework to Write Web Apps without Viewstate or Postbacks” – Note to Jeffrey: bloggers like short titles!? The two page article made me sit up and take notice, and I spent the rest of the day researching ASP.NET MVC.? Championed by none other than Scott Guthrie (ScottGu to his readers), ASP.NET MVC is part of the ASP.NET 3.5 Extensions project hosted at asp.net.? This project was recently released as a CTP and is now available for download.? You can get lots more information about it at Scott’s blog.

By freeing ourselves from the mantra of the PostBack, this MVC approach returns us to real HTML control, without the need to wrap all the content in a runat=server form.? This means you can finally put regular HTML forms on your pages. And best of all, you can still use all the ASP.NET goodies, just in a better architecture: Master Pages, ASP Controls, Code Behind, the works.

Downloading and installing the Extensions CTPwas a snap.? Naturally, it integrates with VS2008, so once it is installed you will see some new project types, a couple of which are MVC specific. Selecting one of these project types will create a project with all the plumbing in place and wired, which I immediately found intuitive and well designed. There are several extra, but well documented, steps you must go through if you wish to add MVC to an existing project, but since I don’t really have any of consequence this was not an issue for me.

Hopefully, this afternoon I will find more time to delve into this further.? I can say that I am very excited by this development.? I can finally do things with ASP.NET that are familiar and comfortable.? Projects like this could easily increase ASP.NET adoption and proliferation. My enthusiastic thanks go to all those involved!

Visual Studio 2008 Setup Project Frustrations

March 4, 2008 28 comments

I have not needed to create a Setup project since installing VS2008, but this afternoon I needed to share a utility program with a coworker friend of mine (who is not technical), so I opened the solution and added a Setup and Deployment project. Everything seemed to be fine. I added the primary output of my application’s project and adjusted the company name and product name properties, as well as some other settings, just like I used to do in VS2005.

The problem occurred when I wanted to create Start Menu and Desktop shortcuts for the application. In VS2005, double clicking the Application Folder would show you the list of DLLs, EXEs, and other files that would be installed. You could right-click the main project output file and create a shortcut to the program, which could then be copied to the User’s Desktop and User’s Program Menu directories. And you could also add icons and assign them to the shortcuts.

This was what I wanted to do in VS2008, but double clicking on the folders in File System does nothing. As a result, you cannot select the output file as instructed in the MSDN documentation. This is very frustrating: the Setup and Deployment project has always worked well for me (these are internal distribution installers), but now with VS2008 it no longer appears to function properly. The resulting MSI did work and did install the software, but without an icon and without shortcuts in the desired locations.

If you know the solution for this, please leave a comment. If I find a solution to this, I’ll be sure to share it. For now, all I can do is share the pain.