starting to work...
[freeside.git] / rt / lib / RT / StyleGuide.pod
1 =head1 NAME
2
3 RT::StyleGuide - RT Style Guide
4
5 =head1 INTRODUCTION
6
7 All code and documentation that is submitted to be included in the RT
8 distribution should follow the style in this document.  This is not to
9 try to stifle your creativity, but to make life easier for everybody who
10 has to work with your code, and to aid those who are not quite sure how
11 to do something.
12
13 These conventions below apply to perl modules, web programs, and
14 command-line programs, specifically, but also might apply to some
15 degree to any Perl code written for use in RT.
16
17 Note that these are all guidelines, not unbreakable rules.  If you have
18 a really good need to break one of the rules herein, however, then it is
19 best to ask on the B<rt-devel> mailing list first.
20
21 Note that with much of this document, it is not so much the Right Way as
22 it is Our Way.  We need to have conventions in order to make life easier
23 for everyone.  So don't gripe, and just follow it, because you didn't
24 get a good grade in "Plays Well With Others" in kindergarten and you
25 want to make up for it now.
26
27 If you have any questions, please ask us on the B<rt-devel> mailing list:
28
29         http://www.bestpractical.com/rt/lists.html
30
31 We don't always follow this guide.  We are making changes throughout
32 our code to be in line with it.  But just because we didn't do
33 it yet, that is no excuse.  Do it anyway.  :-)
34
35 This document is subject to change at the whims of the core RT team.
36 We hope to add any significant changes at the bottom of the document.
37
38
39 =head1 CODING PRINCIPLES
40
41 =head2 Perl Version
42
43 We code everything to perl 5.8.3 or higher.  Complete unicode support
44 requires bugfixes found in 5.8.3.
45
46 =head2 Documentation
47
48 All modules will be documented using the POD examples in the module
49 boilerplate.  The function, purpose, use of the module will be
50 explained, and each public API will be documented with name,
51 description, inputs, outputs, side effects, etc.
52
53 If an array or hash reference is returned, document the size of the
54 array (including what each element is, as appropriate) and name each key
55 in the hash.  For complex data structures, map out the structure as
56 appropriate (e.g., name each field returned for each column from a DB
57 call; yes, this means you shouldn't use "SELECT *", which you shouldn't
58 use anyway).
59
60 Also document what kind of data returned values are.  Is it an integer,
61 a block of HTML, a boolean?
62
63 All command-line program options will be documented using the
64 boilerplate code for command-line programs, which doesn't yet exist.
65 Each available function, switch, etc. should be documented, along
66 with a statement of function, purpose, use of the program.  Do not
67 use the same options as another program, for a different purpose.
68
69 All web templates should be documented with a statement of function,
70 purpose, and use in a mason comment block.
71
72 Any external documents, and documentation for command-line programs and
73 modules, should be written in POD, where appropriate. From there, they
74 can be translated to many formats with the various pod2* translators. 
75 Read the perlpod manpage before writing any POD, because although POD is
76 not difficult, it is not what most people are used to.  It is not a
77 regular markup language; it is just a way to make easy documentation
78 for translating to other formats.  Read, and understand, the perlpod
79 manpage, and ask us or someone else who knows if you have any questions.
80
81
82 =head2 Version
83
84 Our distribution versions use tuples, where the first number is the
85 major revision, the second number is the version, and third
86 number is the subversion.  Odd-numbered versions are development
87 versions.  Examples:
88
89         1.0.0           First release of RT 1
90         1.0.1           Second release of RT 1.0
91         1.0.10          etc.
92         1.1.0           First development release of RT 1.2 (or 2.0)
93         2.0.0           First release of RT 2
94
95 Versions can be modified with a hyphen followed by some text, for
96 special versions, or to give extra information.  Examples:
97
98         2.0.0-pre1      Notes that this is not final, but preview
99
100 In perl 5.6.0, you can have versions like C<v2.0.0>, but this is not
101 allowed in previous versions of perl.  So to convert a tuple version
102 string to a string to use with $VERSION, use a regular integer for
103 the revision, and three digits for version and subversion.  Examples:
104
105         1.1.6   ->      1.001006
106         2.0.0   ->      2.000000
107
108 This way, perl can use the version strings in greater-than and
109 less-than comparisons.
110
111
112 =head2 Comments
113
114 All code should be self-documenting as much as possible.  Only include
115 necessary comments.  Use names like "$ticket_count", so you don't need to
116 do something like:
117
118         # ticket count
119         my $tc = 0;
120
121 Include any comments that are, or might be, necessary in order for
122 someone else to understand the code.  Sometimes a simple one-line
123 comment is good to explain what the purpose of the following code is
124 for.  Sometimes each line needs to be commented because of a complex
125 algorithm.  Read Kernighan & Pike's I<Practice of Programming> about
126 commenting.  Good stuff, Maynard.
127
128
129 =head2 Warnings and Strict
130
131 All code must compile and run cleanly with "use strict" enabled and the
132 perl "-w" (warnings) option on.  If you must do something that -w or
133 strict complains about, there are workarounds, but the chances that you
134 really need to do it that way are remote.
135
136 =head2 Lexical Variables
137
138 Use only lexical variables, except for special global variables
139 ($VERSION, %ENV, @ISA, $!, etc.) or very special circumstances (see
140 %HTML::Mason::Commands::session ).  Global variables
141 for regular use are never appropriate.  When necessary, "declare"
142 globals with "use vars" or "our()".
143
144 A lexical variable is created with my().  A global variable is
145 pre-existing (if it is a special variable), or it pops into existence
146 when it is used.  local() is used to tell perl to assign a temporary
147 value to a variable.  This should only be used with special variables,
148 like $/, or in special circumstances.  If you must assign to any global
149 variable, consider whether or not you should use local().
150
151 local() may also be used on elements of arrays and hashes, though there
152 is seldom a need to do it, and you shouldn't.
153
154
155 =head2 Exporting
156
157 Do not export anything from a module by default.  Feel free to put
158 anything you want to in @EXPORT_OK, so users of your modules can
159 explicitly ask for symbols (e.g., "use Something::Something qw(getFoo
160 setFoo)"), but do not export them by default.
161
162
163 =head2 Pass by Reference
164
165 Arrays and hashes should be passed to and from functions by reference
166 only.  Note that a list and an array are NOT the same thing.  This
167 is perfectly fine:
168
169         return($user, $form, $constants);
170
171 An exception might be a temporary array of discrete arguments:
172
173         my @return = ($user, $form);
174         push @return, $constants if $flag;
175         return @return;
176
177 Although, usually, this is better (faster, easier to read, etc.):
178
179         if ($flag) {
180                 return($user, $form, $constants);
181         } else {
182                 return($user, $form);
183         }
184
185 We need to talk about Class::ReturnValue here.
186
187
188 =head2 Garbage Collection
189
190 Perl does pretty good garbage collection for you.  It will automatically
191 clean up lexical variables that have gone out of scope and objects whose
192 references have gone away.  Normally you don't need to worry about
193 cleaning up after yourself, if using lexicals.
194
195 However, some glue code, code compiled in C and linked to Perl, might
196 not automatically clean up for you.  In such cases, clean up for
197 yourself.  If there is a method in that glue to dispose or destruct,
198 then use it as appropriate.
199
200 Also, if you have a long-running function that has a large data
201 structure in it, it is polite to free up the memory as soon as you are
202 done with it, if possible.
203
204         my $huge_data_structure = get_huge_data_structure();
205         do_something_with($huge_data_structure);
206         undef $huge_data_structure;
207
208 =head2 DESTROY
209
210 All object classes must provide a DESTROY method.  If it won't do
211 anything, provide it anyway:
212
213         sub DESTROY { }
214
215
216
217 =head2 die() and exit()
218
219 Don't do it.  Do not die() or exit() from a web template or module.  Do
220 not call C<kill 9, $$>.  Don't do it.
221
222 In command-line programs, do as you please.
223
224
225 =head2 shift and @_
226
227 Do not use @_.  Use shift.  shift may take more lines, but Jesse thinks it 
228 leads to cleaner code.
229
230         my $var = shift;                        # right
231         my($var) = @_;                          # ick. no
232         sub foo { uc $_[0] }                    # icky. sometimes ok.
233
234
235         my($var1, $var2) = (shift, shift);      # Um, no.
236
237         my $var1 = shift;                       # right
238         my $var2 = shift;                       
239
240 =head2 Method parameters
241
242 If a method takes exactly one mandatory argument, the argument should be
243 passed in a straightforward manner:
244
245         my $self = shift;
246         my $id = shift;
247
248 In all other cases, the method needs to take named parameters, usually
249 using a C<%args> hash to store them:
250
251         my $self = shift;
252         my %args = ( Name => undef,
253                      Description => undef,
254                      @_ );
255
256 You may specify defaults to those named parameters instead of using
257 C<undef> above, as long as it is documented as such.
258
259 It is worth noting that the existing RT codebase had not followed this
260 style perfectly; we are trying to fix it without breaking exsiting APIs.
261
262 =head2 Tests
263
264 Modules should provide test code, with documentation on how to use
265 it.  Test::More makes it easy to create tests. Any code you write
266 should have a testsuite.  Any code you alter should have a test
267 suite. If a patch comes in without tests, there is something wrong.
268
269 When altering code, you must run the test harness before submitting a
270 patch or committing code to the repository.
271
272 "make test" will run the test suite.
273
274 =head2 STDIN/STDOUT
275
276 Always report errors using $RT::Logger. It's a Log::Dispatch object.
277 Unlike message meant for the user, log messages are not to be
278 internationalized.
279
280 There are several different levels ($RT::Logger methods) of logging:
281
282 =over 4
283
284 =item debug
285
286 Used for messages only needed during system debugging.
287
288 =item info
289
290 Should be used to describe "system-critical" events which aren't errors.
291 Examples: creating users, deleting users, creating tickets, creating queues,
292 sending email (message id, time, recipients), recieving mail, changing
293 passwords, changing access control, superuser logins)
294
295 =item error
296
297 Used for RT-generated failures during execution.
298
299 =item crit
300
301 Should be used for messages when an action can not be completed due to some
302 error condition beyond our control.
303
304 =back
305
306 In the web UI and modules, never print directly to STDERR.  Do not print
307 directly to STDOUT, unless you need to print directly to the user's console.
308
309 In command-line programs, feel free to print to STDERR and STDOUT as
310 needed for direct console communication. But for actual error reporting,
311 use the logging API.
312
313
314 =head2 System Calls
315
316 Always check return values from system calls, including open(),
317 close(), mkdir(), or anything else that talks directly to the system. 
318 Perl built-in system calls return the error in $!; some functions in
319 modules might return an error in $@ or some other way, so read the module's
320 documentation if you don't know.  Always do something, even if it is
321 just calling $RT::Logger->warning(), when the return value is not what you'd expect.
322
323
324
325 =head1 STYLE
326
327 Much of the style section is taken from the perlsyle manpage.  We make
328 some changes to it here, but it wouldn't be a bad idea to read that
329 document, too.
330
331 =head2 Terminology
332
333 =over 4
334
335 =item RT the name
336
337 "RT" is the name of the project.  "RT" is, optionally, the
338 specific name for the actual file distribution.  That's it. 
339
340 While we sometimes use "RT2" or "RT3", that's shortand that's really
341 not recommended. The name of the project is "RT".
342
343 To specify a major version, use "RT 3.0".
344 To specify a specific release, use "RT 3.0.12"
345
346 =item function vs. sub(routine) vs. method
347
348 Just because it is the Perl Way (not necessarily right for all
349 languages, but the documented terminology in the perl documentation),
350 "method" should be used only to refer to a subroutine that are object
351 methods or class methods; that is, these are functions that are used
352 with OOP that always take either an object or a class as the first
353 argument. Regular subroutines, ones that are not object or class
354 methods, are functions.  Class methods that create and return an object
355 are optionally called constructors.
356
357 =item Users
358
359 "users" are normally users of RT, the ones hitting the site; if using
360 it in any other context, specify.  
361 "system users" are user
362 names on the operating system.  "database users" are the user names in
363 the database server.  None of these needs to be capitalized.
364
365 =back
366
367
368 =head2 Names
369
370 Don't use single-character variables, except as iterator variables.
371
372 Don't use two-character variables just to spite us over the above rule.
373
374 Constants are in all caps; these are variables whose value will I<never>
375 change during the course of the program.
376
377         $Minimum = 10;          # wrong
378         $MAXIMUM = 50;          # right
379
380 Other variables are lowercase, with underscores separating the words. 
381 They words used should, in general, form a noun (usually singular),
382 unless the variable is a flag used to denote some action that should be
383 taken, in which case they should be verbs (or gerunds, as appropriate)
384 describing that action.
385
386         $thisVar      = 'foo';  # wrong
387         $this_var     = 'foo';  # right
388         $work_hard    = 1;      # right, verb, boolean flag
389         $running_fast = 0;      # right, gerund, boolean flag
390
391 Arrays and hashes should be plural nouns, whether as regular arrays and
392 hashes or array and hash references.  Do not name references with "ref"
393 or the data type in the name.
394
395         @stories     = (1, 2, 3);      # right
396         $comment_ref = [4, 5, 6];      # wrong
397         $comments    = [4, 5, 6];      # right
398         $comment     = $comments->[0]; # right
399
400 Make the name descriptive.  Don't use variables like "$sc" when you
401 could call it "$story_count".  See L<"Comments">.
402
403 There are several variables in RT that are used throughout the code,
404 that you should use in your code.  Do not use these variable names for
405 anything other than how they are normally used, and do not use any
406 other variable names in their place.  Some of these are:
407
408         $self           # first named argument in object method
409
410 Subroutines (except for special cases, like AUTOLOAD and simple accessors)
411 begin with a verb, with words following to complete the action.  Accessors
412 don't start with "Get" if they're just the name of the attribute.
413
414 Accessors which return an object should end with the suffix Obj.
415
416 This section needs clarification for RT.
417
418 Words begin with a capital letter.  They
419 should as clearly as possible describe the activity to be peformed, and
420 the data to be returned. 
421
422
423
424         Load();         # good
425         LoadByName();   # good
426         LoadById();             # good
427
428 Subroutines beginning with C<_> are special: they are not to be used
429 outside the current object.  There is not to be enforced by the code
430 itself, but by someone very big and very scary.
431
432 For large for() loops, do not use $_, but name the variable.
433 Do not use $_ (or assume it) except for when it is absolutely
434 clear what is going on, or when it is required (such as with
435 map() and grep()).
436
437         for (@list) {
438                 print;                  # OK; everyone knows this one
439                 print uc;               # wrong; few people know this
440                 print uc $_;            # better
441         }
442
443 Note that the special variable C<_> I<should> be used when possible.
444 It is a placeholder that can be passed to stat() and the file test
445 operators, that saves perl a trip to re-stat the file.  In the
446 example below, using C<$file> over for each file test, instead of
447 C<_> for subsequent uses, is a performance hit.  You should be
448 careful that the last-tested file is what you think it is, though.
449
450         if (-d $file) {         # $file is a directory
451                 # ...
452         } elsif (-l _) {        # $file is a symlink
453                 # ...
454         }
455
456 Package names begin with a capital letter in each word, followed by
457 lower case letters (for the most part).  Multiple words should be StudlyCapped.
458
459         RT::User                        # good
460         RT::Database::MySQL             # proper name
461         RT::Display::Provider           # good
462         RT::CustomField                 # not so good, but OK
463
464 Plugin modules should begin with "RTx::", followed by the name
465 of the plugin.  
466
467 =head1 Code formatting
468
469 Use perltidy. Anything we say here is wrong if it conflicts with what
470 perltidy does. Your perltidyrc should read:
471
472 -lp -vt=2 -vtc=2 -nsfs -bar                                                                                             
473
474 =head2 Indents and Blank Space
475
476 All indents should be tabs.  Set your tab stops whatever you want them
477 to be; I use 8 spaces per tabs.
478
479 No space before a semicolon that closes a statement.
480
481         foo(@bar) ;     # wrong
482         foo(@bar);      # right
483
484 Line up corresponding items vertically.
485
486         my $foo   = 1;
487         my $bar   = 2;
488         my $xyzzy = 3;
489
490         open(FILE, $fh)   or die $!;
491         open(FILE2, $fh2) or die $!;
492
493         $rot13 =~ tr[abcedfghijklmnopqrstuvwxyz]
494                     [nopqrstuvwxyzabcdefghijklm];
495
496         # note we use a-mn-z instead of a-z,
497         # for readability
498         $rot13 =~ tr[a-mn-z]
499                     [n-za-m];
500
501 Put blank lines between groups of code that do different things.  Put
502 blank lines after your variable declarations.  Put a blank line before a
503 final return() statement.  Put a blank line following a block (and
504 before, with the exception of comment lines).
505
506 An example:
507
508         # this is my function!
509         sub foo {
510                 my $val = shift;
511                 my $obj = new Constructor;
512                 my($var1, $var2);
513
514                 $obj->SetFoo($val);
515                 $var1 = $obj->Foo();
516
517
518                 return($val);
519         }
520
521         print 1;
522
523
524 =head2 Parentheses
525
526 For control structures, there is a space between the keyword and opening
527 parenthesis.  For functions, there is not.
528
529         for(@list)      # wrong
530         for (@list)     # right
531
532         my ($ref)       # wrong
533         my($ref)        # right
534
535 Be careful about list vs. scalar context with parentheses!
536
537         my @array = ('a', 'b', 'c');
538         my($first_element) = @array;            # a
539         my($first_element) = ('a', 'b', 'c');   # a
540         my $element_count  = @array;            # 3
541         my $last_element   = ('a', 'b', 'c');   # c
542
543 Always include parentheses after functions, even if there are no arguments.
544 There are some exceptions, such as list operators (like print) and unary
545 operators (like undef, delete, uc).
546
547 There is no space inside the parentheses, unless it is needed for
548 readability.
549
550         for ( map { [ $_, 1 ] } @list ) # OK
551         for ( @list )                   # not really OK, not horrible
552
553 On multi-line expressions, match up the closing parenthesis with either
554 the opening statement, or the opening parenthesis, whichever works best.
555 Examples:
556
557         @list = qw(
558                 bar
559                 baz
560         );                      # right
561
562         if ($foo && $bar && $baz
563                  && $buz && $xyzzy
564         ) {
565                 print $foo;
566         }
567
568 Whether or not there is space following a closing parenthesis is
569 dependent on what it is that follows.
570
571         print foo(@bar), baz(@buz) if $xyzzy;
572
573 Note also that parentheses around single-statement control expressions,
574 as in C<if $xyzzy>, are optional (and discouraged) C<if> it is I<absolutely>
575 clear -- to a programmer -- what is going on.  There is absolutely no
576 need for parentheses around C<$xyzzy> above, so leaving them out enhances
577 readability.  Use your best discretion.  Better to include them, if
578 there is any question.
579
580 The same essentially goes for perl's built-in functions, when there is
581 nothing confusing about what is going on (for example, there is only one
582 function call in the statement, or the function call is separated by a
583 flow control operator).  User-supplied functions must always include
584 parentheses.
585
586         print 1, 2, 3;                          # good
587         delete $hash{key} if isAnon($uid);      # good
588
589
590 However, if there is any possible confusion at all, then include the
591 parentheses.  Remember the words of Larry Wall in the perlstyle manpage:
592
593         When in doubt, parenthesize.  At the very least it will
594         let some poor schmuck bounce on the % key in vi.
595
596         Even if you aren't in doubt, consider the mental welfare
597         of the person who has to maintain the code after you, and
598         who will probably put parens in the wrong place.
599
600 So leave them out when it is absoutely clear to a programmer, but if
601 there is any question, leave them in.
602
603
604 =head2 Braces
605
606 (This is about control braces, not hash/data structure braces.)
607
608 There is always a space befor the opening brace.
609
610         while (<$fh>){  # wrong
611         while (<$fh>) { # right
612
613 A one-line block may be put on one line, and the semicolon may be
614 omitted.
615
616         for (@list) { print }
617
618 Otherwise, finish each statement with a semicolon, put the keyword and
619 opening curly on the first line, and the ending curly lined up with the
620 keyword at the end.
621
622         for (@list) {
623                 print;
624                 smell();
625         }
626
627 Generally, we prefer "uncuddled elses":
628
629         if ($foo) {
630                 print;
631         }
632         else {
633                 die;
634         }
635
636 _If_ the if statement is very brief, sometimes "cuddling" the else makes code more readable. Feel free to cuddle them in that case:
637
638
639         if ($foo) {
640                 print;
641         } else {
642                 die;
643         }
644
645 =head2 Operators
646
647 Put space around most operators.  The primary exception is the for
648 aesthetics; e.g., sometimes the space around "**" is ommitted,
649 and there is never a space before a ",", but always after.
650
651         print $x , $y;  # wrong
652         print $x, $y;   # right
653
654         $x = 2 >> 1;    # good
655         $y = 2**2;      # ok
656
657 Note that "&&" and "||" have a higher precedence than "and" and "or". 
658 Other than that, they are exactly the same.  It is best to use the lower
659 precedence version for control, and the higher for testing/returning
660 values.  Examples:
661
662         $bool = $flag1 or $flag2;       # WRONG (doesn't work)
663         $value = $foo || $bar;          # right
664         open(FILE, $file) or die $!;
665
666         $true  = foo($bar) && baz($buz);
667         foo($bar) and baz($buz);
668
669 Note that "and" is seldom ever used, because the statement above is
670 better written using "if":
671
672         baz($buz) if foo($bar);
673
674 Most of the time, the confusion between and/&&, or/|| can be alleviated
675 by using parentheses.  If you want to leave off the parentheses then you
676 I<must> use the proper operator.  But if you use parentheses -- and
677 normally, you should, if there is any question at all -- then it doesn't
678 matter which you use.  Use whichever is most readable and aesthetically
679 pleasing to you at the time, and be consistent within your block of code.
680
681 Break long lines AFTER operators, except for "and", "or", "&&", "||".
682 Try to keep the two parts to a binary operator (an operator that
683 has two operands) together when possible.
684
685         print "foo" . "bar" . "baz"
686                 . "buz";                        # wrong
687
688         print "foo" . "bar" . "baz" .
689                 "buz";                          # right
690
691         print $foo unless $x == 3 && $y ==
692                 4 && $z == 5;                   # wrong
693
694         print $foo unless $x == 3 && $y == 4
695                 && $z == 5;                     # right
696
697
698 =head2 Other
699
700 Put space around a complex subscript inside the brackets or braces.
701
702         $foo{$bar{baz}{buz}};   # OK
703         $foo{ $bar{baz}{buz} }; # better
704
705 In general, use single-quotes around literals, and double-quotes
706 when the text needs to be interpolated. 
707
708 It is OK to omit quotes around names in braces and when using
709 the => operator, but be careful not to use a name that doubles as
710 a function; in that case, quote.
711
712         $what{'time'}{it}{is} = time();
713
714 When making compound statements, put the primary action first.
715
716         open(FILE, $fh) or die $!;      # right
717         die $! unless open(FILE, $fh);  # wrong
718
719         print "Starting\n" if $verbose; # right
720         $verbose && print "Starting\n"; # wrong
721
722
723 Use here-docs instead of repeated print statements.
724
725                 print <<EOT;
726         This is a whole bunch of text.
727         I like it.  I don't need to worry about messing
728         with lots of print statements and lining them up.
729         EOT
730
731 Just remember that unless you put single quotes around your here-doc
732 token (<<'EOT'), the text will be interpolated, so escape any "$" or "@"
733 as needed.
734
735 =head1 INTERNATIONALIZATION
736
737
738 =head2 String extraction styleguide
739
740 =over 4
741
742 =item Web templates
743
744 Templates should use the /l filtering component to call the localisation
745 framework
746
747 The string              Foo!
748
749 Should become           <&|/l&>Foo!</&>
750
751 All newlines should be removed from localized strings, to make it easy to 
752 grep the codebase for strings to be localized
753
754 The string              Foo
755                         Bar
756                         Baz
757                         
758 Should become           <&|/l&>Foo Bar Baz</&>
759
760
761 Variable subsititutions should be moved to Locale::MakeText format
762
763 The string              Hello, <%$name %>
764
765 should become           <&|/l, $name &>Hello, [_1]</&>  
766
767
768 Multiple variables work just like single variables
769  
770 The string              You found <%$num%> tickets in queue <%$queue%>
771
772 should become           <&|/l, $num, $queue &>You found [_1] tickets in queue [_2]</&>
773
774 When subcomponents are called in the middle of a phrase, they need to be escaped
775 too:
776
777 The string               <input type="submit" value="New ticket in">&nbsp<& /Elements/SelectNewTicketQueue&>
778
779 should become           <&|/l, $m->scomp('/Elements/SelectNewTicketQueue')&><input type="submit" value="New ticket in">&nbsp;[_1]</&>
780
781
782
783
784 The string      <& /Elements/TitleBoxStart, width=> "40%", titleright => "RT $RT::VERSION for   RT->Config->Get('rtname')", title => 'Login' &>
785
786 should become   <& /Elements/TitleBoxStart, 
787                         width=> "40%",
788                         titleright => loc("RT [_1] for [_2]",$RT::VERSION, RT->Config->Get('rtname')),
789                         title => loc('Login'),
790                 &>
791         
792
793 =item Library code                      
794
795
796
797 Within RT's core code, every module has a localization handle available through the 'loc' method:
798
799 The code        return ( $id, "Queue created" );
800
801 should become   return ( $id, $self->loc("Queue created") );    
802
803 When returning or localizing a single string, the "extra" set of parenthesis () should be omitted.
804
805 The code        return ("Subject changed to ". $self->Data );
806
807 should become    return $self->loc( "Subject changed to [_1]", $self->Data );
808
809
810 It is important not to localize  the names of rights or statuses within RT's core, as there is logic that depends on them as string identifiers.  The proper place to localize these values is when they're presented for display in the web or commandline interfaces.
811
812
813 =back
814
815 =head1 CODING PRCEDURE
816
817 This is for new programs, modules, specific APIs, or anything else.
818
819 =over 4
820
821 =item Present idea to rt-devel
822
823 We may know of a better way to approach the problem, or know of an
824 existing way to deal with it, or know someone else is working on it. 
825 This is mostly informal, but a fairly complete explanation for the need
826 and use of the code should be provided.
827
828
829 =item Present complete specs to rt-devel
830
831 The complete proposed API  should be submitted for
832 approval and discussion.  For web and command-line programs, present the
833 functionality and interface (op codes, command-lin switches, etc.).
834
835 The best way to do this is to take the documentation portion of the
836 boilerplate and fill it in.  You can make changes later if necessary,
837 but fill it in as much as you can.
838
839
840
841 =item Prepare for code review
842
843 When you are done, the code will undergo a code review by a member of
844 the core team, or someone picked by the core team.  This is not to
845 belittle you (that's just a nice side effect), it is to make sure that
846 you understand your code, that we understand your code, that it won't
847 break other code, that it follows the documentation and existing
848 proposal.  It is to check for possible optimizations or better ways of
849 doing it.
850
851 Note that all code is expected to follow the coding principles and style
852 guide contained in this document.
853
854
855 =item Finish it up
856
857 After the code is done (possibly going through multiple code reviews),
858 if you do not have repository access, submit it to rt-<major-version>-bugs@fsck.com as a unified diff. From that point on, it'll be handled by someone with repository access.
859
860 =back
861
862
863 =head1 BUG REPORTS, PATCHES
864
865 Use rt-<major-version>-bugs@fsck.com for I<any> bug that is not
866 being fixed immediately.  If it is not in RT, there
867 is a good chance it will not be dealt with.
868
869 Send patches to rt-<major-version>-bugs@fsck.com, too.  Use C<diff
870 -u> for patches.
871
872 =head1 SCHEMA DESIGN
873
874 RT uses a convention to denote the foreign key status in its tables.
875 The rule of thumb is:
876
877 =over 4
878
879 =item When it references to another table, always use the table name
880
881 For example, the C<Template> field in the C<Scrips> table refers to
882 the C<Id> of the same-named C<Template> table.
883
884 =item Otherwise, always use the C<Id> suffix
885
886 For example, the C<ObjectId> field in the C<ACL> table can refer
887 to any object, so it has the C<Id> suffix.
888
889 =back
890
891 There are some legacy fields that did not follow this rule, namely
892 C<ACL.PrincipalId>, C<GroupMembers.GroupId> and C<Attachments.TransactionId>,
893 but new tables are expected to be consistent.
894
895
896 =head1 EXTENDING RT CLASSES
897
898 =head2 The Overlay mechanism
899
900 RT's classes allow "overlay" methods to be placed into files named Filename_Vendor.pm and Filename_Local.pm
901 _Vendor is for 3rd-party vendor add-ons, while _Local is for site-local customizations.
902
903 These overlay files can contain new subs or subs to replace existing subs in this module.
904
905 Each of these files should begin with the line
906
907    no warnings qw(redefine);
908
909 so that perl does not kick and scream when you redefine a subroutine or variable in your overlay.
910
911 =head1 TO DO
912
913 Talk about DBIx::SearchBuilder
914
915 Talk about mason
916         component style
917         cascading style sheets
918          
919 Talk about adding a new translation
920
921 Talk more about logging
922
923 =head1 CHANGES
924
925         Adapted from Slash Styleguide by jesse - 20 Dec, 2002
926
927
928 =head1 VERSION
929
930 0.1