Do you have much use for formats, protos, ties,...?

K

kj

I do a lot of Perl programming, and yet there are many Perl features
that I *never* find a use for, and I wonder whether this is because
these features are inherently not very useful, or it's me who is
being just too dense to realize what I'm missing. In decreasing
order "remoteness from everyday programming":

1. formats

2. prototypes

3. operator overloading

4. tied variables

I'm curious whether other Perl programmers find these feature
useless as I do, and if not (as is likely) when do you find any of
these features truly handy? I.e. what kind of programming task
would become for you significantly more difficult (or plain less
fun) to code if the feature were not available?

kj
 
C

Chris Mattern

kj said:
I do a lot of Perl programming, and yet there are many Perl features
that I *never* find a use for, and I wonder whether this is because
these features are inherently not very useful, or it's me who is
being just too dense to realize what I'm missing. In decreasing
order "remoteness from everyday programming":

1. formats

I actually used this once, but looking back at it, I should have
just used printf.
2. prototypes

3. operator overloading

In fact, you're already using this; you just don't know it. Perl does a
lot of behind-the-scenes stuff with overloading. And with tied
variable (see next), you're automatically using overloading; that's
how tying works.
4. tied variables

Now, this, on the other hand, is truly useful. I just finshed a
program that reads and rewrites selected lines in a data file.
Tie::File was *very* useful for this.
I'm curious whether other Perl programmers find these feature
useless as I do, and if not (as is likely) when do you find any of
these features truly handy? I.e. what kind of programming task
would become for you significantly more difficult (or plain less
fun) to code if the feature were not available?

kj

--
Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
 
T

Tad McClellan

There is another possibility:

or have you just not done a project that would have benefited
from the feature. (The "right tool for the job" thing.)

I actually used this once, but looking back at it, I should have
just used printf.


That isn't enough if you need word-wrapping or page headers though.

So there are modules for getting that stuff. :)

I'd count this one as "never used". There are now better alternatives.

I seem to remember that they will not be in the core of Perl 6
either, which seems to reinforce that position.

In fact, you're already using this; you just don't know it. Perl does a
lot of behind-the-scenes stuff with overloading.


Right, but here we were talking "Perl programming" rather
than "perl programming". :)

That is, their usefulness at the Perl Program (programmer's API) level.

My take on the above 2:

Prototypes are a cure that can be worse than the disease, not used.

Operator overloading would most often introduce "startle factor",
so used only in very special circumstances, eg: when you are
implementing some domain-specific language in Perl.

Now, this, on the other hand, is truly useful.


<aol> Me too! </aol>
 
K

kj

In said:
There is another possibility:
or have you just not done a project that would have benefited
from the feature. (The "right tool for the job" thing.)


That isn't enough if you need word-wrapping or page headers though.
So there are modules for getting that stuff. :)
I'd count this one as "never used". There are now better alternatives.
I seem to remember that they will not be in the core of Perl 6
either, which seems to reinforce that position.


Right, but here we were talking "Perl programming" rather
than "perl programming". :)
That is, their usefulness at the Perl Program (programmer's API) level.
My take on the above 2:
Prototypes are a cure that can be worse than the disease, not used.
Operator overloading would most often introduce "startle factor",
so used only in very special circumstances, eg: when you are
implementing some domain-specific language in Perl.


<aol> Me too! </aol>


Talk about startle factor, I'm kind of down on tied variables
because last week I spent a lot of time chasing a bug whose root
cause I'm sure is in some variable-tying nonsense in one of the
CPAN modules I was using (Filter::Util::Call). I didn't fully
track down the bug, but, in a nutshell, the act of assigning $_ to
a lexical variable would cause $_ to become undef. As in,

my $x;
$x = $_;
print "\$x: $x\n\$_: $_\n"; # *immediately* after the assignment,
# and in the same scope

=> $x: 1
$_:

Perl is tricky enough out of the box without any further attempts
at tie magic. These tied variables seem to sharply add to the
potential for befuddlement.

kj
 
B

Brian McCauley

kj said:
I do a lot of Perl programming, and yet there are many Perl features
that I *never* find a use for, and I wonder whether this is because
these features are inherently not very useful, or it's me who is
being just too dense to realize what I'm missing. In decreasing
order "remoteness from everyday programming":

1. formats

2. prototypes

3. operator overloading

4. tied variables

I agree with the ordering. I never use formats. I almost never use
protypes.

Operating overloading and tied variables are handy when writing a module
that wants an elegant API. Since most prograqmming is either one side
or the other of an API it is true that actually implementing the API
itself is not an every-day task. I would however sorely miss these
features were they absent.
 
X

xhoster

kj said:
I do a lot of Perl programming, and yet there are many Perl features
that I *never* find a use for, and I wonder whether this is because
these features are inherently not very useful, or it's me who is
being just too dense to realize what I'm missing. In decreasing
order "remoteness from everyday programming":

1. formats

Never used them.
2. prototypes

Never define my own subs to use them, but I do benefit from subs from other
modules (e.g. List::Util) which do use prototypes.
3. operator overloading

I don't use them directly, but I think I do benefit from their use in
modules which I am never explicitly made aware of.
4. tied variables

I occasionally use this directly, like Tie::File and some hash cacheing
module I don't recall, but find them only marginally useful. I may benefit
more from using it indirectly without knowing it.

I'm curious whether other Perl programmers find these feature
useless as I do, and if not (as is likely) when do you find any of
these features truly handy?

I've used tied variables to make large data structures more memory
efficient without having to recode the whole program.

Xho
 
B

Big and Blue

kj said:
I do a lot of Perl programming, and yet there are many Perl features
that I *never* find a use for, and I wonder whether this is because
these features are inherently not very useful, or it's me who is
being just too dense to realize what I'm missing. In decreasing
order "remoteness from everyday programming":

1. formats

I use this is some "quick-information" scripts to wrap output (*and* I
set the variable which determines where the long line may be split).
2. prototypes

Used to check that I use the function correctly within the same file.
3. operator overloading

Never used this directly.
4. tied variables

Used to dump the contents of dbm files (useful for NIS tools).
 
J

Jim Keenan

kj said:
I do a lot of Perl programming, and yet there are many Perl features
that I *never* find a use for, and I wonder whether this is because
these features are inherently not very useful, or it's me who is
being just too dense to realize what I'm missing. In decreasing
order "remoteness from everyday programming":

1. formats

Used them in the first Perl program I ever wrote. Use the 'formline'
function which powers them a lot to this day.
2. prototypes

Never directly.
3. operator overloading

Never directly.
4. tied variables
Tie::File: every day. Lately some use of tied filehandles in testing
STDIN (a module I developed myself based on Camel book examples) and
STDOUT (IO::Capture::Stdout, IO::Capture::Stdout::Extended). But the
dirty details of tying are wrapped up inside these modules, so that I
don't have to think about them at the script-writing level.

Jim Keenan
 
P

phaylon

kj said:
1. formats
Nope.

2. prototypes

Jap, for any less-complex often-to-use functions.
3. operator overloading
Nope.

4. tied variables

Only for experimental/debugging. I always have this 'slow'-feeling when
I'm using them.
I'm curious whether other Perl programmers find these feature useless as I
do, and if not (as is likely) when do you find any of these features truly
handy? I.e. what kind of programming task would become for you
significantly more difficult (or plain less fun) to code if the feature
were not available?

I would just say every coder has his own favorite "tools".


p
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top