Monday, January 05, 2004
google to the rescue (again)

Of course, a quick trip to google, and I'm happy.

Or if not happy, then I'm better off than I was. But why is it so weird?

(added later)

In this regard, where you have to pass things as references rather than directly, it reminds me of when I first got a handle on pointers in C. It was weird, because I'd already figured them out in Pascal, but C's syntax was a little different. In C, you have to know what a thing IS, even if all you are doing is passing it along to the next bit. In Python, and in other languages that are OO and pass pretty much everything by reference, all you really care about is that by the time the thing gets to its destination, it's going to respond properly to the methods that you are going to call.

You don't care that it's a hash or an array or a scalar. In that regard, Perl forces you to look behind the curtain. You have to know more about what is going on than you want to. Python allows you to do a bit of encapsulation, even if you are not making your own classes. You can pass an integer the same way you pass a list or a dict. It just works.

Okay, really, this is just the complaining of a Python guy being forced to use muscles that he'd let atrophy. Nothing more. Okay, maybe I'm engaging in a little bit of righteous indignation, and maybe a bit of a religious war, but I dislike religious wars. Put your braces where you want. I'll figure out a way to read your code. Use vi or emacs or xemacs or whatever. Just pick the right one, or you're going to hell (grin).

10:42:39 AM    comments ()  trackback []  

exploring perl

Because I wanted to understand the SlimServer software for the SqueezeBox, and because I felt I should know more about those things that I complain about, I've been exploring perl again. I say again, because I learned it once, but then gave it up after coding myself into a corner a few times, and after encountering Zope, which forced me to learn Python, I never looked back.

But here I am, writing things that use @_ and (@foo)[1..4, 6, 9] and the like.

I even wrote something that said print "@foo\n" if (@foo);, which I swore never to do.

That's the thing about the dark side. It's seductive. You know you are doing something bad, and yet it feels so good.

Of course, then I tried to do something inane, like pass a list and a scalar to a function, and it all fell apart.

I assume that I'm doing something wrong, and that I also don't fully grok the perl zeitgeist, but heck, how hard could it be? People spit out hundreds of working perl programs all the time.

Here's my thing -- I wanted a function that took a list and a scalar as an arg. In that order.

Let's say that I have: my @t1 = 1..10; my $t2 = 23;, and I have a function "foo" that takes a list and a scalar as args, in that order.

If I call foo like this: &foo(@t1, $t2);, and in foo, I grab the args like this: my (@l, $s) = @_;, @l gets (1 2 3 4 5 6 7 8 9 10 23), and $s is undefined. If I grab the args like this: my @l = shift; my $s = shift;, @l gets 1, and $s gets 2.

Clearly neither of those are the desired results. Making the list the last parameter worked for the first arg parsing case, but not the second.

It also clear that I have no perl chops. I can read the code, and I can see what's going on, at least as long is there is no complex regex-fu going on. I suppose common-grade Perl-fu would defeat me as well.

10:38:38 AM    comments ()  trackback []