Perl Monk, Perl Meditation PerlMonks

### Re: Re: Style, *again*

by Juerd (Abbot)
 on Apr 10, 2003 at 16:19 UTC ( #249661=note: print w/ replies, xml ) Need Help??

in reply to Re: Style, *again*

It's inside a bunch of rules for which you give "Normal linguistics/interpunction." as a reason. I don't think that applies for the quoted rule - I'd like to know why you would never write 4 == \$foo.

It's kind of normal to put the topic (subject) first. 4 is not the topic, because you already know what 4 is. \$foo is what you are unsure about.

Consider these sentences:
"If the image on the cover is a camel, the book is probably Programming Perl."
"If a camel is the image on the cover, the book is probably Programming Perl."
"If foo is 4, ..."
"If 4 is foo, ..."

The camel is constant, the image can be anything.

```Juerd
- http://juerd.nl/
- spamcollector_perlmonks@juerd.nl (do not use).
```

Replies are listed 'Best First'.
Re: Style, *again*
by Abigail-II (Bishop) on Apr 10, 2003 at 19:42 UTC
I see.

I do sometimes write the constant first, because I want to reduce the amount of punctuation. If you write:

```    foo \$x, \$y == 4

then foo isn't called with arguments \$x and \$y. You'd need to write that as:

```    foo (\$x, \$y) == 4

Or

```    4 == foo \$x, \$y

And since == is a symmetric operation (assuming it's not overloaded), I don't feel strongly for the "topic first" argument. But I can see your point.

Abigail

And since == is a symmetric operation

Which is the reason I often put the constant first. Turning an == into an = accidentally results in a non symmetric operation which is illegal when the left side is a constant. Which helps catch silly mistakes that the compiler doesnt notice (like in the conditional part of a ternary op.)

---
demerphq

<Elian> And I do take a kind of perverse pleasure in having an OO assembly language...
Re: Re: Re: Style, *again*
by oylee (Pilgrim) on Apr 14, 2003 at 01:50 UTC
It does make more sense when you read it out loud, but since there's no semantic difference, it sometimes helps to place immutables as the first operand since then you'll get a compiler error out of the simple typo:
```unless (\$foo = 4) {
... argle blougat blopf ...
}
when it looks like this:
```unless (4 = \$foo) {
... womble ...
}

Create A New User
Node Status?
node history
Node Type: note [id://249661]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (11)
As of 2016-07-25 21:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
What is your favorite alternate name for a (specific) keyboard key?

Results (228 votes). Check out past polls.