Re: gtk2-perl: moving on by standardizing our code



On ons, 2003-03-12 at 20:40, Guillaume Cottenceau wrote:
       C code
1: opening curly of a function after a newline

This seems inconsistent to me and less readable. I prefer { on the same
line. I see no difference from control structures.

       Perl code
2: always use parens when invoking functions, even for builtins
   (exceptions: print printf)

This I don't agree with. Its Perl after all...
But I won't make fuss.

6: use Class->method to invoke constructors, not method Class
   (good: Gtk2->init; bad: init Gtk2) (rationale: seems that
   `method Class' comes from the special keyword "new" of C++;
   using Class->method is more orthogonal with using
   $object->method for method calls)

"new Foo" actually come from "print Handle". But that doesn't matter.
Foo->new is less error prone, as "new Foo" can be ambiguous.
But no matter - we agree. Foo->new is better (less pretty - though)... 

Open questions:

1. do we use infix "if/unless" or "and/or" for short control
   structures? namely:
       $self->set_active($flag) if @_ == 2;
                or
       @_ == 2 and $self->set_active($flag);

   I personally prefer "and/or" for two reasons:
   - the condition is on the left, the code to execute is on the
     right, it's more similar to doing if (condition) { .. } when
     the code to execute has many lines
   - I find "unless" very unreadable

   But I know that many people tend to line infix "if", so that's
   why I ask you to choose.

I'd go with the infix if.
Using the boolean operators like that is confusing to many people.
I use "open ... or die ..." all the time but I never use and as a control construct.

I rather like "unless" but I don't care all that much.

2. for one-lines, do we use `shift' or do we name the parameters
   using $_[0], $_[1], etc? I don't have an opinion here. Using
   `shift' can be better because then you can use @_ for the
   parameters of the functions, with any number of parameters.

I think $_[0]->foo is clearer than shift->foo...
But again I won't make a fuss about it.

3. do we use "return" at the end of functions? I'd choose not
   (it's useless) but most people don't like that, it seems.

I agree with you here.

./borup




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