Posted on Leave a comment

Overthinking the problem

As a programmer, I solve problems. For my clients and myself it is important that I solve the problems as efficiently as possible with the caveat that the efficient solution must be scalable and have enough foresight as to cost effectively allow for unpredicted modifications in the future. A trap that developers fall into is overthinking the problem.

Imagine walking out of your house and realizing right as the door closed that you left your keys beside the television. Your mind races. You get all MacGyvery and start looking for a paperclip to use with your pocket knife as a makeshift lock pick. You ponder knocking out a window pane or lowering yourself down the chimney. The schemes escalate and become more elaborate. This is how a programmer overthinking the problem creates unnecessary levels of complexity which can lead to buggy code. The solution could be as simple as checking the other doors to see if one is open or getting the spare key from the neighbor. Or even more simple, doing a sanity check by confirming that the key is not in your pocket. Perhaps you didn’t even lock the door which is now the subject of your ornate plotting.

How can a programmer prevent overthinking a problem and wasting time?

  • Sleep! Sleeping on a problem gives the mind clarity. Sometimes we dream the solution and sometimes the break is enough to see the error in our ways.
  • Take a break! Similar to sleep, a diversion such as juggling, exercising, breathing fresh air, or working on a different type of problem can jolt our minds into seeing a simpler solution to the original problem. I highly recommend getting away from the computer but don’t abide by that myself. Often I will solve a sudoku puzzle or write a blog post to shock my mind into seeing a different solution.
  • Talk to peers. Other people’s input is often helpful in seeing a solution. With programming, like many aspects of life, there can be many solutions to the same problem and others can inspire us with their approach to solving the problem. If you work by yourself like I do, find peers online with IRC or Twitter.
  • Outsource. If a problem is being very difficult, give it to someone else. They may find it less complicated and it frees you to work on something different.

Using the same techniques writers use to alleviate writer’s block can cure coder’s block. Now I must return to the problem that I overcomplicated by overthinking it.

Posted on Leave a comment

DailyWTF

I wrote this piece of rocket science last night:


<select id="birthdateyear" name="birthdateyear">
   <?php for($byear = date("Y",time()); $byear >= 1901; $byear--){ ?>
      <option value="<?php echo $byear; ?>" <?php if($birthdateyear == $byear) echo "selected"; ?>><?php echo date("Y",mktime(12,1,1,1,1,$byear)); ?></option>
   <?php } ?>
</select>

And that is why you shouldn’t code tired.

Posted on Leave a comment

Today’s basic HTML question

Can <optgroup> be nested within <optgroup>? Is the following example legal?

<select>
   <optgroup label="A">
      <optgroup label="1">
            <option>Outlinepart1</option>
      </optgroup>
   </optgroup>
</select>

Answered! Optgroups may NOT be nested per HTML4 specification.

Posted on 3 Comments

Programming self into corner

With programming, over thinking a problem is a common pitfall. Sleeping on a problem often results in a quick solution for the mere fact that you quit thinking about the issue long enough to see the simpler solution. As we contrive our Rube Goldberg devices to solving programming challenges, we become like plumbers simply adding more pipes to divert the water to the end result. Quickly we paint ourselves into a corner and waste valuable time. I am there right now on what should be some simple css.

If I have a <tr> that has a class <tr class="foo"> and the <td> within the tr has an <a href> how do I style the anchor?

Before anyone jumps on the "Don’t use tables" bandwagon, this is semantically correct because the output is tabular data.

The solution should be tr.foo td a { }. But nothing changes. CSS is not magic; not spooky. CSS is relatively simple, and fun! But hiccups like this drive me to the brink!

Posted on Leave a comment

Spam Karma open source or die die die

In case you missed the announcement, Dave who developed Spam Karma is no longer going to make changes or update the code. Instead he has released it as GPL v.2 and created a Google Code repository in hopes that some talented people will pickup where we he leaving off. I wonder if we Spam Karma users had actually donated money toward his efforts if he would have continued.

Spam Karma puts Akismet and other spam fighting tools to shame. I think in all the time I have been using Spam Karma, I have had only one false positive. I get false negatives on trackbacks but that is because it was only recently that I realized I could change the settings for how Spam Karma handles trackbacks so I’m still making adjustments.

I also found Dave’s comments on a WordPress replacement very interesting. Specifically he notes, "If you look at it, blog systems are over 10 year old now. Their UI have barely evolved since the first versions. … There is a bad need for a groundbreaking platform that would get rid of ten years of accumulated UI habits."

Posted on Leave a comment

What do I do?

Frequently people will ask, "Now, what do you do?" Which is a really hard question to answer without people making the wrong assumption, "Oh! My nephew just took a class on that at his high school. He does the same thing." Videos better explain my job:

Of course, that doesn’t apply to any of my clients who read Reality Me!

Posted on Leave a comment

Bring Me A Rock

When talking about software development and software quality assurance processes, I love to talk about the "Bring me a rock!" scenario. I found these renderings of a rock rather amusing. Of course, there are no coffee grounds in the house so that could be a contributing factor in the humor.

I also enjoy talking about delivering a baby in one month by using nine women. And I love the ugly baby syndrome. But those are for later.

Posted on 4 Comments

Do you store images in a database?

As I have built PHP and ColdFusion applications over the years, I have had to deal with image and file uploading from the application. Browsers were not designed for moving files from a client to a server; specifically, browsers were designed to receive files from a server to a client. To move files from a client to a server, an FTP program is used. (My favorite FTP client is WinSCP.) Now, a form can be written and used to upload a picture, movie, or other file from the client (you) to the server. You probably do this quite frequently with Flickr, Youtube and so forth. It is convenient from the enduser point of view because it removes the need to learn new software (the ftp client) and prevents having to get an administrator to create a username and password for each user on the server. Plus, by managing the files through the web application instead of the FTP program, you can programmatically control what is being allowed onto the server so that your user doesn’t maliciously upload an executable designed to damage the server rather than that family vacation photograph.

As a programmer, I have to make decisions about where to store these uploaded files. A common approach is to have a directory on the webserver which cannot be accessed by a browser (that is, the only way to get to the file is through the programming). The filename is then stored in the database. As an independent consultant, I work with different programmers/designers with varied skillsets and differing philosophies on coding. Some coders, like Eric Wise, actually prefer to store the files in the database itself. Eric claims:

…this is pretty sloppy and difficult to manage especially if for some reason you want to reorganize the data… [Source, Eric Wise, Images, Thumbnails, SQL Server, and ASP .NET – Level 200]

Eric describes a process of storing images in SQL Server 2005, automatically compressing the images, and generating thumbnails using ASP .NET. THis is interesting to me as I am wanting to learn C# to add to my skillsets.

I am concerned about database size and performance decreased caused by storing images/files in a database rather than storing the file in a directory and only storing the filename in the database. Jeffrey Palermo, a commenter on Eric Wise’s post, expresses the same concern:

Jeffrey Palermo said:

I’ve considered doing a photo album this way, but the main drawback is the size it makes the database. I have about 4GB of images. Do I really want that much in my database just for images. That also makes the bandwidth between web and db server highly used. Perhaps it’s no big deal, but to date I’ve kept my photos on the web server. Please post if you find no issues with the size of the data in the database when you have _lots_ of pictures there.

And Eric responds:

Eric Wise said:

Jeff,

With the compression tool I referenced, the original image shown was over 2MB, now it’s 165KB.

Having many large files would definately cause a performance issue, but with compression and the fact that it will probably be rare to have more than 2-3 pictures of an asset I’m not all that concerned about it.

What is your approach to storing images from a web application? See also.

Posted on 2 Comments

Cutting a plugin loose – Goodbye WP-Project

I liked the concept of WP-Project. It’s a WordPress plugin which adds a tab in your dashboard for project management. It was inspired by Basecamp (collaboration piece for project management) and Harvest(er) (a timetracker). Conceptually we like to spend a lot of time in our dashboards so why not do our project management there too? I just didn’t find the plugin robust enough for my needs. And if it was robust enough, I’d be concerned that my database, which already has issues with Spam Karma eating its space, would fillup too quickly. (n.b. The database has a 100MB allocation.) For now, I’m going to try out Zoho’s project management.

Posted on Leave a comment

WordPress Support on IRC is on Freenode

For those looking, WordPress.com support on IRC is on the Freenode servers at #wordpress.com while WordPress.org support is on the Freenode servers at #wordpress. #wordpress.com is primarily WordPress.com developers/employees and staff of Automattic while #wordpress is the open source community.

Posted on Leave a comment

Today’s Technical Challenge

I like the semantic web. That means that when I create a website I use markup as its intended. We used to have to use tables to make elegant layouts. Browsers have matured and become more compliant to the HTML specification. Now tables can be used for tabular data; however, designers still have tools which cut and slice designs up into tables rather than using CSS. Tables have their place in HTML. Specifically, tables use be used for presenting tabular data but not for arranging graphics or chopped up pieces of images in the browser window.

Menus and navigation are lists semantically speaking. Of course, no one wants to see a menu with a bunch of dots beside it nor should ever menu be presented as a vertical list with indentions for submenus. Using CSS we can remove the bullets, turn the list horizontal, and make the submenus appear as submenus when the mouse rolls over the navigation. This works great in a browser and because of the semantic nature will present well in a pda, phone or other mobile device. However, the WYSIWYG editor in an email client wreaks havoc on the page. "Huh?" is the correct response because really web pages, particularly dynamic web pages, should not be sent by email. Instead a link to the web page should be sent. BUT Internet Explorer is kind enough to provide under its FILE menu (PAGE menu in IE7) an option to "Send Page by Email" which in theory will deliver an HTML email that is an exact representation of the web page.

In reality, in a specific case which has not been narrowed down yet, the CSS menu is rendered with conditional comments.

<!–[if !supportLists]–>o<!–[endif]–>

Obvious steps have been to make sure that IE is upgraded to IE7 and that the email client is updated. And to confirm that the email is being sent as HTML and not plain text. Aside from returning to a tabled design, what other options should be explored?

Posted on Leave a comment

Collation?

You mean like getting the papers from the copier in order?

You know, I have probably exported and imported data from hundreds of databases at this point in my life. And never, I say never, have I ever had a collation problem. Collation has to deal with how a database handles issues of sort order, case sensitivity, and sensitivity to accents. It becomes important when your database is not US centric or is going to serve an International audience. Last night it got me.

I tried directly updating data on a server that is probably located in Amsterdam and ended up with:

Cannot resolve the collation conflict between "Latin1_General_CI_AS" and "SQL_Latin1_General_CP1_CI_AS" in the equal to operation

Ugh.