Code I Found

Its time for a new category here on my blog... I've been working through a good bit of older code at work and trying to update it to something like modern developer standards. Part of the fun of this has been finding weird, pointless language constructs. Check out this C# example:

if (IsEditable(ID))
    EnableEditButtons(true);
else
    EnableEditButtons(false);

Neat! This developer was able to use 4 lines of code to do one line of code:

EnableEditButtons(IsEditable(ID));

Do you have any good examples of code that just shouldn't have been?

Update!

The EnableEditButton() function from the last example is worth a look too...

protected void EnableEditButtons(bool Value)
{
    if (Value == false)
    {
        buttonAdd.Disabled = true;
        buttonDelete.Disabled = true;
    }
    else
    {
        buttonAdd.Disabled = false;
        buttonDelete.Disabled = false;
    }
}

Could be wrapped up as:

protected void EnableEditButtons(bool Value)
{
    buttonAdd.Disabled = buttonDelete.Disabled = !Value;
}

 

Why IIF() Should be Avoided

I was recently reviewing some code from one of my client projects and saw that the previous developer had liked to use IIF() functions to handle the conditional switching of things like button labels. I idly quipped on Twitter that Every time you execute IIF() an angel loses its wings. A few minutes later a request for some explanation came in on Facebook: Why's that? I like IIF(). Here is why you should avoid IIF().

 

When in Doubt Clear Your Bin

This is a reminder to myself, and anyone facing down a weird error message when trying to build their ASP.NET application: you need to try clearing out your Bin folder and rebuilding it. I've 'fixed' probably a dozen build problems so far just by clearing out my Bin and rebuilding the application. To clear your Bin folder:

  1. Find your project file in Visual Studio and left click it.
  2. Go up to the icons in your Solution Explorer and click 'Show All Files'.
  3. Find your Bin folder in your project, and right click it.
  4. Click 'Open File in Windows Explorer'.
  5. Select everything in the folder (Ctrl + A) and delete it.
  6. Rebuild your application.

I've got no idea why there were errors with my applications, or why this fixed them, but its always a good first line of defense. If you've got an error message you can't figure out, clean out your bin.

 

Lessons on setTimeout() and clearTimeout()

My world was rocked the other day while looking through some source code for a Javascript widget at work. Normally, I'm the one giving lessons in JS techniques, but I was absolutely floored to see how my coworker had used setTimeout() and clearTimeout() in ways I'd never seen before.

 

Getting Started with Cufon

I've been curious for a while about techniques for font replacement on the web. We've probably all heard about the idea of embedding fonts, but looking around at the standards right now, it doesn't sound like any one browser has things right, so I decided to explore a third-party option. Read more to learn about the basics of Cufon, an easy to use font "embedding" system.

 

Missing Data Types in Enterprise Architect

If you've used Sparx System's EA, you might know that its a quirky little program at times. I've come to love the power it gives me to document designs and interactions, even if I've had to give myself a crash course on UML just to get my head around it.

One thing I hate though is that sometimes things just don't work and its not obvious why its not working. When trying to create a Data Modeling Diagram to display the database objects involved in a proposed update, I found that the Data Types selection for my columns was empty: all the entries were missing. I was getting really frustrated until I checked on the table entity itself and found that Database for this table was not set. Once I changed to SQL Server 2000, my Data Type drop downs populated with the correct values.

In short, if you're using EA for a database diagram and your data type selections are blank, you need to check the database setting on the table itself.

 

More Entries

Jon Hartmann, July 2011

I'm Jon Hartmann and I'm a Javascript fanatic, UX/UI evangelist and former ColdFusion master. I blog about mysterious error messages, user interface design questions, and all things baffling and irksome about programming for the web.

Learn more about me on LinkedIn.