May 2010 Archives

monotony in development

| 1 Comment
As I keep working on the same types of problems in my $job, I don't have much to say in my posts here. I have been working on the same problems for a few weeks, and I have run out of neat things to talk about.

Here is hoping that I have something interesting to talk about tomorrow.
I have recently been asked to write some code that by itself is actually very bad code.

$sql = 'select * from table';
$sth = $dbh->prepare($sql);
while (@array = $sth->fetchrow_array){
  if($array[4] =~ /^text_.*_text_$somevar.*$/) {
Basically what is happening is that the hard work of the where clause is being moved from the sql server to the web server. When I suggested that this could be part of why our product is slow, I was told that adding a web server is much easier and cheaper than adding a database server.

So the next time this code needs to be modified, the developer will again need to muddle through the two differing filtering mechanisms, for the sake of not overloading our mysql server(s). 

Although I have not be expressly forbidden from making changes to the sql, any changes do need to be reviewed by someone who understands the much larger architecture better than I do.

Yapc 2010

It seems I will not be able to make it to yapc this year. I will miss all the conversations I have with all of you, and learning as much as humanly possible in three days. Perhaps next year I will have the opportunity to go to YAPC

Sorting interview question revisited

| 1 Comment
I had a lot of thought provoking answers to my question posed a few weeks ago.
Basically the problem posed was you have data in the format of  /^[a-zA-Z]+[0-9]+$/ and you want to sort it. The problem is that you want abc2 to be before abc10 because 2<10

By far the most beautiful solution was moritz's solution:
use Sort::Naturally qw(nsort);
nsort @list;
Today I had to rewrite a similar sort, so I decided to revisit this again. Today I was sorting timestamps in the following format:"MM/DD/YY H:MM [AM|PM]" Which is very similar to the above problem once you break the constituent part away.

Here I will show my sort function for the simpler data above, since it becomes trivial to add the date formatting once . The sort function is only two lines, which I think is really clever, and even readable :

@sorted = sort {
"$a|$b" =~ /^([a-zA-Z]+)([0-9]+)\|([a-zA-Z]+)([0-9]+)$/;
return $1 cmp $3 || $2 <=> $4 ; 
} @array

Basically we get $1-4 set by concatenating the two strings, and then breaking out the alpha parts and the digit parts, and returning the appropriate code depending on the compare values.

About this Archive

This page is an archive of entries from May 2010 listed from newest to oldest.

April 2010 is the previous archive.

June 2010 is the next archive.

Find recent content on the main index or look in the archives to find all content.