This Blog Has a New Home

May 22, 2008

Dear Reader,

Regrettably, WordPress just wasn’t cutting it, and so I made the difficult decision to move ship to Blogger. My new home on the web is www.toastedcode.com. Yeah I know – if I had set up a domain a long time ago I wouldn’t have had to make this service announcement.

I’m still working on Code Toaster and will create an updated site at a later date with links to download files, documentation, and so forth. For now, check www.toastedcode.com for the latest information.

I hope you’ll follow me to my new home, but if not, it’s been swell!


Unit Test Shadowing

April 26, 2008

I looked carefully at the unit test VS.Net 2008 had just generated. Looked standard enough, except… what was this? A class named CodeFragment_Accessor?

PrivateObject param0 = null;

CodeFragment_Accessor target = new
CodeFragment_Accessor(param0);

int expected = 0;

int actual;

target.TextLength = expected;

actual = target.TextLength;

Assert.AreEqual(expected, actual);

Assert.Inconclusive(“Verify the correctness of this test method.”);

 

Hold on now! That wasn’t one of my classes – I’d never seen it before, although I did in fact have a class called CodeFragment. I right-clicked and selected Go To Definition from the popup menu.

[Shadowing("CodeToasterGenerator.Translator.FragmentTracking.CodeFragment")]

public
class
CodeFragment_Accessor : BaseShadow

{


}

 

The class looked familiar somehow. On closer inspection, it appeared to be a copy of my CodeFragment class, except that in this _Accessor version, all the fields I had declared private were declared public. Hmmm.

I cracked open the MSDN documentation and ran a search for the ShadowingAttribute. MSDN displayed the helpful hint: Do not use this class.

Really. That’s what it said. Do not use this class. Lighten up Microsoft, I wasn’t going to use it, I just wanted to know what it’s for! Sheesh. And that’s pretty much all the documentation it looked like I was going to get on the infamous ShadowingAttribute.

But moving right along – the _Accessor class inherits from a class called BaseShadow. Maybe that would provide some clues.

And I was right – MSDN reports that BaseShadow
is used by the publicize method to help you test private types.

Well now, that makes a whole lot more sense, and is actually pretty snazzy too. Although, to be honest, I’m not sure what publicize method they’re referring to. I mean, I see what they’re getting at, but that seems like odd language. Did they mean there’s a class somewhere that has a method named publicize, which uses the BaseShadow class in some way, or does this refer, in a general sense, to the process of publicizing a test? Or something.

Anyway, VS.Net’s unit test framework apparently uses some fancywork (using reflection) to ensure complete code coverage (instead of generating tests for only public fields, properties, and methods). You’re not going to get much help from Google doing a search for ShadowingAttribute, but take it from me that you can (and should) safely use the generated _Accessor class to unit test both public and private accessors in your class. And this is another great reason why you should let VS.Net stub out your unit tests for you instead of building them from scratch yourself – hand coding the “shadow wrapper” would take a while.


Parser Remade

April 24, 2008

Yes, I’m still working on Code Toaster in my spare time. Given several bug reports from the last release involving the COM-based parsing toolkit, ProGrammar, from Norken Technologies, along with the fact that development seems to be inactive right now (read: they stole my money), I decided to yank out all ProGrammar dependent code and replace it with pure .Net parsing stuffs.

And that’s working very well. In fact, I think it’s working better than I expected, perhaps because, this time around, I’m using much better development practices. Like Test Driven Development. In retrospect, it was extremely foolish of me to ever approach a large coding project like this without reams of automated tests – I’ll talk about that later in this post. But first, a little about how the parser(s) work…

Parsing a template is comprised of three steps.

  1. A Code Toaster template is parsed into a parse tree by the Template Parser.
  2. The C# Generator translates the parse tree into compilable C# code. In the new design, C# code generation is done as the template is parsed, not as a separate step (as before, with the ProGrammar parser), which yields much improved performance. I maintained modularity by deriving the C# Generator class from the Template Parser base class, and by making parsing event based: as template “nodes” are parsed, an event is raised that allows any interested classes to “do stuff” (like generate code).
  3. The C# Parser parses the generated C# code. The only reason this step is necessary is to give you bodacious IntelliSense as you’re editing template code.
 

Each step increases in complexity by many-folds. I’ve completed the Template Parser, which was enjoyably challenging but not ridiculously difficult. It’s currently parsing a 1,000+ line template in about 80 milliseconds, which should be fast enough, I think. I’ve done some performance tuning, but may revisit it later to try to speed things up even more. As you’re editing a template, any changes (like variable declarations, new types, etc) need to be available immediately within IntelliSense, which means the backend parser and IntelliSense engine must be lightning fast.

And reliable, which is why I’ve spent a good deal of time fleshing out a suite of unit tests. VS.Net 2008’s new unit testing functionality is just a beautiful thing. It’s actually beyond beautiful. If a test fails, I can easily run just that test (VS.Net is smart enough to figure out what test to run by looking at where my cursor is in the test class), step into the code, and inspect and fix the problem using the stupendous Edit & Continue feature. Yeah, you could do almost the same thing with NUnit, but the process is so much more streamlined now, and just plain easy.

I think I’m on the right track. Getting rid of ProGrammar means there’s no cross-appdomain performance penalties, no COM headaches (like registering and unregistering COM dlls, and all the headaches that could entail, during installation), and most of all, I can tailor the parser architecture to meet the rather specific needs of Code Toaster.

So your next question is probably: what about that C# parser? How long is that bad boy going to take to write from scratch?

And the answer is: not long at all. But that’s a story for another post.


Hackin’ Your Heart

April 6, 2008

 

A few security researchers have recently turned their attention from hacking RFID chips to pacemakers and implantable defibrillators.

Apparently a hacker could cause some serious cardiac damage, wirelessly, from less than 5 feet away. For now, the threat appears to be “largely theoretical”, whatever that means. At the least, the idea of someone being able to stop a heart, via remote control, would make for a great novel or movie plotline.

But for those 250,000 folks sporting a pacemaker under their skin, it might be time to start thinking about making suspicious visitors and money hungry, unscrupulous, relatives check their laptops and other wireless devices at the door. 


How Many Video Cards?

April 1, 2008

So now, apparently, you can configure an SLI system with three (or more!!!) video cards instead of two.

Is it just me, or is this starting to resemble the razor blade shootout between Gillette, Schick, et al?

From TweakTown’s review:

It’s clear that NVIDIA has really got its dual GPU SLI technology sorted out, but when you start mixing it up with three or four GPUs the performance increase while present, is very small, especially in relation to what it costs you to go down that route.”

Psychologically, though, I can’t help feeling that, if I had the funds, of course three video cards must be better than two! And most definitely one!

Ain’t that just silly?


Where Have I Been?

March 20, 2008

You may have noticed this blog has been mostly inactive for a while. A long while. That’s mostly ’cause I haven’t been feeling too good lately. I think I’ve caught every cold and flu bug that’s gone around this season, and along with 1 year old twins taking up a lot of my time, staying up late to work on Code Toaster or blog a bit has been the last thing on my mind.

I’m trying to get back into the rhythm of working on Code Toaster a few hours each night; updates should be forthcoming. Bear with me while I get things rolling again.


Ten Plus Two

January 4, 2008

Every so often, especially if you work in IT, rather than a fancy-schamncy development shop or somesuch, you’ll be tasked to do something mind-numbingly boring, like editing a 10 year old Word macro. Or writing CRUD code by hand. Or writing (the horror!) documentation.

In which case it can become a little difficult to stay focused. For a little help in that area, try out this Yahoo widget: Ten Plus Two (you’ll of course need the Yahoo widget engine installed).

Ten Plus Two is basically a timer than counts down for 10 minutes (or more, or less, if 10 minutes isn’t your cup of tea) of work, and then counts down for 2 minutes of rest before repeating the process. Work for 10 minutes, breathe for 2 minutes. Your two minutes can be a trip to the bathroom, a quick blog post, or just staring off into space while your eyes rest. Each change is accompanied by a nice little audio cue as well as color indicators – the background turns red when you’re supposed to be working, and green when you can take a break.

Granted, this could possibly get aggravating after a while, but it works wonders for keeping me on track while slogging through monotonous work items when I would much rather be browsing TechMeme or reading the latest from Coding Horror.


Volta

December 17, 2007

Someone just sent me a link to this new offering, from Microsoft Labs, called Volta. I haven’t actually tried it out, but if it does what it says it does, it could add a new twist to AJAX-based web development.

What it purports to do is to allow you to design a web app as a .Net client application, slice it up into different tiers, and spit out cross-browser JavaScript for the client tier, web services for the server tier, and all the boilerplate code to tie everything together.

At first glance I got all giddy and thought that this could convert any .Net client application to a web-based app, but a closer look seems to show that to not be the case. You have to use the Volta libraries and mix and match traditional HTML with your .Net code.

Might be worth a look. 


Wonderful Utilities

November 7, 2007

Here are a couple of utilities I use regularly that I consider indispensable and most definitely worth the money.

Ultramonlink

If you have a multi-monitor setup, you must run out and purchase this tool right now.

This tool has changed my life!

OK, maybe not really changed my life, but it has drastically improved my satisfaction level when working across multiple monitors. The price is reasonable at only $39.

Just buy it. Or at least download the trial. You’ll thank me later.

Enso - link

Humanized.com puts out some interesting products; I’ve only tried Enso, and it is truly a beautiful thing. It’s a little hard to explain without actually giving it a whirl, but, in a nutshell, you can teach it to do things when you type short commands, like “open my documents”, or “open intranet”, or “define heuristic”.

If you’re a developer such as myself, your first thought when you take a look at Enso will probably be something like, “I could have done that. This isn’t that hard.” But after using it for a bit, I’ve come to think that it’s too simple and elegant to have been easy to put together. I can open a file, URL, folder, or run a program anywhere on my computer, without searching for it, just by typing a simple intuitive command.

And the price is super reasonable at only $19.99.

Just buy it. Or at least download the trial. You’ll thank me later.


Automagical Update

November 6, 2007

I’m becoming more and more convinced that the best application installer out there is WiX. No, it doesn’t have a fancy GUI, and yes, it has a crazy nasty learning curve, but once you get into it’s innards it is awesomely powerful.

I’m doing some work on the next minor version of Code Toaster, which (hopefully) will include an automatic update feature. After reading (again, for the ka-jillionth time) this tutorial on creating an update msi with WiX, methinks it should be fairly straightforward. The process will go something like this:

  1. When Code Toaster launches, it will download an XML file containing version information.
  2. If there is a new version (as noted in the XML file) Code Toaster will download the msi installer for that update.
  3. Code Toaster will launch the msi and exit.

One problem I’ll have to resolve is how to install an update while Code Toaster is running. The most oft-used and recommended solution for doing auto-updates is to launch your application via a proxy that does the update work, and then launches the application later if no updates are available (or after the update process is complete). But I don’t like that for a couple of reasons. 

  1. If there are two executables, CodeToasterProxy.exe and CodeToaster.exe (or whatever), that might confuse a user as to which one to run (users would run CodeToasterProxy to get the update capabilities, not CodeToaster.exe).
  2. Since CodeToaster.exe can be run as a command-line application (to compile/run templates in batch mode, for example), it should be intuitive which exe to run in that scenario. In this case, the user would run CodeToaster.exe, not CodeToasterProxy.exe.

I bet you’re looking at this post cross-eyed after that wonderful explanation, huh? Maybe I should have boiled it down into one reason: confusion. And we sure don’t want Code Toaster to be confusing.

There is another option : to have Code Toaster check for and download updates, and then launch a separate application to run the msi update. That would keep things intuitive – you would always launch CodeToaster.exe rather from the command-line or from the Windows GUI, and CodeToaster.exe would remain in control of the update process. The only problem, and a minor one at that, would be the installer app would need to wait until the Code Toaster process had successfully exited before beginning the install. So step-by-step, it would work like this…

  1. CodeToaster.exe launches and downloads an XML file containing information about available updates.
  2. If an update is available, CodeToaster.exe asks the user if they want to go ahead and download and install the update.
  3. If the user wants to install the update, CodeToaster.exe initiates the download.
  4. Once the download is complete, CodeToaster.exe launches the installer application, and then exits.
  5. At this point the installer must wait until CodeToaster.exe has finished exiting, and then launch the update .msi file that was downloaded earlier by CodeToaster.exe.
  6. Once the msiexec process has exited, the installer app can re-launch (the now updated and bodacious than ever) CodeToaster.exe, and way the user goes!

Whudya think? I think I like it. That’s the route I will probably take – there are a lot of steps but I think it’s more elegant than having a proxy app between the user and your application. Howsomever, there may be someone out there who knows better – if so let me know.

On another note, I’ve noticed that Windows Installer packages are quite difficult to update. You can’t just run an msi containing a minor (version) update, because you’ll get an error message that says ”Another version of this product is already installed.”

Well, duh! I want to update the version that is already installed!!

So you have to run your msi using the following command:

msiexec /i MsiFileName.msi REINSTALL=ALL REINSTALLMODE=vomus

Don’t ask what “vomus” stands for. I couldn’t find an adequate definition/explanation on Google within my 5-second attention span. But this is another reason to use an automatic update design instead of asking the user to run an update msi manually. Ask a user to do that to update your software and they’ll hate your guts and call you names.

This, too, is documented in the WiX tutorial, lesson 4, if you’re interested in some late night fireside reading while your hunting dog naps beside your overstuffed armchair.

So, looks like I have some work to do.

Onward.


Software Success (an essay on true love)

October 26, 2007

…and how to get the love back.

Over the last 12 years I’ve worked with a lot of software developers that would fit this description. Totally bored with their job and willing only to do the bare minimum: just enough to get by.

I think I know the explanation for most of these cases, if not all. They don’t love what they do. I got into programming because I loved doing it. After I wrote my first computer program, in QBasic over 15 years ago, I was thrilled that I could control what my computer did. I felt empowered, partially because I found myself capable of doing something that previously seemed beyond my grasp, but also because I saw the possibilities: given enough time it would be conceivable to do practically anything! The first thing I did was write a program to help my teacher parents record grades. A few years later I wrote a WYSIWYG editor in Borland Delphi for creating JAVA user interfaces, which helped me get my first job. This stuff was fun!

But that was 15 years ago.

What about today, when LEGO is selling programmable robot toys! And Microsoft has an entire framework for interfacing with robots and other electronic devices. Given enough time, it’s conceivable to build practically anything! How can you not love this wonderful craft? There’s always something new to build, a new problem to solve, a new way to impress your family and friends and be called “that super geeky whiz kid” for the thousandth time.

I believe this is a craft that must be loved before it can be done well. If you love what you do, you’ll try to do it better this time than you did last time, every time (and you can quote me on that). A developer that throws himself into his craft will probably know about design patterns and whether a Hash Table is better than a Linked List in this particular scenario, or whether this database query result needs to be cached, and on and on.

Joel Spoelsky’s 5-step list to software failure unfortunately (but I think correctly) lists bad programmers as the number one reason for software project failure. I totally agree. But I think we could expand on that a tad, by saying software developers that don’t love what they’re doing, that aren’t motivated by an insatiable desire to solve problems, or that don’t care anymore, are the number one reason for project failure.

Because if you love software development, you will be a good software developer. And if you don’t love software development, you can still fall back in love. Yes my friend, there’s still hope. Read some blogs, buy some books, but most of all (I think), start an interesting side project that you can do at home for a few hours a week that will bring the love back.

Here are some “feel the love” suggestions:

  • Build a robotic CD burner using LEGO Mindstorms that will pick up a CD from a stack of CDs and insert it into a CD burner. Program it to burn copies of various CDs stored in a database (or whatever).
  • Write a home document management system application that will scan, OCR, and store in a searchable format all of your personal documents, like Mortgage, Tax, and other stuff. How cool would it be if you could search your computer for that stuff instead of having to root through a file cabinet?
  • Grab a 15-inch LCD touch-screen, an old (or cheap) Windows XP PC, and hook it up to some of those X10 home automation components. Build a spiffy looking user interface for automating your home, and hang it on a wall somewhere for walk-up convenience.
  • Write an application for a friend or family member. Maybe your church or other organization needs an application to send emails, parse data from files, or whatever. Who knows – if you do something well for someone else, it could lead to other, perhaps paid opportunities.
  • Teach your kid how to program. My 7 year-old son just wrote his first “Hello World” QBasic application, and I was so proud. Passing on the joy of watching something you made just work is a great way to bring some of the fun back into programming.

If you’ve lost the love, get up and do something about it. It’ll make you a better programmer.


Code Toaster 0.8 Released

October 23, 2007

There are still a few outstanding bugs, but since this release is infinitely more stable and usable than previous versions, I decided to go ahead and release it as is (and also since interest in Code Toaster seems to be picking up lately).

I plan to release an update in a few weeks with more improvements, as well as bevy of useful template projects and hopefully some video tutorials.

Be forewarned, there is a learning curve, but so far everyone that has climbed the mountain has fallen in love with what this little tool can do.

Please leave any feedback as a comment, or feel free to email me at rmblack at gmail.


Buggy Software

October 23, 2007

Jeff Atwood makes an interesting point over at his Coding Horror blog, that often times features are more important (from a financial standpoint) than fixing bugs. That people are more willing to pay for an impressive feature matrix than a laundry list of bug fixes that may or may not directly impact their work.

I agree.

In fact, in some cases not fixing bugs can play a bug part in the overall financial strategy. For example, I used to work at a software company (which shall remain nameless) which happened to have a monopoly in their market. There was literally nowhere else to buy similar software. Their software was horribly buggy, and so they encouraged customers to purchase a rather highly priced support contract entitling them to, more or less, call support.

In their defense, I don’t think this strategy was intentional – it was an (un?)fortunate side effect of what Jeff blogged about – to sell a product, new features are often more important than bug fixes. And boy did they have an impressive feature matrix. It was ginormous. Anyone comparing products would be silly to even consider a product with a lesser feature matrix, despite the fact that you might be able to save your data without risk of the application blowing up in your face.

I disagree.

On the other hand, in some cases, particularly for small startups, lots of bugs can mean instant death. I later worked as the Webmaster (back when it was still cool to be a Webmaster) for a popular web-based practice test provider. The entire staff was comprised of about 10 people, most of whom authored practice tests. The development staff consisted of me, my boss, and a contractor in another state that would occasionally do new development. With thousands of people using our site every hour, we didn’t have the resources to field calls about usability  or technical issues. The site had to always work – or else.

Balance and Counterbalance

Fixing a bug vs. just leaving it to fester has to be weighed against the time it will take, and the expected benefit(s), among other things. For example, when working in IT, we come across the occasional bizarre problem that only happens when a particular user right-clicks on a Tuesday under a full moon while winking her left eye. We could spend a week setting up a virtual environment and tinkering with different combinations of environment variables, installing and uninstalling different combinations of applications that may be the culprit, but is it really worth the time involved? Is the benefit there?

That depends too – if I worked for a hospital and the software in question monitored respiration or some such, it would most probably be worth the effort and time. But if it’s a Word template malfunctioning, let’s just reimage the user’s machine and move along.

The Feature Matrix

So, I think ultimately the feature matrix counts only towards influencing the initial purchase. If you have an impressive feature matrix but lots of bugs (like that company I used to work for), you can bet lots of users will start to think strongly about migrating to another product as soon as possible. And they’ll probably tell their friends not to even consider your product. And you’ll have a hard time getting positive product testimonies to plaster all over your web site.

Unless, that is, there isn’t another product for them to go to. In which case, you’re home free you nasty scoundrel, and you should offer a hefty support contract and start raking in the dough.


Funky Design

October 19, 2007

I was just browsing the web sites of a few design firms we’ve hired in the past, and was quite surprised at how bad this one is. That web site looks like Cousin Junie wanted to give “this HTML thing” a try.

This one here, on the other hand, seems a lot more “safe”. They probably won’t give me a site design that employes creative use of cockroach antennae, or weird swirly black and white backgrounds.

Oddly, the former (weird site) would probably be considered the “better” of the two firms. More creative, with more high profile clients. And a weirder web site.

Go figure.


Code Toaster 0.8 in Beta

October 11, 2007

The next minor release of Code Toaster, which I’m calling version 0.8, is being tested vigorously by myself and a cadre of enthusiastic code generators. We’ve discovered it works well until you point the included schema provider for SQL Server at a SQL Server 2005 database. SQL Server 2005’s “new” schema ownership model (where objects are owned by schemas, instead of users) is confusing the tarnation out of the schema provider. A fix is in the works.

Actually, previous releases of Code Toaster probably should have been dubbed alpha releases, because they only worked for my needs (i.e. while running within VS.Net), and were only barely ready for public release (including the version {0.50} currently available for download from my downloads page).

This next version will contain numerous bug fixes and enhancements, most notably:

  • Enhanced Intellisense support, including member documentation (if available)
  • Enhanced error tracking (squiggly lines under errors in code)
  • Automatic template output language detection and coloring. For example, if your template generates SQL code, Code Toaster will detect that and color the output for the SQL language. Automatic language selection is only available for a few common languages, however you will be able to manually select from 13 different languages, including PERL, PHP, Phyton, SQL, C#, and more.

Also to be included in the next release will be a very simple Data Access Layer project, called SimpleDAL, which will generate lightweight and (hopefully) easy to understand code for accessing data. I’m calling it SimpleDAL after looking at several other DAL generators which seem to do everything but calculate the earth’s orbit speed around the sun.

And it’s free… like the wind.


Web 2.0 Generators

September 28, 2007

AjaxFlakes.com just posted a list of the top 100 Web 2.0 generators. Generators for everything from buttons to animated “loading” images to rounded corners.

Yeah, yeah, we all know Web 2.0 is just a fancy word to get VC funding or whatever, but you’ve got to agree, Web 2.0 has spawned a lot of nice looking web apps.


SandDock

September 27, 2007

Earlier releases of Code Toaster used the infamous Weifenluo DockPanel suite for managing the tabbed window interface. I found, unfortunately, that since DockPanel uses full-blown windows (Forms, in .Net), there was some annoying flickering and performance involved when windows were shown or hidden programmatically. Also, I found the API was a little clumsy and nonintuitive. It took (me, personally) forever to figure out how to automagically pop up the Errors window if errors were discovered after compilation, like VS does.

So I tried out SandDock from DivElements. SandDock windows inherit from Control rather than Form, so they’re lightning fast without all that extra windowing baggage hanging around. And if you’re already using Forms for your windows (as I was), it’s really easy to convert – you just change the base class from Form to the SandDock “window” control (I forget the name at the moment). You can do that because Form inherits from Control; of course if you’re using Form specific functionality you might run into some issues, but I discovered none.

The SandDock API is a breeze – no need to consult pages of documentation to figure out how to hide or show windows. Very intuitive and easy for a lazy developer such as myself. It’s not free, but it’s very reasonably priced at only $169 per developer. I consider that a good buy if it will make my app look nice and slick and tidy.

Last night while tinkering with Code Toaster I discovered my SandDock trial had expired, so I went ahead and bought a license. I’m planning on releasing the latest and greatest incarnation of Code Toaster within the next few weeks, possibly along with a very simple DAL generator, appropriately called SimpleDAL.

Keep watching here for more updates.


Embedded Databases

September 26, 2007

As I noted in an earlier post, I’ve been experimenting with SQLite, a super-small super-fast SQL database engine. SQlite is a small C library that supports transactions, implements most of SQL-92, supports terabyte-sized databases, and weighs in at only 150KB. I’m finding that it’s just perfect for desktop applications that need to store and quickly retrieve data from disk.

SQLite databases are made up of one file, which you can name whatever you want, and which can be encrypted. There are tons of GUI tools (almost all selling for $60 or more) for creating and configuring SQLite databases, but (for now) I prefer the free SQlite Administrator, which is just about as good as it gets. This isn’t an Enterprise RDBMS here; I just want to create some tables, add some indexes and primary keys, and go develop something cool, and this gets the job done. And you can’t beat the price.

I’m using .Net, so I needed a .Net provider, and I Google’d across this bodacious ADO.Net 2 provider for SQLite, which amazingly can be used either as a .Net provider, or as a “regular ol’” SQlite engine with no linker dependency on the .Net runtime. That’s really neat. Not that I would ever need that – but that’s cool anyway.

I can’t offer my esteemed opinion on performance metrics or whatnot, other than to say that, so far, it’s fast enough. It handles some of Code Toaster’s Intellisense queries lightning fast, against a database of roughly 20 MB in size.

There are other alternatives in the world of embedded databases, most notably SQL Server 2005 Compact Edition, which is also free, and also lightweight, weighing in at a mere 1 MB. The feature-set offered by this database engine is waaay more than SQlite could ever offer (being that SQL Server has more resources and more developers and so forth behind it), but SQLite wins hands down over simplicity. Deployment of SQLite is just the engine (~160KB) and a database file. I haven’t personally tried, but I’m guessing deploying SQL Server Compact Edition requires messing with a merge module or some nonsense that I don’t care to worry with right now (I know, I’m being a lazy blogger. Shame on me.).

The big downside to SQLite, and perhaps a big reason why you would want to consider SQL Server Compact Edition, is this whole locking of the database thing. You can’t write and read at the same time, lest you (and your users) get a nasty error message. Which means if your application is threaded in any way shape or form, you’ll probably need to use a flag, a Mutex, or somethin’ to keep from blowing your app to the moon.

That sounded bad. It’s really not that bad. I like SQLite. Seriously, overall I think SQLite is a simple, sleek little database engine machine thingy, with a wonderfully small footprint that will more than foot the bill if you can afford to take a little extra care in your coding.


Salted Passwords, and Other Cryptographic Goodness

September 19, 2007

Thomas Ptacek’s response to Jeff Atwood’s post on storing passwords securely is going in my bookmarks for posterity. This post, actually both posts, should be required reading for anyone building secure web site.

Make that all developers, period. We should all have a basic understanding of how to store passwords securely, and how bad it can be if we don’t.

Some important lessons I learned:

  • Never try to roll your own “cute” security algorithm or whatever. Just use the solutions professional cryptographers have spent their lives perfecting. Your little algorithm may remain uncracked for years, until one day your customers’ credit card numbers (or worse) start showing up on some web site in Bangkok.
  • Always salt stored passwords before hashing to thwart rainbow table crack attacks.

This is good stuff.


Threading Issues

September 14, 2007

Microsoft has made threading brain-dead easy to implement in the .Net framework.

For starters, every thread you allocate will consume a Meg of memory, right off the bat. In .Net 1.1, that 1MB was reserved, but not committed until the stack grows into it. In .Net 2.0, however, the CLR precommits the whole stack for reliability.

But the main problem n00bs deal with when implementing threading is not memory, but issues of concurrency. Each thread may be doing its own thing for the most part, but at some point its  going to have to reach out and touch data outside of its little thread context.

But what if something else is already touching that data?

Mr. Mutex to the Rescue!

That’s where it gets tricky. And that’s where we might use a little something called a Mutex.

In .Net, a Mutex is implemented in the Mutex class. A Mutex is like a ball that gets passed from thread to thread. Whoever has the ball gets to run (and do stuff). If a thread doesn’t have the Mutex, it has to wait until it gets it.

To create a new Mutex you would just call it’s constructor thusly:

private static Mutex mut = new Mutex();

Up to this point we’ve just pulled a ball out of the locker room, so to speak. But nobody has it yet. From within a thread, we would call the WaitOne() method.

mut.WaitOne();

So the thread will sit here and wait, forever, if necessary, until it owns the Mutex. If it’s the first thread to call WaitOne(), the operating system gives it the ball and it does it’s thing. If it’s not the first thread, it waits and waits and waits, until another thread calls…

mut.ReleaseMutex();

…which, as it says, releases the Mutex. The thread is done with it… let another thread play for a while.

And this leads us to a very important point. A thread can call WaitOne() multiple times, but it must also call ReleaseMutex() the same number of times, or the Mutex won’t get released to other waiting threads. Which basically means your other threads that are waiting, waiting, waiting… will wait forever. Or until the “naughty” thread terminates (which, in .Net 2.0, will raise an AbandonedMutexException).

So a Mutex makes it relatively easy to control threading concurrency issues, although I’m sure some of you out there could concoct nasty horribly complex scenarios that would drive the sanest debugger mad. But you get the point.

Real World 

So how ’bout a real world example? Code Toaster uses the SQLite embedded database engine to cache some of it’s Intellisense data. The problem with SQLite is that while you’re writing data, no other reads or writes can be made, or else an exception is thrown. Which is kinda stinky. SQLite doesn’t handle concurrency very well, does it?

But it is lightning fast, and works extremely well for something like Intellisense, where lots of data needs to be searched and retrieved almost instantaneously.

Since Code Toaster uses background threads to cache Intellisense information from assemblies and assembly documentation files, this was obviously a problem. More than one thread couldn’t write to the Intellisense database at once, lest an exception be thrown. 

So naturally I used a Mutex to allow only one thread to write to the database at a time. Problem solved. Elegantly.

And lightning fast.


iPhone Price Drop

September 6, 2007

Apple has dropped the price of the 8GB iPhone to $399, and tossed the 4GB model, which nobody wanted anyway.

For the same price you can snag the new 16GB iPod Touch, which boasts all the features of the iPhone except for the phone. If you’re near a wireless hotspot you can even browse the web.


Sharepoint 2007 as Document Management System?

August 30, 2007

A couple of weeks ago I attended a Mindsharp Sharepoint Summit held in the beautiful Washington, D.C. My head almost burst with knowledge, because Sharepoint is a wildly complex tool, and Mindsharp does a fabulous job at training.

I would dare to say that Mindsharp may be one of the best training providers I’ve ever had the pleasure to be trained by. My class (the admin track) was led by Ben Curry, a Microsoft Sharepoint MVP who was clearly on the top of his game. Todd Bleeker led the developer track. Just look at Todd’s profile. Yeesh. These people have credentials coming out… their ears.

Microsoft Office Sharepoint Services (MOSS) has a host of new improvements over the 2003 product, which I was thrilled to see. For example, web applications are automatically provisioned on each web front end (WFE) server in your farm. Which is just brilliant. You can add a new WFE, flip a switch, and voila – a new IIS site is created, assigned a port, host header, the appropriate files are created, and you’re off to tell your boss how hard it was to add that new server.

The new Shared Services feature adds a new twist. Shared Services is the set of services that manages personal sites, user profiles, audiences, Excel Services, and the Business Data Catalog, for a set of a web applications. The new architecture allows greater configuration flexibility over Sharepoint 2003’s Shared Services. For example, it’s possible to create two different Shared Service Providers within the same farm, each with its own configuration.

Document management is a major component of life here at my law firm employer, and MOSS is almost ready to be a full-fledged document management system. Features like content types and built-in workflow capabilities make MOSS very enticing as a potential DMS, which some law firms like UK-based Lewis Silkin found hard to resist. Unfortunately, there are a few big ol’ bugs that still make it a little scary to use MOSS as your Enterprise DMS (just yet).

For example, one bug Ben Curry mentioned during training was with the document list Explorer view. You can open any document list in Windows Explorer, as though it were a folder. The path to the folder appears in the Windows Explorer address as a URL, for example http://www.portal.com/document%20lists/MyFolder/, but it looks just like a normal Windows folder! A user can copy, delete, cut, and paste files, and change the view (Details, List). Buckets of coolness.

But a problem occurs when you enable forced checkout mode, which you would want to enable if you were using MOSS as your DMS (Document Management System), because you don’t want anyone to edit a document without first checking it out. Checkouts should therefore be automatic. Checkins, unfortunately, are not automatic, so a user can copy a thousand files into this pseudo-folder (filling up your content database in the process), leave for the day, and because they never checked the files in you won’t be able to see why your content database suddenly filled up! That’s right, until the user checks in the files for the first time, nobody, not even an admin, can see the documents (note that this only occurs when using the Explorer view).

And no, you can’t turn the Explorer view ”feature” off, not without disabling WebDav, which disables lots of other important things too, like Sharepoint Designer authoring, among other things.

Fortunately, that little buggy is buried off in a rather obscure, hard to find place. For small-ish law firms, or small to medium-size businesses where a big-honkin’ Enterprise class Document Management System would be overkill, Sharepoint 2007 fits the bill very nicely. And I know many people are anxiously awaiting the next version (2008? 2009?), not just for the slate of new features sure to be included, but to see if Microsoft gobbles up all the DMS competition.


AJAX

June 19, 2007

Ajax (also known as AJAX), shorthand for “Asynchronous JavaScript and XML“, is a development technique for creating interactive web applications. The intent is to make web pages feel more responsive by exchanging small amounts of data with the server behind the scenes, so that the entire web page does not have to be reloaded each time the user requests a change. This is intended to increase the web page’s interactivity, speed, and usability.

- Wikipedia

No one wants to give Microsoft credit for it, but they invented AJAX. Years ago, when ASP was in its infancy, I played around with a framework Microsoft had put together called Remote Scripting. In a nutshell, Remote Scripting consisted of a JAVA applet that exposed a few methods you could call from client-side Javascript to return string values from the server. In other words, AJAX, albeit very simple.

I thought it was the coolest thing since the inception of the common gateway interface, even though the browser DOMs of the day just weren’t capable enough to really do supercalifragilistic stuff like fading elements in and out, gliding, sliding, and other eye candy.

And then came IE 5, which included the XMLHttpRequest object, allowing developers everywhere to dynamically request XML from a web server (via Javascript calls) and format and display the results dynamically in a web page. In IE 6, the XMLHttpRequest object was converted from a scriptable COM object into a component of the browser itself. And AJAX became easy.

The XMLHttpRequest object is AJAX. There’s a W3C standard that most popular web browsers have adopted that has made AJAX universal - the short list of browsers that have implemented XMLHttpRequest includes Firefox (from Mozilla 1.0), Apple Safari (1.2 and up), Konqueror, Opera (8.0 and up) and iCab. And today’s browsers are application development platforms in themselves, with support for all the sliding, gliding, eye candy you can code.

But to make it even easier to code AJAX, Microsoft has released their AJAX (previously ATLAS) toolkit for .Net 2.0, with not only extraordinary AJAX support built-in, but also a framework of gorgeous sliding and gliding effects that any design challenged coder can easily take advantage of.

And as of last month (May 2007), you can download Microsoft Futures, a collection of ASP.NET and Silverlight controls for developing crazy-cool applications.

I’m lovin’ it. Just lovin’ it.

I’m such a Microsoft fan boy.


Editing XML and XSL

May 15, 2007

Editing XML/XSL is easy. For simple documents, anyway. But what about ginormous XML files with wild and crazy structures?

Try the latest incarnation of Microsoft’s XML notepad, available for download completely free: Download XML Notepad 2007. XML Notepad provides handy-dandy tree view editing of XML documents (even big ‘uns), with built-in XSL preview so you can see what everything looks like after an XSL transform.

But alas, the XSL preview doesn’t automatically reload the XSL document for you. Which is a real pain if you like to switch back and forth between edit and preview mode to see what the output looks like after each subtle change.

It turns out there is an easy way to view previews. Just stick an xml-stylesheet node at the top of your XML document, like so…

<?xml-stylesheet type="text/xsl" href="Stylesheet.xsl"?>

…and load the XML file in IE. Then you can hit F5 all day long, and IE will appropriately refresh the XSL output.


Rapid Wrapper

May 14, 2007

Every now and then you need to create a wrapper object to keep things nice ‘n’ tidy in your code. For example, you might want to wrap the sealed SqlDataReader class with your own class, maybe called SafeDataReader (as in Rockford Lhotka’s most excellent CSLA.Net architecture), to handle null values gracefully so you don’t have to include checks for null values throughout your code.

Since SqlDataReader is a sealed class, you can’t inherit from it. Bummer. And creating a wrapper is a ton of work because of all the members exposed by SqlDataReader.

This is where CodeToaster can save you a ton of work by generating a fully functional wrapper class in less than 15 seconds!

To use the template, you will need CodeToaster (just updated today with a slew of bug fixes and enhancements).

Create a new template project and copy the wrapper template into it: get the wrapper template here.

Now, compile the project, and set the template’s properties thusly (depending on the class you want to wrap):

Now run the template, and you should end up with a bee-youtiful wrapper class that you didn’t spend a billion years coding.

[Disclaimer: I put this template together in about 30 minutes, so there may still be a few bugs. But this is a good example of what CodeToaster (and code generation in general) can do.]


The Google Phone

May 14, 2007

Rumors disspelled here.

OK, not quite. But I have done a fair amount of reading on the subject, and this article seems to put the most realistic spin on the fabled Google Phone (GPhone), rumored to be released by Christmas, 2007.

So here’s the gist:

  • The GPhone won’t be an iPhone clone – it will probably be a software product using someone else’s hardware.
  • It will probably be very cheap, maybe even free, paid for by advertisements. This would make it very appealing to billions of cell phone customers.
  • The phone’s strong point (and a very strong point it seems to be) will be providing location aware search results. So for example, if you’re getting off a plane at Chicago Midway and search your GPhone for “taxi”, you’ll get a list of taxis that service Midway.
  • Given that your phone can let Google know where you are, the possibilities are endless. Google Maps, for instance, could provide you with nearby restaurants, gas stations, and hotels at a button click.

The iPhone is targeted towards the type of people who need, and can afford, a $5 latte every morning. I think the GPhone, on the other hand, will quickly be picked up at your local retail store by… well, everyone else.

(I still think the iPhone is mondo cool.)


Liar, Liar

May 4, 2007

Wow, looks like even the Dean of MIT can’t tell the truth on her resume (she lied about which schools she earned degrees from).

We’re interviewing again for another .Net developer position, and as I’ve said many times before, I don’t even look at resumes anymore. It doesn’t matter…

  • what school you went to
  • which degrees you have
  • what certifications you’ve completed

…you can still be a complete moron, a lazy developer that never cracks a book, or a host of other disqualifiers.

But back to the topic at hand: lying seems to be quite rampant. Or maybe, people just don’t understand when they’re lying. A resume landed on my desk just the other day (which HR had already screened, incidentally) that listed MCSD as one of the candidate’s credentials. Next to MCSD was the abbreviation (TBD). Which meant the candidate hadn’t quite completed his MCSD certification. Huh.

So, why was it on his resume to begin with? I could care less if he’s trying to get his MCSD. That’s like saying “I’m trying to get admitted to Harvard”, or “I’m trying to learn programming.”

In the infamous words of Yoda, “Do, or do not. There is no try.”

Or if I could rephrase, “Don’t be puttin’ stuff on your resume that ain’t right.”


Microsoft Touch Desk

May 4, 2007

Wow. You have to watch this video. This is a research project, and likely something that won’t be in production for a loong time, but still very cool…


The List

April 13, 2007

It’s notoriously difficult to track the progress of software development projects, because it’s hard to get an idea of exactly how much work is being done. When someone is rocked back in their chair staring blankly at a whiteboard, are they thinking hard, or hardly thinking?

Which is why you’ve got to give customers something tangible to show what’s being done. Consulting firms know this – they produce a hundred pages of documentation for every hour worked (it can seem like that anyway). I’m guessing that’s also why you don’t hear of many consulting firms using a methodology light on documentation, like Crystal Clear (or Yellow) or XP (or any other Agile methodology).

In my case, I document like crazy both to keep my own sanity, and to Cover My Taters (CMT). My favorite form of documentation is the plain old list. I have lists of problems, list of tasks, lists of requests, and at least one of those lists is usually on my second monitor or displayed in a Google Desktop Widget for Quick Reference.

Besides helping me keep my sanity, lists are also great for easily communicating to management what you’re working on. The lists I create for my personal consumption are written in a form of shorthand that only I can make sense of. When I’m ready to create a weekly status report, or other formal documentation deliverable, I take a few minutes to word everything into something presentable.

There’s another reason lists are wonderful – they overcome one of the most confounding problems of communication: the paragraph (and its cousin the runon sentence). A paragraph of more than about 2 sentences causes the eyes to glaze over. People readily admit that they “didn’t read that [long] email”. But for some reason, people will read long lists (within reason).

Consider this paragraph:

My status for last week: I met twice with the Glindberg account to gather requirements for their accounting system. We will be meeting twice a week (on Thursdays and Fridays) through the end of Q2 to finalize initial requirements. I will be scheduling a prototype demo with Glindberg’s management team at the end of the month, and will need assistance from someone on our development team. 

And now consider this list, which I believe is infinitely easier to process:

Last week’s Glindberg status:

  1. Held two requirements meetings
  2. Will be meeting twice a week (Thursdays and Fridays) through Q2 to finalize requirements
  3. Will schedule a prototype demo with Glindberg management at the end of the month
  4. Will need developer assistance during prototype demo

Lists divide up a lot of information into manageable, easier to process, chunks of data. Like sound bytes on paper. They look good, and they make you look good.

I like it a lot.


Firebug

April 12, 2007

I read about Firebug in a copy of “Dr. Dobbs” while killing time on MARTA, and was quite impressed, just from the article. So last week when I read Jeff Atwood’s post about using Firefox (with Firebug) for javascript development and debugging, I had to give it a whirl.

And wow. I’ve been missing out. For years, Microsoft has done an excellent job of cavorting with the developer community, but Firefox is holding out a silver platter of goodies for all the web UI folk.

I still feel that IE makes a better browser for the casual user. Like my Mom. And probably yours. It’s reliable and easy to use – Firefox is still a little quirky with things like selecting the URL in the address bar (the text selects/unselects oddly sometimes). However, Firefox is a nifty tool if you’re concerned about managing your Bookmarks, debugging javascript, and using plugins to “enhance the browsing experience”.

Anyway, if you’re a developer, you’ve got to give Firebug a try. Despite what I said in my last post (which was really bashing Firefox-crazed users instead of Firefox itself).


Try Firefox. Do it. Now.

March 30, 2007

I just visited a web site (www.edu-hq.com) using IE 6 and was greeted by an enormous banner at the top of the page encouraging me to use Firefox. This is not the first such banner I’ve seen. It looked like this…

…and it hurt my feelings.

I understand a lot of people have strong opinions over their choice of browser, and many have completely lost their minds over the issue, but isn’t this a little over the top? The banner says to try Firefox because I’ll “like it better”. Why? Because, according to the last bullet point, I’ll be helping to save the world from Microsoft? Save the forests, heal the oceans, and all that?

Is is just me, or is the Firefox crowd starting to sound eerily like a horde of college protesters camped out on the dean’s front lawn? Instead of carrying banners down the sidewalk, they’re putting them at the top of their web pages.

Interestingly, the first two bullet points arguing for Firefox are about blocking popups, and how Firefox does it so much better than IE. OK, that may be true, but do I need to stop and download Firefox now, just to see your web site with the right margins and padding or whatever? And more importantly how can I block these banners urging me to switch browsers?

Seriously, the world is full of IE users. So adjust your beret, boot up your Mac, and fix your web site so it works in all browsers, not just the one you have a thing for.

[PS. I'm not really mad. But it's fun to write like I am, heh.]


Hotmail is for Newbs

March 30, 2007

This confirms my suspicions that Hotmail has gone down the dreaded route of uncoolness. GMail is in – Hotmail is out.

Actual quote (from above link):

You can’t pretend being an internet expert and use a Hotmail account at the same time.

Wow.


Sleazy Recruiters

March 26, 2007

Look at this job ad as seen on a popular developer web site:

windowslivewritersleazyrecruiters-f719image0.png

Well-Respected Consulting Firm, huh? Then why isn’t the well respected firm’s name in the ad? Hrmmmm?

And of course they need “brilliant” developers. No other kind will do, but knowing SQL is a plus, you see.

This is obviously a recruiter-posted ad, to which I say, “ARRRGGGHH!” If you’re looking for a job, try a board like the recruiter unfriendly jobs.joelonsoftware.com, where job ads can’t be posted at all without listing the hiring company’s name.

[And by the way, I'm perfectly satisfied in my current employment - I just spotted this ad on a web site and couldn't resist commenting.]


Productivity Booster

March 22, 2007

A few days ago I downloaded the latest update to Google Desktop Search, and was pleasantly surprised to find that they had updated the sidebar to look more Windows Vista’y. And there seems to be a good deal more quality widgets available. Coolness.

But aside from the coolness factor, this is a nifty productivity booster. As you can see from the screenshot, I’m using a ToDo widget, a Note widget, a Calendar widget (which displays my current Outlook calendar), and a few other extraneous widgets that display the nifty Vista-style clock and weather.

I’m loving the ToDo widget because I’m quite forgetful of late, and this is much more handy, visible, and neat than a collection of sticky notes, or even using Outlook’s Task list (because now there’s nothing to switch to – it’s right there in front of me). And the Notes widget is great for adding details about, for example, a current work item, which I can copy to an email and shoot off as an uber-detail status report when I’m done.

The calendar widget also provides a succint way of reminding me, at a glance, without having to flip to another app, which days I have meetings booked. And the image viewer widget pulls down family photos from a PicasaWeb RSS feed to remind me what my family looks like (the pic in the screenshot is of one of my month old twin daughters). I’m lovin’ it!

Of course, this wouldn’t work half so well if I didn’t have a monster wide-screen primary monitor, in addition to a secondary, smaller monitor, so I have plenty of screen real estate to play with.

In other (related) news, Yahoo Widgets 4 launched today. And they are very cool, with that nifty MAC-glossy look applied to all the widgets. I was hooked on version 3 for a while, until my PC started locking up for no good reason, and my CPU started getting pegged at odd times. An uninstall fixed the issue, which proved (to me) that Yahoo widgets were the culprit. Besides, who needs widgets floating all over your desktop, constantly needing to be moved because they’re in the way?

Google Desktop’s sidebar, on the other hand, doesn’t play nasty, and fits quite compactly in the sidebar. I like it. It’s a great tool in a great product – Google Desktop Search. Give it a try!


Web 2.0 is Script.aculo.us

March 21, 2007

If you haven’t gotten on the http://script.aculo.us/ bandwagon yet, grab my hand and swing aboard! This javascript library makes it ridiculously easy (if you can write code at all) to add eye-catching (and tasteful) animations to your application.

Also check out http://www.miniajax.com/, which also has some fantastic AJAX/Web 2.0 samples.

The whole Web 2.0 phenomenon is all about the idea that the UI matters as much as, or more than, the functionality. Apple already knew that. Microsoft is getting the idea with Windows Vista and WPF and WPF/E, and the new Office Ribbon. Who cares if your application has feature XYZ if its hard to get to? And once they can get to it, why not make the feature fun to use?

For example, when you delete a post from WordPress (note: I’ve only deleted draft/unpublished posts), the post fades away in the browser in a very nifty Web 2.0′y way, while it’s actually deleted via an AJAX call. Which makes it fun!

On the flip side, MS Hotmail is an example of how AJAX can’t do anything for a worthless piece of trash software (oops, did I say that?). Hotmail.com uses AJAX everywhere, but it still can’t seem to filter junk mail into the right folder. My Hotmail inbox is filled with hundreds and hundreds of junk mails, because now I’m so fed up with the thing that I only revisit my Hotmail account every month or so just to make sure I didn’t miss a message from someone important but forgotten.

So do make your site scriptaculous, but don’t neglect to make it work.