Saturday, July 29, 2006

Application_Start and ASP.NET identity impersonation

Now if that isn't a gripping title, I don't know what is!

Found out an interesting bit of trivia about ASP.NET and its processing life-cycle. The code I was working with has a per-application cache that was being loaded during the first web request that came in. There was an immediate problem with it reloading the cache multiple times under sufficient load, so I just put a locking solution into place to get around the problem. For a longer term fix, I thought the right solution would be moving the cache load from Application_BeginRequest out to Application_Start.

That's when I ran headlong into the trivia. The system was using ASP.NET's built in identity impersonation to pass credentials to our SQL Server backend. As soon as a moved the code to Application_Start, though, I got failures to connect to the database because the user wasn't identified.

A little digging turned up this reference which explained it pretty well. ASP.NET doesn't start impersonating a Windows identity until after Application_Start has finished. That meant that when my code was running, it was as the local ASPNET identity, which didn't have the rights to access the database. Given our setup, that wasn't about to change, so the code remains, healthy and happy in Application_BeginRequest.

Wednesday, July 26, 2006

Mali Journal

I talked a little about the trip I took recently to Mali in "And now for something completely different." Finally had a couple people read through, corrected some typos and added a few things, and now it's ready to go. You can check it out at http://home.comcast.net/~jason.r.clark/mali/mali_journal.doc.


My wife also took a bunch of absolutely wonderful photos, and those are at http://tinyurl.com/ra2nn. (Went with Snapfish because it has unlimited upload, although getting a sharable URL took a step or two--they really want you to ping everyone with an e-mail from their system).

Review from a friend

I've never been one of those writers who feels like they need to edit a piece to perfection before someone else reads it. Over the years, I've gladly subjected my friends and family to stories in various levels of completion. Occasionally I'll delay, like today when I'm halfway through a major rewrite, but normally I'm pretty free about sharing works in progress.

My readers have always been encouraging and occasionally give great feedback, but I've learned an important lesson--it's hard for people who don't write to critique fiction. If they read a lot, that helps, but even then comments boil down to vague impressions that leave a writer screaming for details. "That scene didn't work for me," or "I didn't like that character," or the dreaded "It was okay," one-sentence summation of the books. I want to hear their thoughts, but sometimes when it's so broad it's hard to know what to fix.

Nowadays, I still love to have friends and family read my writing, but I tailor my expectations about the comments I expect back. Some people will be better than others, but I rarely look for sentence-level criticisms (or even page for that matter) from most people.

Enter the exception. My friend Nate has his MFA in poetry, and has been accepted for a creative writing PhD program in South Dakota. We've had good discussions about writing before, with intentions to swap work eventually. And boy did it pay off! Nate's got a method to how he critiques, which means that he read through it twice, and made lots of specific comments throughout. He's teaching composition classes at local colleges at the moment too, so he spotted some grammar and construction issues that I would have been hard pressed to pull out, but that once he showed me a few examples are blindingly clear. It was like having a bright light turned on my writing, and it's going to help me a ton.

Equally as important, though, Nate has that most important ingredient in a good critique--he knows how to tell you what's good, and leads off with it. He had several well thought through items he liked about the book (some of which are areas I've been working on in past drafts), he picked up on subtle elements that I've buried in there that no one else has mentioned before, and overall really lifted my spirits. Since the trip, it's been hard getting back into the flow of writing, but after sitting down with him, I feel recharged and ready to dive in.

He passed along a short story of his, the first thing I've had the chance to read from him. I think this is going to be fun!

Sunday, July 23, 2006

Diving into Ruby

If you're involved in web development, or even software in general, you've probably heard about Ruby lately. It's a programming language out of Japan, with a reputation for elegant simplicity, expressive power and just plain being fun to use. The Ruby on Rails web development framework has catapulted the language into the public eye.

I've been dabbling with Ruby for the past week, but it wasn't in fact Rails that drew me to it. The fact that currently Rails doesn't run easily under the web server I use at home (IIS 5.1) and I have a very limited amount of time for extra-curricular development have so far ruled that out (although I'm quite interested).

It was actually reading through the articles on Stevey's Drunken Blog Rants that tipped the balance. Contrary to the name, it's a collection of blog posts from Steve Yegge (who now has a more typical blog) that I found to be quite insightful and entertaining. They do often qualify as rants, but he goes on at some length about the weakness of modern programming languages, how in many cases they hamper our ability to get work done, rather than smoothing the way. He's got me seriously thinking about going back and really learning Lisp, since I didn't get it that well in college (although he clearly recognizes that it isn't too useful in production today).

Anyway, this post is supposed to be about Ruby, though. Yegge's current favorite language is Ruby, and he has a lot of persuasive reasons why he likes it--mostly revolving around how the language doesn't get in the way.

I've experienced (on a small scale) some pains around my current default language, C#, in my home development. I've built a clean, sharp OOP'd up system with nice classes to represent my database storage, elements in the database, units tests for the whole thing. Then I went to add a field. Now maybe there's some obvious deficiency to my design, but it's quite in the mainstream from what I've seen. Anyway, adding a field required changes across multiple files, broke unit tests (well, I guess that's what they're there for, but anyway) forced me to make choices about how to restructure method params--do I want a new constructor, or add the parameter to the old one and change all the call sites? Long story short, something that seems like it should be fairly natural was a pain in the butt.

So I finally set out to actually try out Ruby. I can't use it for production code at my current workplace, but there's a lot of repetitive scripting tasks that I think it might work perfectly for once I get the language well fixed in my mind. And Yegge's right--it's just a pleasure to work with. The syntax, the classes, the interactive shell, it all just works together really well.

Here's some great places to start if you're wanting to dabble with Ruby as well:

  • http://tryruby.hobix.com/ -- Try Ruby online in an interactive shell and tutorial, right in your browser. No install, plenty of good humor and a great way to get a feel for the language.

  • http://rubyforge.org/projects/rubyinstaller/ -- Ruby installer for Win32. Has a basic IDE and all the core stuff--including irb, the interactive shell which is fabulous for just meddling around.

  • http://www.rubycentral.com/book/index.html -- The Pragmatic Programmers: Programming in Ruby. Excellent book that I'm partway through for learning the whole language. Again, lots of character and good writing.
Don't know exactly how this'll all be useful in the future, but another takeaway from Stevey's Drunken Blog Rants is that learning new languages isn't a bad thing whether you use the language or not. It's been too long since I've looked at code (apart from VB) that doesn't have curly braces and semi-colons all over it, so I'm taking the plunge.

Thursday, July 13, 2006

Origins of an idea

I've subscribed recently to Backstory, a blog that gathers together authors' stories about where specific pieces of writing came from (mostly novels, a few short story collections). Although I haven't heard of a lot of the authors, and many are outside of my normal interests, it's always a good read.

Inspired by that, I remember the initial idea from years ago that has turned into the novel I'm currently working on, Dreams of a Shaper. I was recently out of high-school and working evenings at a local grocery store. During the slow periods, this gave a lot of time for thinking. I was in the midst of drafting a fantasy novel at the time, but the current project rarely keeps me from running down other ideas when they seem interesting.

I wanted to write something that took place in the real world, fairly present day. However, I am at my heart a sci-fi and fantasy reader, so it couldn't just rest there. I began with a standard (one might even say clichéd) concept--what would it be like if people were hiding among us, in plain sight, who had tremendous powers? What if they were able to meld the fabric of space, bend it to their will, teleport massive distances, move objects.

I could see it now--a college student is approached by an older, grandfatherly gentleman, who reveals to him the ability that is just now blossoming for the young man. The gentleman becomes his mentor, teaching him how to use this fantastic ability. Perhaps he goes to a school where people, even aliens, gather from everywhere to hone their skills in shaping space.

But what would happen then if a crisis hit, an invasion from outside of our typical, 3d universe. The young man is drawn into this conflict, along with his friends, as they fight for the existence of everything we know.

I played with this idea for several days, coming up with characters, or world details, messing around with them in my mind. It's always good for me to stew a while on the longer ideas I want to write, because many things that at first blush seem great start to creak after just a few hours more contemplation. That's what happened here--I realized how comic-book-ish, space opera, clichéd and boring the whole thing was. I'd spent a couple days building this world in my mind, and when I stepped back I found out that the whole thing sucked.

Well, almost all of it. One small piece, the kernel of the idea stuck with me. It was easy to jettison all the characters and settings I'd develop, but that concept of bending, weaving, shaping the fabric of space, I couldn't shake it. That alone survived, although it wasn't enough on its own. Later, when I mixed that idea with another (shapers are unusually long-lived, but condemned to madness as they age) I suddenly had a live one on my hands.

Often times, authors (myself included) like to act as if all story ideas just come at you, fully formed out of some dark, mysterious place. It's happened to me, and don't get me wrong, it's a wondrous feeling. But don't be discouraged if your initial, fabulous inspiration kind of starts to teeter a few steps down the road. Keep thinking, salvage what's good, and keep writing!

Tuesday, July 11, 2006

Review: Latro in the Mist

Latro in the Mist is an omnibus version of Gene Wolfe's Solider in the Mist and Solider of Arete. With my recent trip, I was looking for something meaty, a book that I wouldn't be finished with in the course of an airline flight. I took only two books on the trip--Latro, and The Island of the Day Before by Umberto Eco. Needless to say, I didn't run out of reading material.

I absolutely love Wolfe's writing, although the things that make it magnificent also make it slightly inaccessible too. The setup for Latro, is that the main character is a solider in ancient Greece who has sustained a head injury and forgets everything by the last day. The book is a chronicle that he writes for himself to remember what has gone before. When I first heard that, I wondered how anyone could form a reasonable story with that premise, but Wolfe pulls it off.

Most of the time, each chapter encompasses a single day in Latro's memory. Often these chapters will begin with a tidbit about where the chapter will end up--the point at which Latro is actually writing down about his day. This is quite effective foreshadowing, giving a brief glimpse of what's to come in a natural form. It feels completely consistent with a journal, but serves a purpose for the reader too.

Repetition is a common element in the book. Since Latro meets everyone anew each day, he often doesn't know the name or identity of people that he runs into early in the chapter. Wolfe manages to keep this fresh, though, in a couple of ways. For one, he uses the tool to his advantage with characters whose relationship to Latro change over time. People who begin as friends in some cases turn out to be enemies, but since Latro has no memory of them before, he isn't aware of that shift like the reader is. Wolfe also mixes it up by a slow build-up of vague familiarity in Latro for central characters--Io, a slave girl; Seven Lions, a black man who fights alongside him from the start. It is interesting to see this knowledge, hazy though it might be, build throughout the course of the story.

In typical Wolfe fashion, the plot is not always direct, but this reflects neatly off Latro's own inability to remember what was happening before. Occasionally there are gaps in time in which the reader--and Latro--know only what they can conjecture of what happened, as Latro did not manage to write.

Reading this book also gave me a desire to get more familiar with Greek mythology and history. Along with his memory problems, Latro is also capable of seeing the gods throughout the land. Mostly, they aren't introduced by name, but only described, so without a solid grounding in the mythology, I'm sure I missed many subtle points. Ditto on the history. It fits into a very specific time-period, with well known events... just not well known to me.

As an example of Wolfe's style and abilities, I think this is an excellent book, and would serve as a great introduction to the author.

Thursday, July 6, 2006

And now for something completely different

I recently took a trip to Mali, West Africa, with Northwest Medical Teams. It was a great experience, and one of the best parts about it was the break in my writing routine it brought about. Before we went, I decided that I was going to journal the experience in some solid detail, but also that I would write in such a way that I could later share it with others.

It was quite refreshing to take on a totally different type of writing. Where fiction (my fiction at least) dictates a fair amount of structure--you need to set the scene, have a clear direction, no long, rambling descriptions unless there's a point--journaling opens up whole new worlds of looseness.

Another plus was reading it aloud to my wife, Amber, at several points along the way. She was quite encouraging, letting me know that I'd done a good job capturing the essence of what the trip was like.

I'm planning to do some minor editing--just fixing blatant grammar and spelling problems, that sort of stuff--and that is also a nice break. I want the piece to have a fairly rough feel to it, so the normal process of polish, polish, polish isn't really called for.

I might post it online once I'm done, along with some photos. Not going to spend much time here talking about it, but as a writing exercise, I've got to say that travel journaling has been a wonderful change of pace.