programming/AnIntrospectionAdvantage written at 01:55:34; Add Comment
An advantage to introspection and an interactive interpreter
I spent part of today writing a very simple network server in Perl. While most of my problems were due to my ignorance, the experience did give me a new appreciation for introspection and interactive interpreters.
The problem is that without introspection, things are opaque when something goes wrong. What do you have? Certainly not what you expected, but it's hard to tell much more than that. With introspection, you can find out type information, maybe a printable representation of the thing (this gives you some idea if you're on the right track), and perhaps even lets you find out some of what you can do with it.
Perl has some introspection support, but it also has a tendency to make a lot of the socket things I was interested in into typeless, opaque strings. It was startling how different working in such a 'bare' environment felt.
An interactive interpreter taps introspection's power, because you can experiment without having to edit and restart programs. You grab the thing you're having trouble with, then fiddle around with it and see what happens; this gives you rapid feedback, so you can quickly refine and focus your fiddling and work out how to do what you want.
(Exceptions are also an advantage in this sort of exploration because they let you know immediately when you've done something wrong, and often give you specific details about what you screwed up.)
To answer the question 'why Perl (instead of, say, Python)': Solaris 9 has Perl has part of a relatively standard install, but not Python et al. And I would rather write simple networking programs in Perl than C.
Sidebar: introspection et al in Perl
Perl does have some addons for introspective and interactive interpreter features. The ones I've found and want to save for later reference:
I'm honestly surprised that
(Additional suggestions welcome.)
* * *
Atom feeds are available; see the bottom of most pages.