summaryrefslogtreecommitdiff
path: root/STYLEGUIDE
blob: e6dd3c9fbe01b96932bd63e9730bfa603841bd00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
Always do:

- Pragmatic modules ALWAYS to use in ALL packages: 

  use strict;
  use warnings;

- Only for packages for including package UNIVERSAL definitions

  use Xerl::Page::Base;

- Object oriented coding style

- Always use method prototypes if possible

  sub foo($;$) { .... }

- Explicit object typing if possible

  my Class::Name::Here $foo = Class::Name::Here->new();

- If no real ret val, set undef; explicitly

  sub foo() {
  	# Do some stuff
	...
	# Set explicit undef ret value
	return undef;
  }

- Private subs use _ as its prefix and are called only from the current package.

  package Xerl::Foo::Bla;
  .
  .

  sub _iamprivate($) {
	my Xerl::Foo:Bla $self = $_[0];
	.
	.
  }

  sub iampublic($) {
	my Xerl::Foo:Bla $self = $_[0];
	$self->_iamprivate();
	return undef;
  }

- Static subs (not OOP) are in CAPITAL letters. 

  sub IAMSTATIC($) {
	print shift;
	return 'Hello World';
  }

  sub iamdynamic($) {
	my Xerl::Foo:Bla $self = $_[0];
	return Xerl::Foo::Bla::IAMSTATIC( $self->get_somevalue() );
  }

- Static private subs start with _ and are written in CAPITAL letters

  sub _IAMSTATICPRIVATE() { 
	.
	.
  }

- Use Pidy to automaically restyle the code! (make pidy)

- Mark things which are still to do with TODO: at any place in the source
  tree. (Can be searched for using 'make todo').