Evil Exception HandlingPosted on October 29, 2008Grrrrrrrrrrrrrrr..........here's what I started this morning with(click to enlarge): Can anyone spot the exception? the real exception? Ya, me neither, I have no clue what happened because of these lines: After commenting out the exception squishing code above and rebuilding, here are the images of the results I see now(I cut the screen shot into two because it was too big for one). Now can you spot the actual problem? The problem was simple, my local copy of the database for this app is out of date, I just need to update. But to figure this out I had to crack open the solution, comment out lines of code that added zero value(actually reduced value), rebuild and then see the issue. Frustrating. The Downside of Anonymous Types As ArgumentsPosted on October 25, 2008So far the only gotchya in upgrading to ASP.NET Beta was Html.TextBox. It used to have this signature:
and now it has this signature
notice anything? Yep, now that object means something different, so my calls that looked like this:
started rendering this
apparently I need better testing coverage, cuz you won't catch those at compile time. Testing JsonResults in ASP.NET MVCPosted on October 23, 2008I needed a way to test values in a JsonResult to verify an action was behaving properly. In my action i return something like this:
So in my test for the Action i need to verify the values of success and message but they're in an anonymous type so I need to pluck out the values. That's where this extension method comes into play:
Now in my test I can do stuff like this:
Pretty cool, huh? Finally, Notebooks with 3+ GHz processorsPosted on October 23, 2008Well specifically thinkpads. I'm liking where the W series is going. 17 inch monitor, which I'm still on the fence. 1 gig dedicated frickin video card. And now you can get a 64 gig SSD as the primary and a zippy 7200rpm secondary drive. Now, if only I could get it all for half of the price....or win the lottery. My only request is that Windows 7 ships before I get stuck upgrading to Vista.. Check out the specs: Optional Parameters In JavaScriptPosted on October 20, 2008I've found more and more uses for the optional parameters in javascript. I have no idea if there's an actual name for this other than optional parameters, so i'm goin with it. jQuery and prototype and I'm sure most if not all of the other cool "web 2.0" libraries have a way of extending objects and have had these methods for a long time, so this is nothing new, I just am now finding more uses for it. It usually entails copying the properties of one object over the properties of another. I wrote a stand alone function copied from prototype's Object.extend implementation that looks like this:
So let's say I have a function that has has 3 possible values that can be passed into it. Most of the time I see methods like this:
The problem with this method is that all of params are required and none of them have default values. Another way is using the built in arguments object (description taken from the ecmascript spec here-it's a pdf) like this:
This accounts for not passing in all of the parameters and getting some default behavior, but they are based on position. So in order to override the title, you'd need to pass in values for the first two params. Optional Params Using extend
Using the extend method now, we can call the above method with any, all, or none of the parameters like this:
Here's a little test page that exercises this stuff: DefaultParams.htm ASP.NET MVC Beta Source Code Is Posted On CodePlexPosted on October 20, 2008Yay, i was downloader number 7! Get it here. Politics And MoneyPosted on October 19, 2008Are You Fucking Kidding Me?I'm usually not into politics, actually almost never. Sadly, this is the first year I am voting. I do not support Obama. I just don't want the old white guy to make it(gee, guess who I'm voting for). However, today I realized why I don't like either candidate. Apparently Mr. Obama raised 150 million in September. According to the article, it puts Obama at 605 million bucks raised for his campaign so far. Let me repeat...605 MILLION DOLLARS. Wouldn't The Best Candidate Be The One...... who could do the most with the least? I'll prolly never go to a democratic or republican convention. Why not? Better question: why? There's absolutely nothing one of those conventions can provide me or anyone else that will affect the way I feel about either candidate or party. Nada. Zip. They do one thing, waste money. Sure, they "create jobs"...for a week, but how bout taking that money and pouring it into something like schools or hospitals or something useful? I'll prolly never go to a political fund raising dinner either, because I don't have any money I feel like lighting on fire and wasting. Candidates, don't tell me how you're gonna fix the economy, show me by running the slimmest campaign, not the fattest. Don't Mess With My TV ScheduleThis one pisses me off the most. Stop putting those debates on TV. At least not on the weekends, or Monday through Friday, between the hours of 5am and midnight. Seriously, put that shit on YouTube, NBC, or somewhere online, and only the highlights please. Internet DebateWhat would that take? An internet debate, online, realtime, open to anyone and everyone on earth to ask questions. Put one candidate in one booth, the other in his booth, they don't need to see each other, and a host who can see both. You'll need bandwidth(nbc could donate that), the host to ask the questions, and one of us geeks to run the internet show, and a small handful of people to screen questions. Done. How much would that cost? 605 million? Nope, not even close. The candidates are free, right? they sure as hell don't(shouldn't) get paid for this shit. The host(I vote for John Stewart) would do it for free as well, it's an honor and a service for the country right? Bandwidth isn't free, but that's where well placed commercials come in, kinda like how NBC does it now.
OK. I'm done. I Heart Balsamiq MockupsPosted on October 5, 2008This post is a little info on how I went about coming up with a design for a winform app I'm building. OK. I still use paper. This is what I started with today(very bad quality photo of paper): Although simple, it took me awhile to figure out where to start on the UI. Once this was on paper, I had a better idea of where I wanted to start with Balsamiq Mockups. After a pretty short amount of time(like maybe 30 minutes), I came up with this(click to enlarge): I spent very little time in the winform designer once i mocked up what I wanted. I ended up with this as a first cut: Part 2: Test Driven Development In PracticePosted on October 3, 2008OK. Here's part 2 of the TDD in practice dealio. I decided a screencast would be appropriate. I'm just getting over a cold so my voice is shot, this is a silent movie. In part 1 I typed in code that I want, to solve my problem. Most of the code did not exist. So in part 2, we need to create everything that's missing and make the test pass. Play the video to see how I did it(I used all CodeRush features to generate code - with a little manual intervention; but most of this can also be done with raw Visual Studio shortcuts). Part 1: Test Driven Development In PracticePosted on October 3, 2008Ok, so I've been meaning to do a screencast on this, i've done one but it's lame. I figured I'd do more a photo slash journal-ish type thing and describe my real world(yes this is for an actual project) usage of TDD. So here goes, I just typed the following into my test, this is what I want to do: And that's pretty much it. Notice the red squiggly lines? Yep, I haven't created that stuff yet, cuz this is what I want to do, not what I've done. Next part will be making those red lines go away... Muppet F*ckerPosted on October 3, 2008That's one of the funniest terms I've heard in awhile. I heard it during the brilliant presentation by Giles Bowkett recorded at RubyFringe. IModelBinder with AutoBinderPosted on October 2, 2008Today I noticed this post on the ModelBinder attribute that ships with Preview 5 of ASP.NET MVC. I looked at the example and it doesn't make any sense. I had come up with something I call AutoBinder and until today didn't think it was anything worth mentioning. I could swear I saw somewhere that something like this would be included in the RTM of MVC but I can't remember where I saw that. IModelBinderIModelBinder is a simple interface with one method to implement, it looks like this:
AutoBinderAutoBinder simply implements that interface like this:
And AutoBinder.UpdateFrom looks like this:
Using AutoBinderUsing this requires either registering the types with their appropriate binder at app startup or adorning your models with the ModelBuilder attribute like so:
Now in a controller we might have a method that looks like this:
Assuming that all of the fields on the form have the same name attribute as the properties on the model, the customer arg will be mapped up with the posted form values automagically through the ModelBinder attribute. Anyway, here's the spectacular example: ModelBinder.zip. It assumes that you have Preview 5 of ASP.NET MVC installed. |
Loading...
|