hash as argument

D

Dale Henderson

TM> The programmer's choice of quotes is a note to (him|her)self:

TM> "interpolation or backslash escapes are here!"
TM> or
TM> 'nothing special going on here'


This makes me wonder if perhaps 'This is a string' is faster than
"This is a string" because in the first example the interpreter
can just use the string as is. But in the second the interpreter
must scan the string looking for interpolation or backslash
and construct a new string to use.
 
D

Daedalus

Some more examples of saying that "something special" is going
on when nothing special is going on:

m/RE/s; # when RE does not contain a dot

m/RE/m; # when RE does not contain ^ or $ anchors

printf "%s\n", 'Hello World'; # printf() w/same formatting as print()


It makes me think of one thing. Funny how the perl's default seems to be the
double-quotes-like style. qx//, qw//, m//, s///, qr//, <<EOF. And if you
need them to behave like single-quotes you have to specify: qx' ' or
<<'EOF'. May not be a coincidence if some poeple think as perl itself and
uses double-quotes unless singles are needed.

DAE
 
A

Anno Siegel

Daedalus said:
It makes me think of one thing. Funny how the perl's default seems to be the
double-quotes-like style. qx//, qw//, m//, s///, qr//, <<EOF. And if you
need them to behave like single-quotes you have to specify: qx' ' or
<<'EOF'. May not be a coincidence if some poeple think as perl itself and
uses double-quotes unless singles are needed.

You are right in observing that with Perl's operators the default is
double-quotish behavior. But that doesn't mean it's good style to
follow suit. Perl's defaults are geared to be useful in small, casual
programs, where style is of less concern than otherwise. Defaults
are there to keep small programs small.

A larger program can afford to override them, and often should. A
particularly notable case is that warnings and strictures are off by
default. Yet there is largely agreement that it is good style to
switch them on in anything substantial. A similar argument can be
made for the use of single quotes when they yield the same result
as doubles. Or for "sub()" over "&sub" when they are exchangeable.

Anno
 
J

John W. Krahn

Daedalus said:
It makes me think of one thing. Funny how the perl's default seems to be the
double-quotes-like style. qx//, qw//, m//, s///, qr//, <<EOF.

I think you may have misunderstood how qw// works.

$ perl -le'@x = qw/$a @b c/; print "@x"'
$a @b c


John
 
T

Tad McClellan

Dale Henderson said:
This makes me wonder if perhaps 'This is a string' is faster than
"This is a string"


No need to wonder, just find out:

perldoc Benchmark
 
A

Andrew Hamm

Sherm said:
So now someone wants to debate whether it's a subject worth arguing
about. Oy! You just can't win with this group...

Not sure I wanted to initiate a debate, but from the comments I'm responding
to (or other comments) it sounds like the debate has been forcibly dominated
by one side. I don't know the personalities 'cos I haven't hung around a
perl group for a few years now, but :

all I was trying to point out is that my style of bug revolves around USING
single quotes. Different people must make different styles of mistakes. The
smart people will learn from their mistakes and establish their style to
overcome their weaknesses. I think it's fairly pointless issuing dogma. I do
some training here in my company on other programming subjects, and I always
back up a statement of dogma with a piece of experience to show why method A
is crap and method B is good. Sometimes someone will make a counter-example.
From their experience. Everyone says "hmmmm" and learns a little more.
Tolerance for ideas removes the arguments.

I'm also a sucker for a cut-n-paste bug. I've lost count of the times I've
pasted a block and then somehow managed to forget to change one critical
component like [$i] into [$j], or $x into $y or all sorts of stupid editing
failures. Yet I still keep on doing cut-n-paste in my coding ;-/
 
A

Andrew Hamm

John said:
AOL. One IMHO legit reason to prefer double quotes is that ' and "
are more visually distinct than ` and '.
AOL?

I'd argue the " vs. ' beef isn't in the same league as use strict,
test return value from open(), avoid C-style loops, and most others.

oooooo hell no. this argument is pocket change in the grand scheme of
things.
 
A

Andrew Hamm

Tad said:
Some more examples of saying that "something special" is going
on when nothing special is going on:

m/RE/s; # when RE does not contain a dot

m/RE/m; # when RE does not contain ^ or $ anchors

or even m/RE/ instead of /RE/ ??? :-D
 
D

Dale Henderson

Abigail> There's no interpreter.

Now I'm confused. If there is no interpreter, what executes the
output (for lack of a better word) of the compiler?
 
D

Dale Henderson

TM> The programmer's choice of quotes is a note to (him|her)self:

TM> "interpolation or backslash escapes are here!" or 'nothing
TM> special going on here'


DH> This makes me wonder if perhaps 'This is a string' is
DH> faster than "This is a string" because in the first example
DH> the interpreter can just use the string as is. But in the
DH> second the interpreter must scan the string looking for
DH> interpolation or backslash and construct a new string to use.

Forget this. I'm being an idiot. First of all backslashes are a
non-issue since they are taken care of by the compiler.

For some reason I was thinking that if you assigned $string="Var is
$var"; then $string would be re-interpolated every time it is
used. This patently false!
 
A

Anno Siegel

Abigail said:
Anno Siegel ([email protected]) wrote on MMMCMLXV
September MCMXCIII in <URL:[...]

%% > that there's no interpolation. To me their uses are a matter of choice. But
%% > saying "misuse of double-quotes" or ask to "fix" the thing... Do it because
%% > the majority is doing it, thats not a rule of perl.
%%
%% It is a more general rule of human interaction. It is often useful
%% to do things in one, agreed-upon way, even if there is no rational
%% reason why that particular way should be preferred. Traffic regulations
%% (beginning with the side of the road you drive on) are often quite
%% arbitrary, but the advantages of adhering to them are obvious.

I get the traffic story. Traffic rules are good because there are many
people on the road at once, each driving a potentially lethal weapon.
I don't come across hundreds of other programmers whose editors could
harm me when I write a program.

The consequences of violating a traffic rule are obviously more dire than
disregarding a programming convention, but that isn't the point of the
comparison. The point is that the rules are basically arbitrary, but
it is still preferable to have a rule to having none. Folklore about
the sword-hand side aside, there is no intrinsic advantage in driving
on the right side over driving on the left. There is still a distinct
advantage to agreeing on one or the other. Knowing what to expect
makes assessment of situations easier. That goes for single/double
quoting as well.
%% Similarly, for a programming community, there are advantages in having
%% conventional preferences for one style over another when technically
%% two (or more) ways would give the same result. By using the conventional
%% style, the author tells the reader "Nothing to see here, move along...".
%% A deviation from the standard tells the reader to look for the reason.
%% That makes such code a lot easier to read.

The "conventional style"? Are you now claiming that whatever style you
are defending is "conventional" and that the others are "deviating"?
That's quite presumptuous.

Presumptuous or not, that's the way a new convention propagates.
Deliberately or unconsciously, some people publicly act as if it were
already in place. If enough people follow suit, it becomes so.

Clpm is one of the places where this process happens.
%% Thus, a set of stylistic conventions gives a language a dimension of
%% expressiveness it wouldn't have without it. That is a Good Thing.
%% The preference of '' over "" and of sub() over &sub belong in this
%% category.

I think they aren't equivalent. 'sub()' is used far more often than
'&sub' - that preference has been settled. I highly doubt that the
preference of '' vs "" has been settled.

Then it's time to settle it :)

Anno
 
T

Tassilo v. Parseval

Also sprach Anno Siegel:

[ quoting conventions ]
Presumptuous or not, that's the way a new convention propagates.
Deliberately or unconsciously, some people publicly act as if it were
already in place. If enough people follow suit, it becomes so.

Clpm is one of the places where this process happens.

Just for the record, I'd like to note that this process hasn't yet
started to happen for me. On the quote issue, I decide from case to
case. Usually, when I have characters that require escaping in a
double-quotish context, I use single quotes. When I have something
to interpolate, I use double ones, even if that requires one or the
other backspace. Once the amount of backspacing gets annoying, I start
using heredocs or maybe 'qq'.

I'd say that this quoting issue is too minor to require a convention on
it. I do agree that conventions and rules are invaluable. That however
wont hold true for any convention. Now, getting slightly political, when
I think about the vast amount of bills we have in Germany, I'd really
say that having fewer of those would be a relief for anyone involved.

This group already has quite a few rules, such as using
strictures, warnings, checking the success of system-calls, lexical
scoping where applicable etc. All of those serve a very good purpose.
It's much less obvious (for me anyway) what purpose quoting-rules could
have.
Then it's time to settle it :)

Just keep in mind how certain people react towards rules they don't
agree with. I, for instance, tend to do the exact opposite of such
rules, just for the sake of contradiction and for expressing my grudge.
I am totally aware that this is the mindset of a five-year old, but
sometimes I really don't mind acting like a child. :)

Tassilo
 
D

Daedalus

%% > that there's no interpolation. To me their uses are a matter of
choice. But
The consequences of violating a traffic rule are obviously more dire than
disregarding a programming convention, but that isn't the point of the
comparison. The point is that the rules are basically arbitrary, but
it is still preferable to have a rule to having none. Folklore about
the sword-hand side aside, there is no intrinsic advantage in driving
on the right side over driving on the left. There is still a distinct
advantage to agreeing on one or the other. Knowing what to expect
makes assessment of situations easier. That goes for single/double
quoting as well.


You should think of quoting more like the highway traffic. There's more than
one way for the same direction. You can choose the one you want, unless you
have reasons that gives you no choice.
I agree with you about conventions, where it's necessary, but seriously
quoting don't need convention. And I'm sure that if some people decided that
the convention was the opposite (double-quotes everywhere it doesn't matter)
you would not agree and you would still use your style and argue about it.
People usualy choose the style that best suits there way of thinking and
working.
And I respect that.

DAE
 
A

Anno Siegel

Tassilo v. Parseval said:
Also sprach Anno Siegel:

[ quoting conventions ]
Presumptuous or not, that's the way a new convention propagates.
Deliberately or unconsciously, some people publicly act as if it were
already in place. If enough people follow suit, it becomes so.

Clpm is one of the places where this process happens.

Just for the record, I'd like to note that this process hasn't yet
started to happen for me. On the quote issue, I decide from case to
case. Usually, when I have characters that require escaping in a
double-quotish context, I use single quotes. When I have something
to interpolate, I use double ones, even if that requires one or the
other backspace. Once the amount of backspacing gets annoying, I start
using heredocs or maybe 'qq'.

s/space/slash/

As long as you *have* reason to prefer one or another quoting mechanism,
there is no need for a convention. The convention comes in when other
criteria are absent.
I'd say that this quoting issue is too minor to require a convention on
it. I do agree that conventions and rules are invaluable. That however
wont hold true for any convention. Now, getting slightly political, when
I think about the vast amount of bills we have in Germany, I'd really
say that having fewer of those would be a relief for anyone involved.

Also, was das betrifft... uh, err, never mind.

Now, programming conventions aren't laws that bind you no matter what.
As a programmer, they help me decide what to do in an ambiguous situation,
and help me be consistent about it.

Anecdotally, as an occasional C programmer, the ambiguity of pointer-
and array notation gives me pause each time it comes up, because I don't
have a clear preference. I wish there was a convention...

As a program reader, ideally the programmer uses the same set of
conventions I do, but a different set of conventions is also useful
if consistently applied.
This group already has quite a few rules, such as using
strictures, warnings, checking the success of system-calls, lexical
scoping where applicable etc. All of those serve a very good purpose.
It's much less obvious (for me anyway) what purpose quoting-rules could
have.

Having any rule at all can be better than having none, even if the
specifics of the rule aren't provably superior to possible alternatives.
The side-of-the-road-rule exemplifies this for traffic. So I would like to
see a convention for quotes in programming.

The current leaning seems to be "Single quotes when possible, double when
needed". Preferring single quotes is reader-friendly because they are
easier to parse, but less programmer-friendly because (applied strictly)
it calls for frequent changes of quotes during maintenance. I could
also live with the opposite rule, "Double quotes unless they are positively
unwieldy", but at least among the majority of clpm regulars, reader-
friendliness appears to have won.

The downside of conventions is that they are grist on the mill of
pedants and wannabees. That's part of the cost of having them, I
guess. No free lunch, and all that...
Just keep in mind how certain people react towards rules they don't
agree with. I, for instance, tend to do the exact opposite of such
rules, just for the sake of contradiction and for expressing my grudge.

A stance that is both noble and revolutionary :)
I am totally aware that this is the mindset of a five-year old, but
sometimes I really don't mind acting like a child. :)

Oh, certainly. The adoption and rejection of conventions by a group
happens subconsciously most of the time, and that's how we operate on
that level. It works quite well...

Anno
 
A

Anno Siegel

[quoting conventions]
You should think of quoting more like the highway traffic. There's more than
one way for the same direction. You can choose the one you want, unless you
have reasons that gives you no choice.

Conventions are there to make a choice when other criteria are absent.
For the programmer they make the choice easier, without groping for
reasons where there are none. For the reader, the choice becomes
predictable.
I agree with you about conventions, where it's necessary, but seriously
quoting don't need convention.

The need for a convention hinges on how often ambiguous situations come
up. The choice of "" or '' is arbitrary often enough for a default to
be useful.
And I'm sure that if some people decided that
the convention was the opposite (double-quotes everywhere it doesn't matter)
you would not agree and you would still use your style and argue about it.
People usualy choose the style that best suits there way of thinking and
working.

I believe you're wrong there. If there was serious agreement among
Perl programmers to use double quotes whenever possible, I would adapt,
at least in published code on clpm and the CPAN, and then, for simplicity,
in all code of some substance.

Then again, you don't have to follow every convention on every occasion.
Some functions are more formal than others :)

Anno
 
D

Daedalus

Some more examples of saying that "something special" is going
I think you may have misunderstood how qw// works.

Oups, sorry I put this one by mistake. This one have a constant behavior,
like qq// and q//.
But all those that can have both single or double-like behavior are default
to doubles.

DAE
 
D

Dale Henderson

Abigail> Now, clearly you weren't talking about an interpreter
Abigail> that executes output of the compiler. You were talking
Abigail> about an interpreter in the classical sense - one that
Abigail> takes a unit of code, interprets and executes it.

Actually, I did mean the interpreter that executes the output of
the compiler. For some bizarre reason, I was thinking that the
compiler would just store the double quote string somewhere and
the interpreter would have to recompile it every time it was
used. In short I was being stupid. Sorry.

Abigail> If you want to call whatever is executing the compile
Abigail> code an "interpreter", that's fine with me. Just don't
Abigail> confuse matters by suggesting that same thing will
Abigail> actually compile the code as well.

I'll try to be more careful in the future.
 
A

Anno Siegel

Abigail said:
Anno Siegel ([email protected]) wrote on MMMCMLXVI
September MCMXCIII in <URL:**
** The current leaning seems to be "Single quotes when possible, double when
** needed". Preferring single quotes is reader-friendly because they are
** easier to parse, but less programmer-friendly because (applied strictly)
** it calls for frequent changes of quotes during maintenance. I could
** also live with the opposite rule, "Double quotes unless they are positively
** unwieldy", but at least among the majority of clpm regulars, reader-
** friendliness appears to have won.


I think the majority of the clpm regulars have not stated a preference,
only a handful of people did.

Okay. The preference for '' is more often stated than the opposite.
As for 'readerfriendliness', that too I find
debatable. It may be reader friendly to *you*, because that's what you
are used to. It's not reader friendly to someone with different habits.
And I highly doubt the suggestion that single quoted strings are easier
to parse than double quoted strings.

That was indeed my premise, as opposed to personal habits. As a perl
construct, '' is clearly the simpler one.
It's not reader friendly towards
those with a C background, for whom 'a' is 97, and not a single character
string. I don't program that often in C, but even I occasionally think
"integer" when seeing a single quoted single character string, instead of
"string".

I didn't consider cross-effects with other languages.

Anyhow, I'm not so much in favor of one particular rule, than of having
any rule at all. Since the '' crowd is the one with an out-spoken lobby,
I give it better chances and side with that one. Opportunistic? Sue
me.

Anno
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top