Shlomi Fish avatar Shlomi Fish committed 985a0e8

Remove trailing space.

Comments (0)

Files changed (1)

src/tutorials/bad-elements/index.html.wml

 <ol>
 
 <li>
-<a href="https://www.socialtext.net/perl5/prototype">Discussion on the Perl 5 Wiki</a> 
+<a href="https://www.socialtext.net/perl5/prototype">Discussion on the Perl 5 Wiki</a>
 </li>
 
 <li>
 </pre>
 
 <p>
-The same thing holds for unpacking <tt>@ARGV</tt>, the array containing the 
-command-line arguments for a Perl program, or any other array. Don't use 
-<tt>$ARGV[0]</tt>, <tt>$ARGV[1]</tt> etc. directly, but instead unpack 
+The same thing holds for unpacking <tt>@ARGV</tt>, the array containing the
+command-line arguments for a Perl program, or any other array. Don't use
+<tt>$ARGV[0]</tt>, <tt>$ARGV[1]</tt> etc. directly, but instead unpack
 <tt>@ARGV</tt> using the methods given above. For processing
-command line arguments, you should also consider using 
+command line arguments, you should also consider using
 <cpan_self_mod m="Getopt::Long" />.
 </p>
 
 function chop()</a> in order to remove newline characters from the end
 of lines read using the diamond operator (<tt>&lt;&gt;</tt>), because this
 may cause the last character in a line without a line feed character to be
-removed. Instead, use <a 
-href="http://perldoc.perl.org/functions/chomp.html">chomp()</a>. 
+removed. Instead, use <a
+href="http://perldoc.perl.org/functions/chomp.html">chomp()</a>.
 </p>
 
 <p>
 <item id="lowercase_modules_and_pkgs" h="Don't start Modules and Packages with a Lowercase Letter">
 
 <p>
-Both modules and packages (the latter also known as namespaces) and all 
+Both modules and packages (the latter also known as namespaces) and all
 intermediate components thereof should always start with an uppercase letter,
 because modules and packages that start with a lowercase letter are
 reserved for pragmas. So this is bad:
 </pre>
 
 <p>
-An arbitrary C-style for loop can be replaced with a while loop with 
+An arbitrary C-style for loop can be replaced with a while loop with
 a <tt>continue</tt> block.
 </p>
 
 <p>
 Some commenting is too intrusive and interrupts the flow of reading the code.
 Examples for that are the <tt>########################</tt> hard-rules that
-some people put in their code, the comments using multiple 
+some people put in their code, the comments using multiple
 <a href="http://en.wikipedia.org/wiki/Number_sign">number signs ("#")</a>,
 like <tt>####</tt>, or excessively long comment block. Please avoid all those.
 </p>
 
 <p>
 Some schools of software engineering argue that if the code's author feels
-that a comment is needed, it usually indicates that the code is not clear 
+that a comment is needed, it usually indicates that the code is not clear
 and should be factored better (like extracting a method or a subroutine with
 a meaningful name.). It probably does not mean that you should avoid writing
 comments altogether, but excessive commenting could prove as a red flag.
 
 <p>
 Since <a href="$(ROOT)/topics/object-oriented/">Perl objects</a> are simple
-references some programmers are tempted to access them directly: 
+references some programmers are tempted to access them directly:
 </p>
 
 <bad_code>
 <p>
 However, this is sub-optimal as explained in
 <a href="http://www.shlomifish.org/lecture/Perl/Newbies/lecture5/accessors/">the
-Perl 
+Perl
 for Newbies section about "Accessors"</a>, and one should use accessors
 using code like that:
 </p>
 <p>
 Some people use "^" and "$" in regular expressions to mean
 beginning-of-the-string or end-of-the-string. However, they can mean
-beginning-of-a-line and end-of-a-line respectively using the <tt>/m</tt> flag 
+beginning-of-a-line and end-of-a-line respectively using the <tt>/m</tt> flag
 which is confusing. It's a good idea to use <tt>\A</tt> for start-of-string
 and <tt>\z</tt> for end-of-string always, and to specify the <tt>/m</tt> flag
 if one needs to use "^" and "$" for start/end of a line.
 <item id="magic_numbers" h="Magic Numbers">
 
 <p>
-Your code should not include <a href="http://en.wikipedia.org/wiki/Magic_number_%28programming%29#Unnamed_numerical_constants">unnamed 
-numerical constants also known as "magic numbers" or "magic constants"</a>. 
+Your code should not include <a href="http://en.wikipedia.org/wiki/Magic_number_%28programming%29#Unnamed_numerical_constants">unnamed
+numerical constants also known as "magic numbers" or "magic constants"</a>.
 For example, there is one in this code to shuffle a deck of cards:
 </p>
 
 </bad_code>
 
 <p>
-However, it's not necessary to enclose $name in double quotes (i.e: 
-<tt>"$name"</tt>) because it's already a string. Using it by itself as 
+However, it's not necessary to enclose $name in double quotes (i.e:
+<tt>"$name"</tt>) because it's already a string. Using it by itself as
 <tt>$name</tt> will do just fine:
 </p>
 
 <item id="at-array-for-subscripting" h="@array[$idx] for array subscripting">
 
 <p>
-Some newcomers to Perl 5 would be tempted to write <tt>@array[$index]</tt> 
+Some newcomers to Perl 5 would be tempted to write <tt>@array[$index]</tt>
 to subscript a single element out of the array <tt>@array</tt>. However,
 <tt>@array[$index]</tt> is a single-element array <b>slice</b>. To get
 a single subscript out of <tt>@array</tt> use <tt>$array[$idx]</tt> (with
 a dollar sign). Note that if you want to extract several elements, you can
-use an array slice such as <tt>@array[@indexes]</tt> or 
+use an array slice such as <tt>@array[@indexes]</tt> or
 <tt>@array[$x,$y] = @array[$y,$x]</tt>. However, then it's a list which should
 be used in list context.
 </p>
 
 <p>
 One should not create lexical variables called <tt>$a</tt> and <tt>$b</tt>
-because there are built-in-variables called that used for 
+because there are built-in-variables called that used for
 <pdoc_f f="sort">sorting</pdoc_f> and other uses (such as reduce in
 <cpan_self_mod m="List::Util" />), which the lexical variables will interfere
 with:
 .
 .
 \# Won't work now.
-my @array = sort { length($a) &lt;=&gt; length($b) } @other_array; 
+my @array = sort { length($a) &lt;=&gt; length($b) } @other_array;
 </bad_code>
 
 <p>
-Instead, use other single-letter variable names such as 
+Instead, use other single-letter variable names such as
 <tt>$x</tt> and <tt>$y</tt>, or better yet give more descriptive names.
 </p>
 
 <item id="flow-stmts-without-labels" h="Flow Control Statements Without an Explicit Label">
 
 <p>
-One can sometimes see flow-control statements such as 
+One can sometimes see flow-control statements such as
 <pdoc_f f="next"><b>next</b></pdoc_f>, <pdoc_f f="last"><b>last</b></pdoc_f> or
-<pdoc_f f="redo"><b>redo</b></pdoc_f> used without an explicit label following 
-them, in which case they default to re-iterating or breaking out of the 
+<pdoc_f f="redo"><b>redo</b></pdoc_f> used without an explicit label following
+them, in which case they default to re-iterating or breaking out of the
 innermost loop. However, this is inadvisable, because later on, one may modify
 the code to insert a loop in between the innermost loop and the flow control
 statement, which will break the code. So always append a label to "next",
-"last" and "redo" and label your loops accordingly: 
+"last" and "redo" and label your loops accordingly:
 </p>
 
 <pre>
 or even <tt>$array[scalar(@array)-1]</tt>. This duplicates the identifier
 and is error prone and there's a better way to do it in Perl using
 negative indexes. <tt>$array[-1]</tt> is the last element of the array,
-<tt>$array[-2]</tt> is the second-to-last, etc. 
+<tt>$array[-2]</tt> is the second-to-last, etc.
 </p>
 
 </item>
 </p>
 
 <p>
-The solution to this is to use \Q and \E to signify a 
+The solution to this is to use \Q and \E to signify a
 <pdoc_f f="quotemeta">quotemeta()</pdoc_f> portion that will treat the
 interpolated strings as plaintext with all the special characters escaped.
 So the line becomes: <tt>if ($line =~ m{\A\Q$username\E})</tt>.
 It's a good idea not to overuse <tt>$_</tt> because using it, especially in
 large scopes, is prone to errors, including many subtle ones. Most Perl
 operations support operating on other variables and you should use lexical
-variables with meaningful names instead of $_ whenever possible. 
+variables with meaningful names instead of $_ whenever possible.
 </p>
 
 <p>
 <item id="mixing_tabs_and_spaces" h="Mixing Tabs and Spaces">
 
 <p>
-Some improperly configured text editors may be used to write code that, while 
+Some improperly configured text editors may be used to write code that, while
 indented well at a certain tab size looks terrible on other tab sizes, due
 to a mixture of tabs and spaces. So either use tabs for indentation or make
 sure your tab key expands to a constant number of spaces. You may also wish
 <item id="explicit_return" h="No Explicit Returns">
 
 <p>
-As noted in "Perl Best Practices", all functions must have an explicit 
+As noted in "Perl Best Practices", all functions must have an explicit
 <tt>return</tt> statement, as otherwise they implicitly return the last
 expression, which would be subject to change upon changing the code. If you
 don't want the subroutine to return anything (i.e: it's a so-called
 "procedure"), then write <tt>return;</tt> to always return a false value,
-which the caller won't be able to do anything meaningful with. 
+which the caller won't be able to do anything meaningful with.
 </p>
 
 <p>
 Another mistake is to write "return 0;" or "return undef;" to return
 false, because in list context, they will return a one-element list which
-is considered true. So always type <tt>return;</tt> to return false. 
+is considered true. So always type <tt>return;</tt> to return false.
 </p>
 
 </item>
 
 <p>
 Mark Jason Dominus has written about
-<a href="http://perl.plover.com/varvarname.html">varvarname - 
+<a href="http://perl.plover.com/varvarname.html">varvarname -
 "Why it's stupid to `use a variable as a variable name'"</a>, namely if
 <tt>$myvar</tt> is <tt>'foobar'</tt> they want to operate on the value of
 <tt>$foobar</tt>. While there are ways to achieve similar things in Perl,
-the best way is to use <a href="$(ROOT)/topics/hashes/">hashes</a> (possibly 
+the best way is to use <a href="$(ROOT)/topics/hashes/">hashes</a> (possibly
 pointing to complex records with more information) and lookup them by
 the string you want to use. Read the link by MJD for more information.
 </p>
 
 <p>
 It is preferable to write <tt>print {$write_fh} @args</tt>
-over <tt>print $write_fh @args</tt> because the latter can more easily be 
+over <tt>print $write_fh @args</tt> because the latter can more easily be
 mistaken for <tt>print $write_fh, @args</tt> (which does something different)
-and does not provide enough visual hints that you are writing to the 
+and does not provide enough visual hints that you are writing to the
 <tt>$write_fh</tt> filehandle. Therefore, always wrap the file-handle in
 curly braces (so-called "dative block"). (Inspired by "Perl Best Practices").
 </p>
 
 <p>
 However, it is usually better to use <tt>ARGV</tt> instead of <tt>STDIN</tt>
-because it also allows processing the filenames from the command line. This 
+because it also allows processing the filenames from the command line. This
 can also be achieved by simply saying <tt>&lt;&gt;</tt>. So the code becomes:
 </p>
 
 Some people ask about how to add or remove elements to an existing array or
 hash when iterating over them using <tt>foreach</tt> and other loops. The
 answer to that is that Perl will likely not handle it too well, and it expects
-that during loops the keys of a data structure will remain constant. 
+that during loops the keys of a data structure will remain constant.
 </p>
 
 <p>
 
 <p>
 One should not use <tt>perlform</tt> for formatting text, because it makes
-use of global identifiers, and should use the 
-<cpan_self_dist d="Perl6-Form" /> CPAN distribution instead. Also see 
+use of global identifiers, and should use the
+<cpan_self_dist d="Perl6-Form" /> CPAN distribution instead. Also see
 our <a href="$(ROOT)/uses/text-generation/">text generation page</a> for
 more information. (Inspired by "Perl Best Practices").
 </p>
 </bad_code>
 
 <p>
-The problem here is that this allows one to do 
+The problem here is that this allows one to do
 <tt>$my_object_instance-&gt;new</tt> to create a new instance of the object,
 but many people will expect it to be invalid or to clone the object. So don't
 do that and instead write your constructors as:
 {
     my $class = shift;
     my $self  = {};
-    
+
     bless $self, $class;
 }
 </pre>
 
 <p>
-Which will disable it and will just allow 
+Which will disable it and will just allow
 <tt>ref($my_object_instance)-&gt;new(…)</tt>. If you need a clone method,
 then code one called "clone()" and don't use "new" for that.
 </p>
 
 <p>
-(Thanks to 
+(Thanks to
 <a href="http://www.stonehenge.com/merlyn/UnixReview/col52.html">Randal L.
 Schwartz's post "Constructing Objects"</a> for providing the insight to this).
 </p>
 <p>
 See the <a href="http://en.wikipedia.org/wiki/Law_of_Demeter">Wikipedia article
 about "Law of Demeter" for more information</a>. Namely, doing many nested
-method calls like 
+method calls like
 <tt>$self-&gt;get_employee('sophie')-&gt;get_address()-&gt;get_street()</tt>
 is not advisable, and should be avoided.
 </p>
 <item id="duplicate_code" h="Duplicate Code">
 
 <p>
-As noted in 
-<a href="http://www.shlomifish.org/philosophy/books-recommends/#refactoring">Martin 
+As noted in
+<a href="http://www.shlomifish.org/philosophy/books-recommends/#refactoring">Martin
 Fowler's "Refactoring"</a> book (but held as a fact for a long time
-beforehand), 
-<a href="http://en.wikipedia.org/wiki/Duplicate_code">duplicate code</a> is a 
+beforehand),
+<a href="http://en.wikipedia.org/wiki/Duplicate_code">duplicate code</a> is a
 code smell, and should be avoided. The solution is to extract duplicate
 functionality into subroutines, methods and classes.
 </p>
 <item id="long_functions" h="Long Functions and Methods">
 
 <p>
-Another common code smell is 
-<a href="http://c2.com/cgi/wiki?LongMethodSmell">long 
-subroutines and methods</a>. The solution to these is to extract several 
+Another common code smell is
+<a href="http://c2.com/cgi/wiki?LongMethodSmell">long
+subroutines and methods</a>. The solution to these is to extract several
 shorter methods out, with meaningful names.
 </p>
 
 <item id="ternary_operator_instead_of_if_else" h="Using the ternary operator for side-effects instead of if/else">
 
 <p>
-A similar symptom to the above is people who wish to use the ternary 
+A similar symptom to the above is people who wish to use the ternary
 inline- conditional operator (<tt>? :</tt>) for choosing to execute between
 two different statements with side-effects
 instead of using <tt>if</tt> and <tt>else</tt>. For example:
 </p>
 
 <p>
-However, the ternary operator is meant to be an expression that is a choice 
+However, the ternary operator is meant to be an expression that is a choice
 between two values and should not be used for its side-effects. To do the
 latter, just use <tt>if</tt> and <tt>else</tt>:
 </p>
 </pre>
 
 <p>
-This is safer, and better conveys one’s intentions. 
+This is safer, and better conveys one’s intentions.
 </p>
 
 <p>
 <item id="nested_top_level_subroutines" h="Nested top-level subroutines">
 
 <p>
-One should not nest an inner top-level subroutine declared using 
+One should not nest an inner top-level subroutine declared using
 <tt>sub inner</tt> inside of an outer one, like so:
 </p>
 
 </p>
 
 <p>
-The first problem with this approach is that <tt>inner()</tt> will still be 
+The first problem with this approach is that <tt>inner()</tt> will still be
 visible outside <tt>outer()</tt>, but the more serious problem is that the
-inner subroutine will only get one copy of the lexical variables inside 
+inner subroutine will only get one copy of the lexical variables inside
 <tt>outer()</tt>.
 </p>
 
 all. However, grep is intended to extract <b>all</b> matching elements out
 of a list, not just the first one, and as a result will not stop until it
 finds them all. To remedy this look at either <tt>first()</tt> from
-<cpan_self_mod m="List::Util" /> (to find the first match) or 
+<cpan_self_mod m="List::Util" /> (to find the first match) or
 "any/all/notall/none" from <cpan_self_mod m="List::MoreUtils" /> (to find
 whether a single element exists). These better convey one's intention
 and may be more efficient because they stop on the first match.
 
 <p>
 One should note that if one does such lookups often, then they should try
-to use a <a href="$(ROOT)/topics/hashes/">hash</a> instead. 
+to use a <a href="$(ROOT)/topics/hashes/">hash</a> instead.
 </p>
 
 </item>
 <p>
 We are often asked how one can "include" a file in a Perl program (similar
 to <a href="http://php.net/manual/en/function.include.php">PHP's include</a>
-or <a href="http://ss64.com/bash/period.html">the shell's 
+or <a href="http://ss64.com/bash/period.html">the shell's
 "source" or "." operators</a>. The answer is that the better way is to extract
 the common functionality from all the programs into
 <a href="$(ROOT)/topics/modules-and-packages/">modules</a> and load them by
 
 <p>
 Note that <pdoc_f f="do">do</pdoc_f> can be used to evaluate a file (but in
-a different scope), but it's almost always not needed. 
+a different scope), but it's almost always not needed.
 </p>
 
 <p>
 
 <p>
 Some beginners, when thinking they need to multitask their programs start
-thinking they should use perl threads. However, as mentioned in 
+thinking they should use perl threads. However, as mentioned in
 <pdoc d="perlthrtut">perlthrtut</pdoc>, perl threads are very much unlike
 the traditional thread modules, share nothing by default and are in fact
 heavyweight processes (instead of the usual lightweight ones). See also
 
 <p>
 To sum up, usually threads are the wrong answer and you should be using
-forking processes or something like POE (see our 
+forking processes or something like POE (see our
 <a href="$(ROOT)/uses/multitasking/">page about multitasking</a>) instead.
 </p>
 
 <item id="missing-semicolons-at-the-end-of-blocks" h="Missing Semicolons at the end of blocks">
 
 <p>
-The perl interpreter allows one to omit the last trailing semicolon (";") in 
+The perl interpreter allows one to omit the last trailing semicolon (";") in
 the containing block. Like so:
 </p>
 
 </bad_code>
 
 <p>
-However, this isn't a good idea, because it is inconsistent, and may cause 
+However, this isn't a good idea, because it is inconsistent, and may cause
 errors (or obscure failures) if one-or-more statements are added afterwards.
 </p>
 
 <p>
-As a result, you should end every statement with a semicolon (";") even if 
+As a result, you should end every statement with a semicolon (";") even i
 it’s the last one. A possible exception to this may be single-line and/or
 single-statement blocks like in <pdoc_f f="map">map</pdoc_f>.
 </p>
 <item id="list-form-of-open-with-one-arg" h="List form of open with one argument.">
 
 <p>
-Recent versions of of perl introduced the list-forms of piping to and from a 
+Recent versions of of perl introduced the list-forms of piping to and from a
 command, such as <tt>open my $fh, '-|', 'fortune', $collection</tt> or
 <tt>open my $printer, '|-', 'lpr', '-Plp1'</tt>. However, not only they are
-not implemented on Windows and other UNIX-like systems yet, but when one passes 
+not implemented on Windows and other UNIX-like systems yet, but when one passes
 only one argument to them, they pass it to the shell verbatim.
 </p>
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.