You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

Guidelines for the zealots (smile)

The CodingStyle used in an application can lead to various heated debates. To avoid those in future, the SpamAssassin team tried to come to a compromise. Not everybody likes every single detail but sometimes one has to bite the bullet to avoid long discussions (smile)

Perl CodingStyle

Mostly quite sensible perl stuff. Minor differences from what's considered "normal":

Accessors

We don't use perl-style accessors very frequently (ie.

  sub foo {
    my ($self, $val) = @_;
    if (defined $val) { $self->{foo} = $val; } else { return $val; }
  }

since these can have side-effects if your code accidentally calls

 $obj->foo($newval); 

and $newval is undef. Instead, the more wordy Java/C++ style is preferred:

  sub get_foo { my ($self) = @_; return $val; }
  sub set_foo { my ($self, $val) = @_; $self->{foo} = $val; }

(status of this guideline: proposed by JustinMason. everyone happy with it?)

Return Values From Functions

Returns should be explicit, instead of implicit, for clarity:

  sub foo { ...stuff...; $val = 1; return $val; }

instead of

  sub foo { ...stuff...; $val = 1; }

reason: in the latter, $val is returned, but it's not explicit and not obvious. A later change could result in code being added after the assignment to $val, since it's not clear that the value is returned by the function.

(status of this guideline: proposed by JustinMason. everyone happy with it?)

C CodingStyle

In our C code we took the easiest way and adopted the [http://www.apache.org/dev/styleguide.html Apache Developers' C Language Style Guide].

  • No labels