[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Coding style for unary operators

From: Rik
Subject: Re: Coding style for unary operators
Date: Sun, 09 Nov 2014 20:13:43 -0800

On 11/09/2014 09:00 AM, address@hidden wrote:
Re: Coding style: unary operators
Juan Pablo Carbajal <address@hidden>
11/08/2014 09:27 AM
Philip Nienhuis <address@hidden>
Octave Maintainers List <address@hidden>
<address@hidden> <address@hidden>
text/plain; charset=UTF-8

On Sat, Nov 8, 2014 at 4:07 PM, Philip Nienhuis <address@hidden> wrote:
> Juan Pablo Carbajal-2 wrote
>> Hi,
>> Do we need to insert a blank after unary prefix operators?
>> That is,
>>  if !flag
>> should it be
>>  if ! flag
>> ?
>> For me it doesn't make sense, other wise we would have to write "-1"
>> as "- 1". Does anybody do that?
> For me a space after "!" makes it easier to distinguish it from "l" (lower
> L) or "1" or "|" (vertical line).
> The core devs have decided this (space after !) to be the preferred style so
> I just adhere to it (uhm, I try to).
> "- 1" seems to work as well.
> But it can be argued that a minus sign actually belongs to the following
> number, just like a "+" sign would/could, rather than it being a unary
> operator. So I'd say it depends on the context:
> -<space><some complicated term>  would make perfect sense; "-" is clearly a
> unary operator there.
> -<space>3  would make less sense (to me), I'd perceive "-3" as just a number
> or quantity.
> Philip
> --
> View this message in context: http://octave.1599824.n4.nabble.com/Coding-style-unary-operators-tp4667274p4667275.html
> Sent from the Octave - Maintainers mailing list archive at Nabble.com.
So the Chicago boys support my feeling that unary operators are more
often understood as a modification of the symbol next to it, rather
than an operator therefore the blank is not natural (under this view).
Do we stick to the Chicago style or we have our own, and I have to get
use to add blanks after unary operators?

The standard for Octave core code is a space after the negation operator (!).  I came from a shell/Perl background and found this awkward at first, but it really didn't take that long to simply adapt. 

If it is helpful, consider expanding out each logical operator to its English equivalent and then the space becomes more reasonable.  A&B => AANDB, which looks more natural as A AND B => A & B.  Similarly, !A => NOTA, which looks more natural as NOT A => ! A.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]