Monthly Archives: February 2008

Net-Nannies Suck

So I finally signed up for Twitter, since that seems to be the hip thing to do, only to discover that the service is blocked at work.  Categorized as “Dating” by WebSense.  Just out of curiosity, is anybody in the world really using Twitter to hook up?  Half the information I need when researching a problem these days is on a blog, which is under the similarly scandalous category of “Personal.”  Seriously, we’re not children.  Just let us do our jobs, and judge us on the work that we get done for you.

We’ll Miss You, Eric

Last night around midnight while looking at Facebook, I discovered that one of my friends from college named Eric Myers died suddenly on Sunday evening.  The only warning signs were some flu-like symptoms.  I hadn’t spoken to him since I got out of school, but this still came as quite a shock.

I met Eric while we were pledging for Delta Chi Delta, our social club (kind of like a fraternity, but lose the booze and frat house and add Bible studies and devotionals).  Eric immediately became everyone’s favorite, and the unofficial leader of our pledge class.  He had a sort of casual charisma; he was the kind of guy that you’d follow not just because he could inspire you almost without thinking about it, but because you just genuinely liked to be around the guy.  In a campus full of nice people, Eric stood out because when he talked to you, you could tell he wasn’t just being polite, but that he really cared.  It’s no wonder we made him Vice President. 

You will be missed, Eric.  We’ll see you soon, but in the meantime, enjoy that mansion, robe, and crown. 

eric

MultiComparer

My friend and co-worker Kaelin was working on an application that was using a grid to display some custom objects, but wanted to be able to sort by multiple fields like you would do with an SQL query.  He came up with something that I think is pretty cool, and very reusable:

Public Class MultiComparer(Of T)

   Implements IComparer(Of T)

   Private _comparers As List(Of IComparer(Of T))

   Public Sub New(ByVal comparers As List(Of IComparer(Of T)))

      Me._comparers = comparers

   End Sub

   Public Function Compare(ByVal x As T, ByVal y As T) As Integer Implements System.Collections.Generic.IComparer(Of T).Compare

      For Each comparer As IComparer(Of T) In Me._comparers

         Dim i As Integer = comparer.Compare(x, y)

         If i <> 0 Then

            Return i

         End If

      Next

      Return 0

   End Function

End Class

 

 

Let that sink in for a minute… 

 

So, if you wanted to sort, say, a list of Person objects by last name, then first name, then birthday, you’d create a new MultiComparer passing in a list consisting of a LastNameComparer, a FirstNameComparer, and a BirthdayComparer (in that order).  Mad props to Kaelin for his understanding of generics!

Creating a Shiny Button in Paint.NET

Last post I talked about how easy it really is to create professional-looking graphics when you’ve got a decent editor.  Now I’m going to prove it to you!  We’re going to try to recreate this snazzy button from Mint.com:

button-signup

We might not be able to do it exactly, but it’ll be something with the same general effect.

Step 1:  Open up Paint.NET (or any other similar graphics editor) and set your canvas size to 140×40.  Set your primary color to (25, 108, 200).  This will be the outside border of the button.  Set your secondary color to (41, 129, 229).  This will be the main interior color of the button.

Step 2:  Choose the rounded rectangle button and set it to “Filled Shape with Outline” mode.  Create a shape that fills up most of the canvas.

step2

Step 3:  Next we need to do the “shine” on the top half of the button.  Select the first layer (the one with the blue rectangle) and choose the Magic Wand tool.  Set the tolerance to about 75% and click anywhere in the shape to select it.  Create a new layer on top of the other two.  Choose the Ellipse tool and set it to “Draw Filled Shape,” and make sure your primary color is still white.  Draw the ellipse starting above the top of the canvas and go down about a third of the way into the button.

step3

Step 4:  Go to the “Layer” menu and choose “Layer Properties.”  Set the opacity of the layer to about 85.

step4

Step 5:  Go to the “Effects” menu and choose “Gaussian Blur.”  Set the radius to 2 and click “OK.”

step5

Step 6:  If you’ll notice, there’s a kind of “glow” around the edge of the button.  To duplicate this, first go to the “Layers” menu and choose “Merge Layer Down.”  Then, pick the Magic Wand tool and set the tolerance to 25%.  Click anywhere in the darker blue section to select it.  Create a new layer.  Choose the Rounded Rectangle tool and set it to “Draw Shape Outline.”  Draw an rectangle just on the inside of the button in white.

step6

Step 7:  Do another Gaussian blur with a 3px radius.

step7

Step 8:  Now let’s do the drop shadow.  Flatten your layers again and choose the Magic Wand tool.  Set the tolerance to 75% and click anywhere on the button.  Create a new layer.  Choose the paint bucket and pick a light gray color.  Click inside the selected region to fill it.  Make sure your Layers window is open (F7), and click the down arrow to move the gray rectangle below the blue one.  Choose the Move Selected Pixels tool and hit the down arrow on your keyboard about 3 times.

step8

Step 9:  Do another Gaussian Blur with a 3px radius.

step9

Step 10:  Set the opacity of the layer to 135.

step10

Step 11:  Now put your text on top.  I couldn’t find something that looked like the font Mint is using, so I just used Lucida Sans.

step11 

Well, it’s not perfect, but I’m starting to get the hang of it, I think.  Play around with it a bit and see what you can come up with.  If you have any suggestions about the way I’ve done this button, I’m all ears!

Demystifying Web Graphics

One of the things that has kept me from doing freelance web work for a long time is graphics.  I’ve had no training in graphic design, and very little natural talent to speak of in the artistic area.  And let’s face it.  In a public facing site, the look and feel is what gets a user’s attention and keeps it, and thus determines a large part of a site’s success.  Your app could function perfectly and provide incredibly useful functionality, but if it looks like the web circa 1996, it’s going nowhere.  So I thought I was stuck.  I thought if I was ever going to be successful as a web developer, I would have to buy my graphics from a professional designer every time.

But a couple of weeks ago when the consulting company came in to demo some of their sites, I started to notice some patterns.  I’m not sure what clicked in my head, but I started to see what design details made the sites look modern and professional.  Now, don’t get me wrong, I’m not suddenly some master designer, but I figure if I can deconstruct what makes other sites look good, then I can try to apply some of those principles to sites of my own and start to grow my skills.

The one thing I saw almost everywhere was gradients.  Seriously, take a look around your favorite site.  Chances are there will be gradients all over the place.  Everything from backgrounds to buttons to form borders use them.  And they make a huge difference.  For example, take a look at this button from the ASP.NET forums site:

Pretty basic, but still modern and attractive.  Before I started really thinking about it, I probably would have settled for something flat and boring like this on a site I made:

Okay, but not great.  But if we use a gradient instead of the flat blue color, and make the bottom right half of the border just a bit darker, we get this:

See how we get that “3D” effect?  It’s a whole lot easier than I thought it would be.  The trend right now seems to be toward what I think of as “chunky” graphics, especially on modern, “Web 2.0”-ish sites.  Very simple shapes, but with a lot of depth and lighting to them.  For example, take a look at Mint.com.  The buttons, the leaf graphics, and the word balloons all use very simple techniques to give them a professional look.  This is great for novice designers like myself.  We can be trendy even while we’re still learning the basics.

One thing that helps out immensely is having a good graphics editor.  As Jeff Atwood has said, every developer ought to learn to use one.  And not MSPaint, you wimp. 😛  I’ve been playing around with Paint.NET, and I like it a lot.  It has features that can produce some very nice looking grpahics, but it doesn’t feel crowded or cluttered with unneccessary tools.  And, hey, the price is right!  😉  I’ve also heard some good things about The GIMP, if you’re feeling Linuxy.

So if you have only thought of yourself as a programmer, unfit to wear that black turtleneck, just give it a try.  Download a graphics editor and try to duplicate a nice simple button or logo from a site you like.  It’s easier than you think.

Unit Testing 101

In response to Chad
Myers
admonition to blog
now,
I’m going to try my hand at writing about a few of the topics he
suggested, starting with “Unit Testing 101.” I think these
entries will mostly be for me, to solidify my own understanding of
these topics. But maybe I can say something differently than the way
it’s been said before and help someone out a bit.

DISCLAIMER:
I do not claim to be an expert on this or any further topics
suggested by Chad. Feel free to correct me when I post something
that’s incorrect or misleading, but let’s keep it friendly. I’m
a newbie here, okay? 😉
Examples
will be in C#.

First off, why would
we need unit tests? We can already build applications that work
correctly without writing a single unit test. Why go to the extra
effort (and write the extra code) when we can get along just fine
without them?

The purpose of unit
tests is to verify that each particular atomic piece (usually a
method on a class) works correctly, independent of the code around
it. By testing a method in isolation, you can have greater confidence
that your method works the way you intended it to. Once you have a
reasonable level of confidence that methods work the way they are
supposed to, you can narrow down the source of a bug by eliminating
possibilities of where that bug might exist. Unit tests also help
when changes need to be made to a system. After you’ve changed the
way a method works, your unit tests can verify that the method still
works correctly.

To illustrate, let’s
look at a very simple method called
GCD.
As you might expect, this method will take two integers as
parameters, and return the greatest common divisor of those two
integers. You remember this from Comp Sci 101, right? 😉 The method
might look something like this:

static int GCD(int a, int b)
{
        int Remainder;
    
        while( b != 0 )
        {
            Remainder = a % b;
            a = b;
            b = Remainder;
        }
      
        return a;
}

 Pretty simple. So now, let's write a function to make sure this method returns the correct value for a given set of inputs.

 static void GCDOf10And25ShouldBe5() { Console.Write(“Test – GCDOf10And25ShouldBe5: “); int result = GCD(10, 25); if(result == 5) { Console.WriteLine(“Passed”); } else { Console.WriteLine(“Failed”); } } We can write other tests like this for our other methods, and call them all to produce a kind of report that will tell us which tests
passed and which failed. I know what you're thinking. “Brian, that sure is a lot of code.”
Yep. And repetitive, too. Lots of calls to Console.WriteLine. And what happens when the number of tests you have starts to grow?
You'll have a hard time picking out that one line out of twenty or thirty that says “Failed.”

Well, that's because I just showed you the old-fashioned way of writing unit tests,
using only what's available by default in the programming environment. If you're going to use unit tests,
you need to use a unit testing framework. There are lots of them out there, for just about every language you can think of
(and quite a few that you didn't know existed, most likely). A lot of them are in the “xUnit” family,
which means that they have their roots in a framework called SUnit originally developed for Smalltalk by a guy named Kent Beck.
I'm going to use one of those frameworks, MbUnit, in my examples. When you download MbUnit or other similar framework,
you get a set of libraries to use in your tests, plus a test runner console application (and sometimes a GUI version)
that will run all of the tests in a class or group of classes.

So lets rewrite that test we just made using MbUnit.

[Test]
public void GCDOf10And25ShouldBe5()
{
Assert.AreEqual(5, GCD(10, 25));
}

Well, that was a bit shorter at least. Lets take a look at what's going on here. That [Test] attribute up top is just to let MbUnit know
that this method needs to be called when we use the test runner. The only method we're calling, AreEqual, is the backbone of an
xUnit type testing framework. When the two parameters passed in to the method aren't equal, an AssertionException is thrown.
It is caught by the test runner and turned into a readable message. The test runner also keeps track of how many tests
and how many failed, and displays a summary once all the tests have been run.

There are tons of other features of this and other frameworks, way too many to go into here. If I've piqued your interest at all,
check out the WikiPedia article on testing frameworks and pick one for your environment.

Laymen’s Perceptions

  At work, my customers know that there is no way
that they could do the work that I do without some serious training
time.  But all too often after describing something they want done,
they utter those dreaded words, “That should be pretty easy, right?”
As is true with most professions, the work involved in software
development is both incomprehensibly complex and deceptively simple to
those on the outside.  Something as “simple” as moving an entry field
to another part of a form could take hours of work, depending on how
tightly coupled the system is to its user interface.  On the other
hand, something as “complex” as building a report that allows a user to
sort data, move columns around, and group things on the fly could take
the same few hours given the right tools.

It’s totally
understandable that people don’t know how complex a problem is and how
long it will take to solve.  The problem is that they think they do
know.  They try to base the estimate in their own mind on empirical
evidence from past projects (which can be misleading), or worse, the
raw visual complexity of the application.

I’ve also experienced
this outside of my corporate job.  About six months ago, I began
working on a small e-commerce site for a lady that goes to my in-law’s
church to get my foot in the door moonlighting as a web developer.  The
problem was, I had a budget of exactly zero.  That’s right, I did it
for free.  I figured the references I would get out of the project
would be well worth the time I put in.  But that meant that for every
feature I had to either find resources for free or build it myself.  (Visual Web Developer and PayPal Website Payments Standard
were godsends.)  I think I probably logged about 100 hours getting the
whole thing up and running, complete with a WinForms product
maintenance system. 

But now that I’m done and she would like
to recommend me to other people, I have a problem.  Her impression
about what something like that should cost is based on these chop-shops
that charge $350 for an e-commerce enabled site.  Am I really worth
$3.50 an hour?  You could argue that now that I’ve got an existing
codebase the time involved getting someone else set up would be
minimal, but what about sites that have other needs?  Do my prices
start at $350 but then jump up over $1000 as soon as anything outside
the e-commerce norm pops up?  I wonder how small consulting shops
handle the price issue…

I don’t suppose there’s any easy
remedy for this problem.  You just have to earn your users’ trust over
time that you know what you’re doing.

On Your Own

Today, I listened to a presentation from a company that my employer is thinking about contracting to do some design work for a site we’re rewriting and possibly a new CMS implementation for corporate stuff.  When the presenter talked about how he had founded the company three years ago after building a very successful previous business and then selling it.  Even though the company is still very new, it has contracts with some of the biggest companies in our area (which includes one of the biggest companies in the world).

I thought to myself, “This guy really knows how to make it on his own.”  The more I think about it, the more I think I’d like to own my own business.  Sure, there’s some risk involved, and you don’t have that security blanket that goes with a job in corporate America, but I think being in control of your own destiny is enough to swing me in the other direction.  I think it’s also the desire to build that I’ve written about previously, the drive to create.  I don’t think I’m anywhere close to having the kind of experience I need to be out on my own.  Of course, I could probably use that excuse for my whole career.  And I bet the hard part about it isn’t technical, but being able to build a customer base.  What do you think about being on your own versus working for somebody else?

Go Vote on Super Tuesday!

If you’re one of the millions of Americans whose state’s primary is today, please go vote!  This is the most impact many Americans have ever had on the primary process, with nearly half the states in the union voting today.  Please take advantage of your privilege and fulfill your civic duty.

Taking the Plunge – Ubuntu

Call me a copycat, but I decided to install Ubuntu on a partition on my laptop, just to see what all the fuss is about.  Honestly, part of what got me to try it was the fact that my father decided to use it exclusively on one of his machines.  Now, my dad’s no luddite, but he’s certainly not what I would call a hard-core computer geek.  I thought, “Okay, Brian.  If you’re going to be a real geek, have some stones and give it a shot.” 

The experience has been mixed so far.  Most everything works the way I would expect.  Wireless worked out of the box, which was very nice.  I still can’t get sound to work, however, and the troubleshooting docs I’ve found so far haven’t been very helpful.  My friendly neighborhood coffeehouse owner is a real Linux geek, though, so I may hit him up for some help with that.

My overall impression so far is that it is the polar opposite of a Mac as Jeff described it the other day.  Instead of having an extremely closed, almost game-console-like evironment where everything works because it was all designed to work together, you have a jungle of software and  hardware drivers to wade through that may or may not totally explode when used with the wrong command-line flag.  Even the way you obtain and install it feels very by-the-seat-of-your-pants.  It very much feels do-it-yourself, as opposed to the “We’ll take care m of all that silly computer stuff for you, you just concentrate on watching YouTube and checking the weather” vibe I get from a Mac.  The Mac and Linux zealots seem very similar in their motivations for choosing a different platform, but to me Windows is actually somewhere in between the two in the compromise between out-of-the-box usability and freedom of customization. 

Anyway, I hope to start really learning ruby soon, now that I have the environment most people using it run on.  If I run into anything else interesting, I’ll be sure to post it.

Update:  Turns out enabling Gutsy Backports fixed my problem.  Anyone else with Intel’s ICH8 chipset, take note.  Thanks to linuxtechie for posting the solution.