David's Mumblings

Python 'for' loops and 'else'

category: Programming
I discovered a fairly interesting feature of Python for loops: you can add an 'else' clause that is triggered if the for loop runs to completion without a 'break' statement. Read More → ^ TOP

Posted on 08/03/10 at 13:32:39 by dchaley (David Haley)
No comments


Odd APIs

category: Programming
I'm using an API that exposes two functions: (paraphrasing) "get_data" and "get_latest_data". The documentation for "get_data" says that it gets you the data -- ok, fine. But then the documentation for "get_latest_data" says that it gets you the latest data in the system. So why would anybody ever want to use the first function? Both are parametrized by date, so both allow reading historical data. It seems that you might as well call the functions "give_me_old_crappy_data" and "give_me_awesome_data"!

Oh well, hopefully an email to the authors will clear things up. ^ TOP

Posted on 03/08/10 at 13:31:53 by dchaley (David Haley)
No comments


Whitespace-sensitive languages

category: Programming
I really, really do not like whitespace-sensitive programming languages. The following code does not parse in Ruby 1.8.6:


if ($idf.size != $freq_table.size
    || $all_words.size != $word_indices.size
    || $word_indices.size != $idf.size) then
  raise "bad data: size mismatch"
end


To make it parse, you must either add backslashes at the end of the lines, or make it all one line. Either solution is IMHO terrible.

I don't get it. The parser should be able to tell that the expression isn't complete, not only due to the first parenthesis (which is optional), but also due to the fact that the "then" that accompanies the "if" has not yet been reached.

Ruby has many nice features but IMHO this is really not one of them... ^ TOP

Posted on 04/29/08 at 11:05:42 by dchaley (David Haley)
1 comment


Actual vs. Perceived Performance: progress bars

category: Programming
My friend Adam sent me this link to an article on actual vs. perceived performance. The gist of it is that by altering the rate at which a progress bar fills, even if the actual time it takes to fill the bar remains constant, you can change people's perception of how long it takes.

I think it's pretty interesting that you can make people think something is faster simply by making the bar move continuously and more rapidly towards the end, rather than have it increase in jumps and be slow to get started.

It also means that if you want to trick users, err, I mean, "improve performance" of your application, you can just fake the progress bars to not represent what's actually happening... ^ TOP

Posted on 03/03/08 at 03:44:57 by dchaley (David Haley)
No comments


Search engine crawlers

category: Programming
On February 17th, the Google crawler hit my blog 243 times, and PowerSet's crawler got me for some huge number as well. I don't have the exact number, but my log went from 12k to 210k -- I aggregate the Google hits into a single count, so the only change was PowerSet. (11kb is roughly 50 hits, so 210k-12k=198k is approximately 900 hits.) Not entirely sure why both hit the same day, or why they (esp. Powerset) hit so much in one day.

Too bad PowerSet is still closed and I can't even try searching for myself there! At least I can search for and easily find myself on Google. :-) ^ TOP

Posted on 02/20/08 at 16:26:09 by dchaley (David Haley)
No comments


Short and useful programming

category: Programming
I try to make it a rule of life to try to automate tasks when I can and when it's not too expensive. If I think that I'm going to be doing the same repetitive thing more than a few times, I try to come up with a way to script or otherwise automate the process using programming of some sort (even as relatively simple as an Excel spreadsheet).

Read More → ^ TOP

Posted on 12/17/07 at 01:34:46 by dchaley (David Haley)
No comments


Lisp and Machine Registers

category: Programming
I find it somewhat amusing that Lisp, which prides itself on being so high-level and conceptual etc., has language constructs directly related to the 'address' and 'decrement' machine registers. (E.g. the functions car, cdr, rplaca, rplacd...) Sure, the meaning is just 'first' and 'rest' (not that that's obvious by looking at 'car' and 'cdr', mind you), but to have names that are so tied to a machine architecture seems backwards to me for such a high-level language. ^ TOP

Posted on 09/27/07 at 19:50:15 by dchaley (David Haley)
No comments


Bad Global Variables

category: Programming
One of the first things they teach you in introductory computer science classes is to avoid global variables like the plague. As you get "older", you learn that what you're really avoiding is unprotected shared state where things can get really messed up. In some cases, global variables can make it simply impossible to do certain things without removing the globals (for example, re-entrance, or multi-threading).

At work today we discovered a rather big problem in Perl. There is a function you can call, each, that iterates over the key/value pairs of a hash table. Read More → ^ TOP

Posted on 07/10/06 at 17:54:38 by dchaley (David Haley)
1 comment


Messed up JVM

category: Programming
I implemented a small coroutine package in Java and was trying to time it. But while timing it I discovered very, very odd behavior of the JVM's "optimizer". As a test, I was seeing how long it would take to generate all strings of length 16 representing all binary numbers with 16 bits. (In other words, all possible combinations of 0s and 1s of length 16.) I was trying to see how fast the library was by comparing it to the same task in Lua which is rapidly turning into one of my favorite languages. Read More → ^ TOP

Posted on 05/24/06 at 21:49:45 by dchaley (David Haley)
6 comments


Litestep work

category: Programming
I've opened up a new section of my website on the Litestep shell environment. At the moment, all it contains is a brief introduction to Litestep and screenshots/explanations of my current working environment. I think it's pretty nifty, and it's a rather novel way of using the Windows environment. Most people who see my screen do a double-take, because it looks like Windows but isn't quite normal...

Anyhow, you might find it interesting. At some point I'll be putting up more details on things like the battery widget I wrote for Litestep (which you can see on the screenshots). ^ TOP

Posted on 05/01/06 at 03:29:53 by dchaley (David Haley)
4 comments