You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by sp...@incubator.apache.org on 2004/08/04 04:19:54 UTC
[SpamAssassin Wiki] Updated: CodingStyle
Date: 2004-08-03T19:19:54
Editor: JustinMason <jm...@jmason.org>
Wiki: SpamAssassin Wiki
Page: CodingStyle
URL: http://wiki.apache.org/spamassassin/CodingStyle
proposing a couple of style things
Change Log:
------------------------------------------------------------------------------
@@ -4,7 +4,45 @@
== Perl CodingStyle ==
-under construction
+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 ==