Parentheses

Discussion in 'Ruby' started by Nikolai Weibull, Oct 15, 2003.

  1. OK, is there a general concensus on when it is OK to omit parentheses
    and when it is not? I prefer skipping parentheses as often as possible,
    but I'm not quite sure when I may run into trouble and when it is OK.
    nikolai

    --
    ::: name: Nikolai Weibull :: aliases: pcp / lone-star / aka :::
    ::: born: Chicago, IL USA :: loc atm: Gothenburg, Sweden :::
    ::: page: www.pcppopper.org :: fun atm: gf,lps,ruby,lisp,war3 :::
    main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}
    Nikolai Weibull, Oct 15, 2003
    #1
    1. Advertising

  2. Hi,

    In message "Parentheses"
    on 03/10/16, Nikolai Weibull <> writes:

    |OK, is there a general concensus on when it is OK to omit parentheses
    |and when it is not? I prefer skipping parentheses as often as possible,
    |but I'm not quite sure when I may run into trouble and when it is OK.

    foo 1,2,3 # this is OK (top level)
    a = foo 3 # this is not recommended (part of expression)

    matz.
    Yukihiro Matsumoto, Oct 15, 2003
    #2
    1. Advertising

  3. * Yukihiro Matsumoto <> [Oct, 15 2003 18:20]:
    > |OK, is there a general concensus on when it is OK to omit parentheses
    > |and when it is not? I prefer skipping parentheses as often as possible,
    > |but I'm not quite sure when I may run into trouble and when it is OK.
    >
    > foo 1,2,3 # this is OK (top level)
    > a = foo 3 # this is not recommended (part of expression)

    OK, thanks. Did this change in 1.8.0 in any way?
    nikolai

    --
    ::: name: Nikolai Weibull :: aliases: pcp / lone-star / aka :::
    ::: born: Chicago, IL USA :: loc atm: Gothenburg, Sweden :::
    ::: page: www.pcppopper.org :: fun atm: gf,lps,ruby,lisp,war3 :::
    main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}
    Nikolai Weibull, Oct 15, 2003
    #3
  4. Hi!

    * Nikolai Weibull; 2003-10-15, 21:32 UTC:
    > OK, is there a general concensus on when it is OK to omit
    > parentheses and when it is not?


    The answer depends on what 'OK' means. The obvious answer is: "You
    can drop any parentheses unless doing so breakes the program." That
    doesn't help you a lot, does it?

    A better approach seems to be "Remove or add non-essential
    parentheses unless the code 'feels good'". What 'feels good'? This
    depends on the problem you face: The following can 'feel good' if it
    means 'compute a sum, divide it by a value then divide it by a
    quotient':

    (1.1 + 2.2) / 3.3 / ((2.2 + 3.3) / (1.0 + 0.1))

    but if the same computation is done meaning 'compute a fraction and
    then divide it by another fraction' one should rather write

    ((1.1 + 2.2) / 3.3) / ((2.2 + 3.3) / (1.0 + 0.1))

    This is the techical side of 'feels good'. The other side is the
    programmer. Many programmers are 'parameter-centered' while many
    others are 'option-centered'.

    One can see h.delete in two ways: As a function that takes a
    parameter or as a command that understands a numerical option.
    Depending on how your interpretation of h.delete is, you either
    prefer using parentheses or not.

    irb(main):001:0> a = [3, 1, 4, 1, 5]; b = [3, 1, 4, 1, 5]
    => [3, 1, 4, 1, 5]
    irb(main):002:0> a.delete(1)
    => 1
    irb(main):003:0> b.delete 1
    => 1
    irb(main):004:0> a
    => [3, 4, 5]
    irb(main):005:0> b
    => [3, 4, 5]

    > I prefer skipping parentheses as often as possible, but I'm not
    > quite sure when I may run into trouble and when it is OK.


    Corollary of "Remove or add non-essential parentheses unless code
    'feels good'": "Don't remove parentheses that feel like trouble, add
    parentheses where white space feels like trouble".

    Please take notice of signature! / Bitte Signature beachten!

    Josef 'Jupp' Schugt
    --
    db Wenn sie mir ohne meine Einwilligung geschickt wurde, db
    dpqb wird eine E-Mail > 100 kB ungelesen entsorgt dpqb
    dp::qb If you send me an e-mail > 100 kB without my dp::qb
    dp::::qb consent it will be silently discarded dp::::qb
    Josef 'Jupp' SCHUGT, Oct 16, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?UGF0cmljay5PLklnZQ==?=

    'AddressOf' operand must be the name of a method; no parentheses a

    =?Utf-8?B?UGF0cmljay5PLklnZQ==?=, Oct 18, 2004, in forum: ASP .Net
    Replies:
    15
    Views:
    7,539
    =?Utf-8?B?UGF0cmljay5PLklnZQ==?=
    Oct 19, 2004
  2. Replies:
    7
    Views:
    9,195
    Jeff Dillon
    May 17, 2006
  3. Memana
    Replies:
    1
    Views:
    315
    Alf P. Steinbach
    Jul 5, 2004
  4. Christopher Benson-Manica

    Empty parentheses

    Christopher Benson-Manica, Oct 17, 2003, in forum: C Programming
    Replies:
    10
    Views:
    595
    Jeremy Yallop
    Oct 17, 2003
  5. Replies:
    44
    Views:
    929
    Timo Virkkala
    Jan 6, 2005
Loading...

Share This Page