Initial add of defaria.com
[clearscm.git] / defaria.com / blogs / Status / archives / 000753.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" id="sixapart-standard">
4 <head>
5    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6    <meta name="generator" content="Movable Type 5.2.3" />
7
8    <link rel="stylesheet" href="http://defaria.com/blogs/Status/styles-site.css" type="text/css" />
9    <link rel="alternate" type="application/atom+xml" title="Atom" href="http://defaria.com/blogs/Status/atom.xml" />
10    <link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="http://defaria.com/blogs/Status/index.xml" />
11
12    <title>Status for Andrew DeFaria: Eliminating Perl Syntactic Sugar</title>
13
14    <link rel="start" href="http://defaria.com/blogs/Status/" title="Home" />
15    <link rel="prev" href="http://defaria.com/blogs/Status/archives/000752.html" title="2012-05-11-adefaria" />
16    <link rel="next" href="http://defaria.com/blogs/Status/archives/000754.html" title="Creating Development Schema Repositories" />
17
18    <!--
19 <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
20          xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/"
21          xmlns:dc="http://purl.org/dc/elements/1.1/">
22 <rdf:Description
23     rdf:about="http://defaria.com/blogs/Status/archives/000753.html"
24     trackback:ping="http://defaria.com/mt/mt-tb.cgi/117"
25     dc:title="Eliminating Perl Syntactic Sugar"
26     dc:identifier="http://defaria.com/blogs/Status/archives/000753.html"
27     dc:subject=""
28     dc:description="Programming complex systems is... well... complicated. You need to focus on the task at hand and be able to see the trees from the forest as they say. That&apos;s why I like to eliminate as much what I call syntactic..."
29     dc:creator=""
30     dc:date="2012-08-02T20:13:44-06:00" />
31 </rdf:RDF>
32 -->
33
34
35    
36
37    <script type="text/javascript" src="http://defaria.com/blogs/Status/mt-site.js"></script>
38 </head>
39 <body class="layout-one-column" onload="individualArchivesOnLoad(commenter_name)">
40    <div id="container">
41       <div id="container-inner" class="pkg">
42
43          <div id="banner">
44             <div id="banner-inner" class="pkg">
45                <h1 id="banner-header"><a href="http://defaria.com/blogs/Status/" accesskey="1">Status for Andrew DeFaria</a></h1>
46                <h2 id="banner-description">Searchable status reports and work log</h2>
47             </div>
48          </div>
49
50          <div id="pagebody">
51             <div id="pagebody-inner" class="pkg">
52                <div id="alpha">
53                   <div id="alpha-inner" class="pkg">
54
55                      <p class="content-nav">
56                         <a href="http://defaria.com/blogs/Status/archives/000752.html">&laquo; 2012-05-11-adefaria</a> |
57                         <a href="http://defaria.com/blogs/Status/">Main</a>
58                         | <a href="http://defaria.com/blogs/Status/archives/000754.html">Creating Development Schema Repositories &raquo;</a>
59                      </p>
60
61                      <a id="a000753"></a>
62                      <div class="entry" id="entry-753">
63                         <h3 class="entry-header">Eliminating Perl Syntactic Sugar</h3>
64                         <div class="entry-content">
65                            <div class="entry-body">
66                               <p>Programming complex systems is... well... complicated. You need to focus on the task at hand and be able to see the trees from the forest as they say. That's why I like to eliminate as much what I call syntactic sugar from the language. Syntactic sugar are ornaments, special characters and restating the obvious or default that makes your mind drift from the problem at hand to how to formulate syntactic sugar. Additionally such sugar takes time to type in, is prone to errors if you don't get it right and usually are comprised of characters that, as a touch typist, you have to often stretch to reach on the keyboard.</p>
67
68 <p>Here's an example. Recently I came across the following code:</p>
69
70 <div class="code">
71     delete($self->{'cqc'}->{'fields'}->{'PCP_ID'}) if (exists $self->{'cqc'}->{'fields'}->{'PCP_ID'}); # PCP_ID  is read-only and should not be passed through.<br>
72     delete($self->{'cqc'}->{'fields'}->{'Approved_by_CCB'}) if (exists $self->{'cqc'}->{'fields'}->{'Approved_by_CCB'});<br>
73     delete($self->{'cqc'}->{'fields'}->{'record_type'}) if (exists $self->{'cqc'}->{'fields'}->{'record_type'});<br>
74 </div>
75
76 <p>Now that takes a some time to parse... (Did you see the comment buried in there?) And here's the same code with the syntactic sugar removed:</p>
77
78 <div class="code">
79     delete $self->{cqc}{fields}{PCP_ID};<br>
80     delete $self->{cqc}{fields}{Approved_by_CCB};<br>
81     delete $self->{cqc}{fields}{record_type};<br>
82 </div>
83
84 <p>which do you find easier to read?</p>
85
86 <p><b>Notes:</b></p>
87
88 <ul>
89   <li> Surrounding hash keys with '' is unnecessary unless you use special characters in the key name like spaces and '-'. The '_' character is OK (the Perl interpreter views '-' as a possible subtraction). Use '' for hash keys only when necessary.</li>
90
91   <li>The additional '->' operators are unnecessary. The first one is necessary since $self is a hashref, but after that you don't need them - why type them?</li>
92
93   <li>The delete call need not have (). Granted, delete is a function and some people field all function should have () even if there are no parameters. And yet even people who feel this way rarely use () on Perl builtins like print and die. If you define your subroutines before they are used you can call them without ().</li>
94
95   <li>There's no reason to include "if (exists $self->{'cqc'}->{'fields'}->{'PCP_ID'})". First off, if clauses that follow the statement do not need (). Even "exists" is unnecessary as if it is omitted the if statement works the same anyway. Finally, delete $hashref->{unknown} will not error out if $hashref->{unknown} doesn't exist.</li>
96 </ul>
97                            </div>
98                            <div id="more" class="entry-more">
99                               
100                            </div>
101                         </div>
102                         <p class="entry-footer">
103                            <span class="post-footers">Posted by  on August  2, 2012  8:13 PM</span> <span class="separator">|</span> <a class="permalink" href="http://defaria.com/blogs/Status/archives/000753.html">Permalink</a>
104                         </p>
105                      </div>
106
107                      
108                      <div class="trackbacks">
109                         <h3 id="trackback" class="trackbacks-header">TrackBack</h3>
110                         <div id="trackbacks-info">
111                            <p>TrackBack URL for this entry:<br />http://defaria.com/mt/mt-tb.cgi/117</p>
112                         </div>
113                         <div class="trackbacks-content">
114                            
115                         </div>
116                      </div>
117                      
118
119                      
120                   </div>
121                </div>
122             </div>
123          </div>
124       </div>
125    </div>
126 </body>
127 </html>