in reply to Re: Re: Style, *again*

Thanks for the annotated list. I don't always make the same decisions, but it's interesting to see where people take an different approach, and why they do that. One question I have, you write:
```Logical order in comparisons: \$foo == 4, but never 4 == \$foo
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.

Abigail

Replies are listed 'Best First'.
Re: Re: Style, *again*
by Juerd (Abbot) on Apr 10, 2003 at 16:19 UTC

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).
```

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...
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 ...
}
```unless (4 = \$foo) {