August 2007 Blog Posts

Tips for Non-Programmers Who Want to Learn to Program

Shout at the Devil!I have a pretty diverse group of friends, some of whom are developers and some of whom aren't.  A subset of the non-developer folks have, at times, mentioned to me that they really want to learn how to program but:

  • They don't have a computer background.
  • They fear it takes a long time to learn how to do anything good.
  • They don't have time to go to school.
  • They don't want to read thousands of pages worth of books before writing code.
  • They're intimidated by the seeming complexity of programming.

There are plenty of people out there who are self-taught programmers.  For non-developers who want to learn, don't be discouraged.  Here are my recommendations for people in this situation:

  • Start small.  Don't try to build a 3D rendering engine as your first program.  Don't try to build an RSS reader as your first program.  Don't try to build a screen saver as your first program.  Instead, pick a small task that you do all the time and automate that.  Maybe once a week you copy last week's status report and rename it to something new so you can start this week's status report.  Maybe you manually read through a text file and summarize a report out of it every day.  Pick something small and repetitive to automate as your first task.
  • Avoid GUI programming.  There are lots of great WYSIWYG tools out there for dragging buttons onto forms and having cool things happen, but these tools mask a lot of the goings-on from the developer and that's not always a good thing.  If things work perfectly, no problem.  If they don't... well, it can be a frustrating experience for the newbie.  Write something that runs at a command line so you won't have to deal with the windowing environment.
  • Keep focused on your task.  Your first program that prints something to the screen is referred to as a "Hello World" program (because, classically, the first line it prints is "Hello World").  Do your "Hello World" and then get back to the task you chose to do.  Why?  Having a task to accomplish is a milestone.  If you're just tinkering around in "Hello World" land, it's hard to really see any results or feel fulfilled that you're learning anything.  That's discouraging and I've seen several folks just give up because they didn't feel like they were getting anywhere.
  • Use a scripting language.  You probably shouldn't try your first program in C++ when there are so many far easier languages to use to accomplish simple tasks.  I'd look at VBScript, batch scripting, AppleScript, or some other simple, high-level scripting language of your choice.  (HTML is not a programming language, so don't pick that.)
  • Take online tutorials and do the exercises.  There are several free online resources to learn how to do simple scripting.  Take advantage of them.  When you see code examples or exercises in these tutorials, do them.  There's nothing quite like actually doing it to help you understand.
  • Get a tutorial book and a reference book.  Once you've picked a language (most likely after you've done one or two of the online tutorials) go to your local bookstore and pick up a tutorial book and a reference book on your chosen language.  The tutorial book will teach you how to do simple things in your language and will have a title like "Learn BlahBlah In A Week."  Tutorial books are good to augment the online tutorials you find out there.  The reference book will help you as you're working so if you need to look up what all of the options are for a certain thing, it's right there.  When you're starting out, a book might easier to deal with than trying to coordinate online help and your script across multiple windows/monitors.
  • Don't get overwhelmed and don't give up.  Programming isn't slam-dunk easy.  If it was, there'd be a lot of programmers out of jobs.  Don't let yourself get overwhelmed by your efforts.  If you find that it's becoming so overwhelming that it's not fun anymore and you don't feel like you're making any progress, maybe you picked a task that was too difficult.  Instead of giving up, pick a smaller task or maybe break the task you're trying to automate down into smaller sub-tasks and solve each one independently.  For example, if you're copying and renaming a file and that's too hard, maybe just do the copy part first and handle the renaming after you get the first part down.

For the developers out there, what do you tell people who ask you how to start learning to program?

How Do You Test Thread Safety?

I'm all about testing.  I do my best to adhere to test-driven development (though, admittedly, sometimes that's hard when you're doing some experimental work just to see if something's possible).  I even go as far as mocking full page request lifecycles to test controls and page behavior.

But say you have a little code block like this:

if(!initialized)
{
  lock(syncroot)
  {
    if(!initialized)
    {
      Initialize();
    }
  }
}

Standard lock/double-check stuff to ensure things only get initialized once.  Does anyone have a good way to test that?  A quick search of the net turns up... well, pretty much nothing.

Laser Hair Removal: Treatment 1

First, out with it: I'm getting laser hair removal on my face.

"Seriously?"

Yes.  Interesting that's the first reaction people have when they hear that.  But figure it this way: I can't actually allow my facial hair to grow.  If I do, I have all sorts of skin complications ranging from pretty bad ingrowns to severe acne and everything in between.  Talking to multiple dermatologists, I'm not ever supposed to let it grow.  Ever.  So I get the exciting fun of shaving for, well, ever.  No point in that, now, is there?  Laser hair removal to the rescue.

I went in on Saturday for my first treatment.  When I scheduled the appointment, I was told there were two different lasers that could be used: The MeDioStar or the Dermo Flash.  (Okay, the Dermo Flash is technically a Non-Contact Pulse Light, not a laser, but whatever.)  The MeDioStar removes hair by zapping each individual follicle; the Dermo Flash is more of a broad-spectrum thing that can cover several hairs at once.  The MeDioStar was described to me to feel "like having a tattoo."  I don't have any tattoos, so that didn't help me.  The Dermo Flash was described as more of a "heat" oriented thing.

I have like zero pain tolerance, so I specifically requested the Dermo Flash.

When I went in on Saturday, the technician told me that the Dermo Flash was pretty new so they didn't know how well it would work on coarse hair like the stuff on my face, but hypothetically it should work.  (According to the company, it should work.)  On the other hand, the MeDioStar is more of a "guaranteed results" thing... but it hurts. "No pain, no gain in hair removal," said the technician, Jessica.  "The Dermo Flash is pretty new and we haven't really tried it out on some of the more coarse-haired folks.  It's supposed to work, but we haven't really tried it out much.  The MeDioStar always works.  Why don't we just start you on the MeDioStar and see how it goes?"

"Okay," I said.  "I'll have to take your recommendation on this.  I don't know much about it."

"I've got to warn you, though," said Jessica.  "It hurts.  Bad.  The only time I've really ever made guys cry is with this thing.  It's far worse for coarse, dark hair than it is for light hair, so it's not like if your wife was to have her legs done or something.  This is 100 times worse than that.  My boyfriend has had some work done with the MeDioStar and he said he'd rather sit through a five hour tattoo session than have this again."

"Oh, well, now that you've sold me on it, let's hit it.  I'm looking damn well forward to it.  Bring it on.  Seriously, though, if this is the way to go, I guess let's try it and we'll see."

Jessica put some eye protection (sort of sunglasses) on me and handed me a rubber glove full of ice and told me to ice up the area.  I did, held it on as long as I could stand it, and then she brought out the MeDioStar and started dragging it across my lower neck, from my adam's apple to just under my ear.  "There are only a few hairs here," she said, "so you'll get a feel for what it's like."

Oh.

My.

God.

Seriously.  I've been hit in the nuts before and a good punch to the junk has nothing on MeDioStar hair removal.  It was about this time when I realized that ice really doesn't do shit for pain.  The thing only zapped me three or four times and I was pretty much hurting.  "Can you handle it?" she asked.

"Um... uh... well, it does hurt, yeah.  I guess try another section," I said, thinking that maybe it was just tender right there.  I mean, it's your neck, right?  It's gotta be pretty tender there.

She ran the thing along the next area just above the first.  This time it zapped maybe eight times.  The goggles she put on me started fogging up and my toes were curled in my shoes.  I crushed all the ice in that stupid rubber glove.  I was pretty much ready to die.  "There's this cooling plate here, see, that cools the skin way down before it zaps you," she said, like that helped.  "Oh, and if you want to curse at me or something, that's okay.  I'm used to that.  By the way, it gets a little worse along the jaw line."  She started in on the next area up... at my jawline.

This time it shot me maybe 12 times.  That was pretty much all I could stand.  "Jesus, are you sure you can't just give me something for this?  Like the dentist gas or something?  Seriously, I'll pay for it.  A lot.  Anything.  Just give me something because I swear I'm going to pass out in a minute.  This is the worst.  Ever."

"Yeah," she said, "a lot of a our patients would like the gas.  I've been working on the doctor to see if we can get some but he hasn't yet."

"Well, I don't think I can do this thing anymore.  This is just too much."

"Do you want to try the Dermo Flash?"

"Oh, hell yes.  I'll be your experiment.  You can verify whether the machine does what the company claims or not."

"That's not a bad idea.  And if it doesn't work, we'll comp you this treatment."

"Fair enough."

The Dermo Flash is a walk in the park compared to the MeDioStar.  This nozzle-looking thing gets put on your skin and then bam! it shoots you with this hot beam.  It sort of feels like a rubber band snapping you and it leaves a warm sensation.

I could do Dermo Flash all day long.  I almost wondered if Jessica pulled the MeDioStar out on me specifically so my pain expectation would be heightened to the point that the Dermo Flash almost feels good in comparison.

When you're done with Dermo Flash, your face feels like you've got a low-grade sunburn, but that goes away after a day.  You're not supposed to go out in the sun for a few days afterword because your skin is light-sensitive.  On the other hand, the MeDioStar section of my neck is still red and irritated looking and sore.

I am praying - and you should pray for me, too - that Dermo Flash works.  I'm finishing this thing, but if it's gotta be MeDioStar, they're going to have to give me some serious drugs.

UPDATE 8/30/07: In case it isn't clear - Jessica is cool and really easy-going and the place I'm going is also very cool with lots of cool people.  I'm happy with the service so far.  I just wasn't really ready for the MeDioStar and I don't think there's anything that could have been done to make me ready.  We tried it, it hurt too bad, and I'm hoping against hope that Dermo Flash does the job.  We'll see in a week or so!

My Daemon: The Golden Compass

For those who haven't read the His Dark Materials trilogy, do that, and prepare for the movie coming out in December.

Neat thing about the movie site - you can take a little quiz to see your daemon. I dig it. Here's mine. If you know me, you can vote on this for the next few days) and say whether you think it fits or not:

posted @ Monday, August 27, 2007 8:16 AM | Feedback (0) | Filed Under [ Media ]

Bart and Bicycles

This weekend was pretty crazy with all the running around, but the major goings-on included...

My mom got me a copy of The Simpsons Handbook through her work, but she was also able to get it slightly personalized for me on the inside...

Matt Groening personalized drawing of Bart Simpson

That's right - she got Matt Groening himself to sketch Bart on the inside!  Far, far too cool.

While we were with them on Saturday, we went shopping for bicycles, too.  Mom and Dad bought them for us as belated wedding gifts - far better than a toaster!  Jenn and I have been wanting bikes for a while, so we were pretty stoked.  Jenn ended up getting a Giant Sedona and I got a Giant Cypress.  Jenn was able to bring hers home on Saturday, but mine's still getting put together and should be done today.  I'll have to go in and pick it up tonight or maybe tomorrow, pending on my schedule, from the local Bike n' Hike.

We're all geared up with helmets and bells and everything, ready to take a ride.  The only things we really haven't gotten yet are locks and racks (so, yes, we'll have to put my bike in the back of the car for now).  We want the Yakima KingJoe 2 but we haven't been able to find it anywhere around here.  Maybe we'll have to order it online.  Anyway, I'll post pictures of the first ride when it happens.  I'm excited.

My dad's brother and family were up here this weekend visiting from California, so we got together with them, too.  It was nice to see them again and demonstrate how thoroughly I trounce Dad at Xbox 360.

Bioshock, John Woo's Stranglehold, Overlord, and Other Demos

I've tried out a bunch of game demos over the last few days on Xbox Live Marketplace and thought I'd share some feedback and maybe save you some time.

The Good Ones...

Bioshock Gamestop Limited EditionBioshock:  Possibly the richest first-person shooter environment I've ever seen, this game takes you to the underwater city of "Rapture," an exquisite art deco masterpiece, where you take on a society of genetically modified citizens in an effort to uncover the mysteries of the city and escape.  I couldn't put it down, my dad couldn't put it down... it's amazing and compelling.  I found a Barnes & Noble gift certificate I had and just now pre-ordered the Gamestop Limited Edition of this for the additional $10, which comes with a soundtrack CD, behind the scenes DVD, and action figure.

UPDATE 9/5/07: The availability of the limited edition changes so the links to it are flaky.  If you want to see more on Bioshock, check out the regular version or try finding one new/used at Amazon.

Overlord:  Tired of being the good guy in games?  Be the bad guy!  This game lets you "construct your evil empire" by ordering your minions about to carry out your nefarious deeds.  You run around in third-person as the "overlord" and send your minions to fight, overcome obstacles, etc.  I was struck by the humor in this one and had a blast with the demo.  Not sure I'll pay a full $60 for it, but if I find it used for cheaper, I'll certainly look twice.

John Woo's Stranglehold:  I like John Woo, and while I wasn't overwhelmed by the awesomeness of Hard Boiled, this game was definitely a lot of fun and very stylish.  You play Tequila, the Chow Yun-Fat character, a cop trying to track down some cop killers.  Running around shooting the bad guys is fun, and the special powers you get and the interactions with the environment make it cool to watch and play.  Even Jenn was commenting on how cool it looked as I showed her the demo.  Very easy to pick up and play and even comes with a "Casual" difficulty so you can just have fun with it.  Again, maybe not $60, but definitely on the list.

The Not-So-Good Ones...

Hexic 2:  I played the first one because it came for free with the Xbox 360.  This one adds an incomprehensible "battle mode" and removes the easy-to-see colors of the original interface with a washed-out set of colors that makes the whole thing just confusing and hard to play.  Deleted.

Fatal Inertia:  Spaceship racing with weapons thrown in - hey, never seen that before.  Oh, and if you could make it more difficult to control and basically cause me to lose the race if I mess up one turn, that'd be great, too.  Deleted.

The Darkness:  I collect comics, and I read The Darkness, so I was actually hoping for some serious coolness here.  It was sort of neat, but generally I just ran around confused and disoriented, not really knowing where to go or what to do.  I got to a point in the demo where I was running around outside some sort of compound and ended up just quitting the demo because I couldn't figure out what to do next.  The idea was neat, but the execution... not so much.  I think if I saw it for like $20 I'd consider it because when I was able to figure out what to do, it was fun.  Can't imagine putting myself through that torture for $60, though.

Track and Field:  Message to Konami - please stop porting crappy games to the Xbox Live Arcade.  Seriously.  Just quit.

Ecco the Dolphin:  Didn't this suck when it came out the first time?  I, uh, swam around aimlessly for a while, basically not getting it, dying a few times, and called it a day.

Disabled Trackbacks

Even using Akismet for anti-blog-spam (which seems to work pretty well), I've noticed that as far as trackbacks/pingbacks are concerned, I only get two types:

  1. One of my own articles tracking back to itself for cross-referencing.
  2. Spam that slips through Akismet.

So I've disabled trackbacks because they're just a pain in my ass to moderate.  If anyone can provide a decent argument why I should re-enable them, I'm all ears.  Comment away.  (Comments are still enabled.)

2007 Oregon International Air Show

The Blue Angels do their famous delta formation.The Oregon International Air Show was this past weekend and it was pretty cool.  Since Jenn and I live near the airport, we get a pretty decent view of the show just by sitting on our front porch, so we popped some chairs out there and watched the Blue Angels literally fly down our street.  (The photo is from the Blue Angels web site, but the view looks almost identical from our house.)

After the air show, since we were outside anyway, we decided to do some much-needed garage cleaning.  We "inherited" a lot of stuff when we moved into our house because my parents moved into a condo about the same time.  Stuff like two big boxes of slug and snail bait.  Bottles and cans of substances I don't think they've actually manufactured in my lifetime.  Time to get rid of it.  So we gathered all of that stuff up into a couple of boxes and prepared it to go to the chemical disposal facility.  (Gotta dispose of that stuff in a safe manner!)

Oh, and I can't remember the last time I used a hand saw, but somehow I have three.  Fine, I'll keep one, but the other two went to the Goodwill donation truck along with the four spare hose nozzles and other redundant implements.

We also made a Home Depot run to get some boxes and such to better organize the things we decided to keep.  Net result - we've reclaimed the garage.  You can swim in the space in there.  We didn't even get through all of it, either - I can see where we can do some additional optimization and reclaim even more of the space in there.

Why?  We've been wanting to get bikes for some time now, but the garage has been so jam-packed there was nowhere to put them.  Now that we've reduced the amount of crap in there, I can see some storage opportunities for those babies.  You know when the last time I rode a bike was?  Neither do I.  It's time to get back out there.

Oh, before I forget - Sunday we went to see The Bourne Ultimatum with a couple of Jenn's friends, Angela and Keaka (cool people).  We left during the Sunday showing of the Blue Angels, figuring we'd beat the traffic.  Not so - traffic was worse than ever.  Why? The ridiculous freeloading morons who decided to park along the side of the road so they could watch the show.  It wasn't just a few cars - there were so many cars lined up on the freeway it was like they had pulled over for an emergency vehicle and just decided not to drive again.  Motorhomes pulled off into fields adjacent to the freeway and dropped anchor.  Cars lined up like it was a drive-in movie, pulling off the road with their rear ends in the ditch.

Now, I'm glad that they pulled off the road rather than trying to drive and watch at the same time.  (We passed a totalled car that was pretty obviously the result of the driver trying to watch and drive at the same time.)  But I feel pretty strongly that if you're going to watch the show, maybe you should go pay your $20 and support the show.  I realize it sounds sort of hypocritical considering I parked my butt out on my front porch, but then, the airport has a noise easement over my house for this sort of thing, so I kind of feel like my property taxes already go to support these things.  My house is the one the pilot's going to crash into if he goes down.  You people parking on the side of the freeway?  You were on the way to the store and decided to get a free show.  That's bullshit.  Either keep driving or go get a ticket, you freeloader.

The Bourne Ultimatum

I really need to get past the fact that the Bourne movies have no relation whatsoever to the books with the exception of general character naming.  Ever since the first movie, they've gone on such a diverging path as to make the two almost incomparable.

That said, if you let all that go, The Bourne Ultimatum is a pretty cool movie.

I re-watched the first two this week in preparation.  In The Bourne Identity, we find that Jason Bourne (Matt Damon) is a black ops assassin trained by the government during an operation called "Treadstone."  In The Bourne Supremacy, some people in on the "Treadstone" operation try to frame Bourne for some evil doings in an attempt to use Bourne's reputation as a cover-up.  Each of those movies ends with Bourne basically going off into the sunset to try and live his life in peace, but realizing that the government is still after him so he'll always be on the run.

The Bourne Ultimatum is Bourne trying to find out more about his past and stumbling upon a larger operation - apparently "Treadstone" was just the beginning.

The movie was an action-fest, and none of us left the theater disappointed.  Great stunts, lots of fun, and very entertaining.  I didn't feel like my entertainment dollar was wasted.

That said, you really couldn't analyze it too closely because the plot starts looking like Swiss cheese with all the holes.  Normally I can let a lot of that stuff go by virtue of the fact it's an action movie and generally implausible anyway, so a couple of details this way or that way don't matter.  There were two details that bugged me about The Bourne Supremacy that I'm having trouble getting past.

First, by the end of the second movie we see that Bourne has kind of made peace with things and has accepted that he'll only know just so much about his past.  He goes off to live happily ever after.  At the beginning of the third movie, he's back in full gunslinging action, apparently on a search for... his past again?  I thought he was over that.  Eh, fine, they needed something for him to get worked up over.

Second, in the end of the first movie when Bourne confronts his old CIA handler, Conklin (Chris Cooper - a man who always plays the best corrupt government agents), about his identity, Conklin does a little disclosure monologue saying how Bourne was supposed to kill some guy, yadda yadda yadda, and that Bourne picked the place it would happen, picked the time it would happen, and picked his cover for the hit - Bourne picked the name "Jason Bourne."  In Ultimatum, they contradict that statement by saying Bourne was given that name during training.  Huh?  I hope I'm just remembering the end of Identity wrong, but I just watched it and I swear that's what happened.  So that stuck in my craw a bit, but I guess I can let that go, too.

Anyway, The Bourne Ultimatum was pretty cool.  I liked it better than The Bourne Supremacy, and there was a lot less of that shaky-cam crap that The Bourne Supremacy overused.  Check it out, you'll like it.

posted @ Monday, August 13, 2007 8:06 AM | Feedback (0) | Filed Under [ Media ]

If You're Gonna Blare Music, Make Sure It's Good Music

Coming out of the grocery store yesterday, I swore I heard an ice cream truck.

It started quiet, sort of peaceful, like that background music you hear sitting outside a decent coffee shop.  Second by second, it got louder.  And louder.

Looking around, I saw this car come tearing into the parking lot.  Tires squealing, careening around other cars, totally unsafe style, and coming this way.

At this point, the music was so loud it was like I was listening to my own headphones.  It had changed, though, from ice cream truck music a la The Entertainer to something more lilting, bringing visions of castles and ponies and princesses to mind.  Like Zamfir, but with more birds chirping and crap.

The car screeched into a parking spot and the driver stepped out, the music immediately silenced as the car turned off.  The driver, acting far more important than I'm sure he'll ever be, strutted into the store.

I'm not a big fan of those cars that crank their music up to share with the neighborhood, but I mind it a little less if it's at least halfway decent music.  I'd even take some ridiculous hardcore gangster rap over this fluffy-pink-clouds garbage.  If you're gonna blare music, at least make sure you're blaring good music.

Cats + Audio = Expensive

Jack and Xev are friends, aren't they?I love my two cats, but the little Siamese-tabby mix Jack is pretty aggressive and he's been chasing my other cat Xev around a lot, particularly in the last, oh, month or so.

Yeah, you'd never guess that from the picture, right?

Okay, so a couple of weeks back, it's business as usual - Xev is yowling because Jack is riding her back around the house.  (Yes, he's fixed.  They both are.  He's just being an asshole.)  They make a mad dash out from behind the couch and...

SLAM!

I turn to see that one of the stands with one of my Bose Acoustimass 16 cubes has been knocked over and the two cubes that make up the speaker have come apart from each other at the part where they swivel.

The cubes are broken apart where they swivel.

Looking at the mechanism that was exposed, it looks like the thing literally just snaps together.  Unfortunately, the way it snaps together is so tight and fits together in just such a way that there's really no way you can just snap it back together.  I can see that the assembly of the two cubes actually happens pretty early in the manufacturing process because it looks like the two cubes would need to be snapped together before the speaker bits got inserted.  The speakers proper still work, the cubes just aren't attached anymore.

I tried everything short of actually disassembling the damn thing, but it was no use.  I ended up taking it to a repair shop who specializes in this sort of thing and it turns out the speakers aren't field serviceable.  Of course they're not.  Instead, they have to order me a replacement, and that's going to cost me - wait for it - $151.  That's one-hundred-and-fifty-one American dollars.  That's in addition to the $25 I already paid them to look at the thing for me (some of that is credited toward the total cost of the speaker, bringing it down to $151).

Travis == Over A Barrel.  ARGH.

Convert A Batch File or VBScript to EXE

There is so much stuff out there that I have no idea exists.  Anyone else know that there's a program that come with Windows called "IEXPRESS.EXE" that basically makes installers?  Anyone know you could use this thing to convert a .BAT or .VBS to an .EXE?

Yeah, neither did I.

CR_Documentor and XSLT May Be Harder Than I Thought

I started working on converting CR_Documentor over to use XSLT for its documentation transformations this morning and soon realized that it may not be that easy.  The goal was to be able to just take the XSLT from the various documentation generation engines (NDoc, Sandcastle) and as fixes or changes happened, "plug in" the new XSLT and have the preview ready to go.

Not so much.

I tried a simple test using the NDoc XSLT and it turns out that I have a few stumbling blocks.

  • The input XML is complex.  The format NDoc expects the XML to be in prior to executing the transformation is pretty complex.  That's not really a problem in a post-build timeframe where you're not looking for real-time changes, but just creating the correct XML hierarchy is a pretty big task, let alone then getting it through the transform engine.
  • Everything is relational.  There are a lot of things in the NDoc XSLT that assume, for example, that you've got everything you need to document all in one file, so there are relational things going on.  For example, when you generate the documentation for a method, any cross-reference links you have are also generated... which runs through connecting actual URLs to HTML files and setting up links and everything.  To avoid setting up bad links, the XML that's generated gets heavily pre-processed.  Again, not something that can readily happen real-time.
  • Much is assumed to be in the filesystem.  Temporary files, the XSLT, images, script... there's a lot that the XSLT assumes is in specific spots in the filesystem, which means that I couldn't use the stylesheets as-is anyway; I'd have to heavily massage it to get it where I want it to be.

Unfortunately, a lot of this sort of means using XSLT directly is a non-starter.  Even if I could get past the fact that I'd be doing almost as much work creating the input XML as I'm doing right now to generate the whole preview, the requirement for all the relational things and the fact there's so much in the filesystem anyway means I'm probably better off just hard-coding the transformation the way I've been doing, as lame as that is.

I won't lie; it doesn't increase my desire to work on the project.  I like it, and I really wish I could just release it to the community open-source style, but since I can't, I'm sort of stuck.  Motivationally challenged, shall we say.

Well, I guess my next step is to look for opportunities to refactor it and make the code at least a little easier to maintain and update.  Maybe that will make it easier to implement new rendering views.

Acquisition Q&A Simulator

Going through the process of being acquired twice in the last few months, I'm getting pretty used to how the information dissemination process works.  In a nutshell, there really isn't any.

From one point of view, I get it - there's a lot to coordinate, and legal requirements dictate that certain things can't be shared until certain times and so on.  I get it.  I get it so much I'm really tired of people reminding me about it because they think I don't get it.  I promise.  I get it.

The other side - the side I seem to always be on is "The Dark Side."  Not like the Dark Side of the Force, more like "people who are in the dark about any details about what's going on."  This is actually the majority of the people most of the time, and regardless of how "transparent" communications are supposed to be, management (the people who "know stuff") generally seems to believe that "more communication is better," even if there isn't actually anything to communicate.

If you haven't been through this process, I thought I'd help you out by throwing together a little Q&A simulator so you know what this is like.

First, imagine you've been notified of a very important all-hands meeting.  It's mandatory.  You must attend.  Your very life depends on it.

You get to the meeting, and the Person In Charge says, basically, "Hey, folks, we've been acquired.  We figured this was the best move for the company.  Any questions?"

Now's the time you get to ask all the questions you might have.  Try them out in my handy simulator:

...and there you have it.

Now go to three or four of these in close succession - one for the whole company, one for your division, one for your group within the division... you get the idea.  Congratulations!  You've been through the acquisition experience.

GTA IV Delayed to 2008

You have to be freaking kidding meI have to wait until SPRING?

Noooooooooooooooooo!!!!!!!!!!!!!!!!!!!!!!

posted @ Friday, August 03, 2007 8:12 AM | Feedback (0) | Filed Under [ Gaming ]

Mock a Page Request Lifecycle with TypeMock

Let's say you're writing a service like an HttpModule that performs an action against each page that gets served up.  Maybe it does something like move the viewstate to the bottom of the page, update a property on the page, or fudge the control hierarchy a bit.

The thing is, you want to unit test it, but how?  Mocking an HttpContext is hard enough, and many times you end up going down the UI automation road.  Ugly.

Enter TypeMock.

A few lines of code, setting up the minimum amount of stuff, and you can mock just enough context to actually get a full page request lifecycle to execute - events and all.  So say your service needs to be called during the page PreInit and you can check the results of whatever you did during Load... here's what that looks like:

[Test(Description = "Tests an external influence on the page lifecycle.")]
public void MyPageServiceTest()
{
  Page page = new Page();
  
  MockObject<HttpBrowserCapabilities> mockBrowser = MockManager.MockObject<HttpBrowserCapabilities>(Constructor.NotMocked);
  mockBrowser.ExpectGetAlways("PreferredRenderingMime", "text/html");
  mockBrowser.ExpectGetAlways("PreferredResponseEncoding", "UTF-8");
  mockBrowser.ExpectGetAlways("PreferredRequestEncoding", "UTF-8");
  mockBrowser.ExpectGetAlways("SupportsMaintainScrollPositionOnPostback", false);
  
  MockObject<HttpRequest> mockRequest = MockManager.MockObject<HttpRequest>(Constructor.Mocked);
  mockRequest.ExpectGetAlways("FilePath", "/default.aspx");
  mockRequest.ExpectGetAlways("HttpMethod", "GET");
  mockRequest.ExpectGetAlways("Browser", mockBrowser.Object);
  
  MockObject<HttpResponse> mockResponse = MockManager.MockObject<HttpResponse>(Constructor.Mocked);
  
  HttpContext mockContext = new HttpContext(mockRequest.Object, mockResponse.Object);
  
  using (StringWriter stringWriter = new StringWriter())
  using (HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter))
  {
    mockBrowser.AlwaysReturn("CreateHtmlTextWriter", htmlWriter);
    page.PreInit +=
      delegate(object sender, EventArgs e)
      {
        // Perform some action
      };
    page.Load +=
      delegate(object sender, EventArgs e)
      {
        // Check/Assert the results of your action
      };
    page.ProcessRequest(mockContext);
  }
}

Obviously the majority of this could be wrapped up into a library or something, but I show it here to illustrate that, at least in ASP.NET 2.0, this is all it takes.

(You'll notice that I'm using the Reflective mocks instead of the Natural mocks that I prefer in TypeMock.  The reason is that I'm mocking a couple of internal things and mocking non-public items requires the Reflective mocks.  By mocking these internal convenience methods, I can greatly reduce the amount of setup for this to run.)

Generation of Designer File Failed: Unknown Server Tag

I was doing some experimentation with custom web server controls in ASP.NET 2.0 so I created a quick Web Application Project and started throwing some controls in, using them on the page that gets put in the app by default.  Unfortunately, I started getting the following warning:

Generation of designer file failed: Unknown server tag 'cc1:MyServerControlName'.

For a minute, I thought maybe I had forgotten the <%@ Register %> directive at the top of the page, but, no, there it was:

<%@ Register Assembly="MyTestAssembly" Namespace="MyTestNamespace" TagPrefix="cc1" %>

I struggled for this with some time, building and rebuilding, searching and not really finding much on the web at large, and then I tried something that worked:

If the page and the custom control are in the same assembly, remove the "Assembly" portion of the directive.  For some reason, the designer just doesn't understand it if you specify the assembly you're tasked to build.  I'm not sure why.  So the directive becomes:

<%@ Register Namespace="MyTestNamespace" TagPrefix="cc1" %>

Once I did that, everything worked great.  YMMV.

UPDATE: If you're using master pages and the control in question is inside a Content control, you may still see weirdness about unrecognized server tags.  In that case, add the tag prefix registration to web.config, again omitting the assembly:

<?xml version="1.0"?>
<configuration>
  <system.web>
    <pages>
      <controls>
        <add tagPrefix="cc1" namespace="MyTestNamespace"/>
      </controls>
    </pages>
  </system.web>
</configuration>

One thing I noticed was that this seems to be... maybe a little flakey.  Depending on the circumstances, you may get a page that says your control tag is unrecognized at runtime.  That will require you add the "assembly" bit to the tag prefix registration in web.config... but that will cause you to have trouble in design time because the designer file won't be generated properly.  Erg.