essays.ajs.com
Please come join me there, where I'll continue to share my thoughts on whatever comes to mind.
"How can anyone think that the ACLU is right in this case? I'm not an advocate of government involvement in most cases, but these kids have no idea what they are doing when they take these pictures and distribute them at 13 years old. Guess, what - pixels don't forget."
"By changing the name to Syfy, which remains phonetically identical, the new brand broadens perceptions and embraces a wider range of current and future imagination-based entertainment beyond just the traditional sci-fi genre, including fantasy, supernatural, paranormal, reality, mystery, action and adventure."
I'm doing a lot of work in Python these days, and while I like a lot of things about the language, and have even gotten over the things that initially bothered me, there are some structural things that make little sense to me. Autovivification (or more specifically, the lack of it) is high on that list.
In Perl, when you want to store the number of bytes of traffic that have been seen in a log file for a specific system on a specific day, you do something like this:
$logdata{$host}{$day}{bytes} += $number_of_bytes;
Nice and simple. In Python, that's:
logdata.setdefault(host,{})
logdata[host].setdefault(day,{})
logdata[host][day].setdefault('bytes',0)
logdata[host][day]['bytes'] += number_of_bytes
# UPDATE: note that this can be simplified to:
h = logdata.setdefault(host,{})
d = h.setdefault(day,{})
d.setdefault('bytes',0)
d['bytes'] += number_of_bytes
# It's still annoying, but certainly shorter.
The other item that comes up, here, is auto-quoting. I really miss being able to say:
$foo{bar}
rather than
foo['bar']
I don't know why I find quotes to be so cumbersome when I don't find brackets to be. It's just a feeling that I'm doing a lot of extra work to say, "this is the thing I wanted to look up." Then again, quoting in Perl is vastly superior on so many levels that it's a rather moot point. From the balanced quoting operators:
$pseudo-text = q{/\/\ & /\/\s};
$python = qq{a = { 'a':1 }
b = """Another '''day'''\nAnother \$"""};
$perl = q{$c = qq{Hello, world\n}};
to its powerful combination of regular expression text and code:
s{ perl \s* \{ (.*) \} }{ $1 }eesx;
Again, I love Python. It has a great object system and much cleaner function declaration syntax than Perl. I just wish it weren't so annoying sometimes (a feeling that I'm sure Python programmers have when using Perl). Perhaps someday, those of us who enjoy both languages will get together and write a new one. Maybe we'll call it Ruby. ;-)
A friend of mine just asked a question I've been asked many times before. I'll re-phrase his question in a different way than he asked it at first:
How do I evaluate a string from user-data safely so that I can gather configuration settings from an external file?
This is a really common situation. What you often see in Perl code is something like this:
if ($config =~ /^\s*set\s*(\w+)\s*=\s*(.*)/) {
eval "\$$1 = '$2'";
}
and as my friend rightly pointed out, this is not only dangerous, but really just asking to be ostracized from the company of your peers. What you're asking Perl to do is to evaluate a random string as if it were valid code. What if that ".*" matched something with a single-quote in it? What if that "\w+" matched the name of one of Perl's internal variables or one of your program's variables?
I don't think that I have to point out how wrong it would be to make a dance mix of Rain (from the Cowboy Bebop soundtrack, which restored my faith in Japanese musical artistry), but someone felt the need to do it. My eternal complaint about Rain is that there are two versions on the C.B. soundtracks. One is by a female artist who has a lovely voice that's just perfect for the song, but she gets the pacing rather muddled and occasionally ends up turning a slightly awkward line into a train-wreck of syllables. The other version is by a male artist who absolutely nails the song in terms of timing and flow, but he just doesn't have the voice for it. I've always wanted to hear the perfect version of this song... and now I get a third problem: the dance mix. Why? Why?!
Sigh.