PageSourceSearch

https://eecs390.org/style.html

html eecs390.org collected 2026-09-28 07:14:39 UTC 28,787 bytes, 364 lines download raw bytes

1<!DOCTYPE html>
2<!--
3==============================================================================
4           "GitHub HTML5 Pandoc Template" v2.2 — by Tristano Ajmone
5==============================================================================
6Copyright © Tristano Ajmone, 2017-2020, MIT License (MIT). Project's home:
7
8- https://github.com/tajmone/pandoc-goodies
9
10The CSS in this template reuses source code taken from the following projects:
11
12- GitHub Markdown CSS: Copyright © Sindre Sorhus, MIT License (MIT):
13  https://github.com/sindresorhus/github-markdown-css
14
15- Primer CSS: Copyright © 2016-2017 GitHub Inc., MIT License (MIT):
16  http://primercss.io/
17
18~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19The MIT License
20
21Copyright (c) Tristano Ajmone, 2017-2020 (github.com/tajmone/pandoc-goodies)
22Copyright (c) Sindre Sorhus <[email protected]> (sindresorhus.com)
23Copyright (c) 2017 GitHub Inc.
24
25"GitHub Pandoc HTML5 Template" is Copyright (c) Tristano Ajmone, 2017-2020,
26released under the MIT License (MIT); it contains readaptations of substantial
27portions of the following third party softwares:
28
29(1) "GitHub Markdown CSS", Copyright (c) Sindre Sorhus, MIT License (MIT).
30(2) "Primer CSS", Copyright (c) 2016 GitHub Inc., MIT License (MIT).
31
32Permission is hereby granted, free of charge, to any person obtaining a copy
33of this software and associated documentation files (the "Software"), to deal
34in the Software without restriction, including without limitation the rights
35to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
36copies of the Software, and to permit persons to whom the Software is
37furnished to do so, subject to the following conditions:
38
39The above copyright notice and this permission notice shall be included in all
40copies or substantial portions of the Software.
41
42THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
43IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
44FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
45AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
46LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
47OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
48SOFTWARE.
49==============================================================================-->
50<html>
51<head>
52  <meta charset="utf-8" />
53  <meta name="generator" content="pandoc" />
54  <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
55  <title>Coding Standards</title>
56  <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/semantic.min.css">
57  <style type="text/css">
58@charset "UTF-8";.markdown-body{-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;color:#24292e;font-family:-apple-system,system-ui,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";font-size:16px;line-height:1.5;word-wrap:break-word;box-sizing:border-box;
58min-width:200px;max-width:980px;margin:0 auto;padding:45px}.markdown-body a{color:#0366d6;background-color:transparent;text-decoration:none;-webkit-text-decoration-skip:objects}.markdown-body a:active,.markdown-body a:hover{outline-width:0}.markdown-body a:hover{text-decoration:underline}.markdown-body a:not([href]){color:inherit;text-decoration:none}.markdown-body strong{font-weight:600}.markdown-body h1,.markdown-body h2,.markdown-body h3,.markdown-body h4,.markdown-body h5,.markdown-body h6{margin-top:24px;margin-bottom:16px;font-weight:600;line-height:1.25}.markdown-body h1{font-size:2em;margin:.67em 0;padding-bottom:.3em;border-bottom:1px solid #eaecef}.markdown-body h2{padding-bottom:.3em;font-size:1.5em;border-bottom:1px solid #eaecef}.markdown-body h3{font-size:1.25em}.markdown-body h4{font-size:1em}.markdown-body h5{font-size:.875em}.markdown-body h6{font-size:.85em;color:#6a737d}.markdown-body img{border-style:none}.markdown-body svg:not(:root){overflow:hidden}.markdown-body hr{box-sizing:content-box;height:.25em;margin:24px 0;padding:0;overflow:hidden;background-color:#e1e4e8;border:0}.markdown-body hr::before{display:table;content:""}.markdown-body hr::after{display:table;clear:both;content:""}.markdown-body input{margin:0;overflow:visible;font:inherit;font-family:inherit;font-size:inherit;line-height:inherit}.markdown-body [type=checkbox]{box-sizing:border-box;padding:0}.markdown-body *{box-sizing:border-box}.markdown-body blockquote{margin:0}.markdown-body ol,.markdown-body ul{padding-left:2em}.markdown-body ol ol,.markdown-body ul ol{list-style-type:lower-roman}.markdown-body ol ol,.markdown-body ol ul,.markdown-body ul ol,.markdown-body ul ul{margin-top:0;margin-bottom:0}.markdown-body ol ol ol,.markdown-body ol ul ol,.markdown-body ul ol ol,.markdown-body ul ul ol{list-style-type:lower-alpha}.markdown-body li>p{margin-top:16px}.markdown-body li+li{margin-top:.25em}.markdown-body dd{margin-left:0}.markdown-body dl{padding:0}.markdown-body dl dt{padding:0;margin-top:16px;font-size:1em;font-style:italic;font-weight:600}.markdown-body dl dd{padding:0 16px;margin-bottom:16px}.markdown-body code{font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace}.markdown-body pre{font:12px SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;word-wrap:normal}.markdown-body blockquote,.markdown-body dl,.markdown-body ol,.markdown-body p,.markdown-body pre,.markdown-body table,.markdown-body ul{margin-top:0;margin-bottom:16px}.markdown-body blockquote{padding:0 1em;color:#6a737d;border-left:.25em solid #dfe2e5}.markdown-body blockquote>:first-child{margin-top:0}.markdown-body blockquote>:last-child{margin-bottom:0}.markdown-body table{display:block;width:100%;overflow:auto;border-spacing:0;border-collapse:collapse}.markdown-body table th{font-weight:600}.markdown-body table td,.markdown-body table th{padding:6px 13px;border:1px solid #dfe2e5}.markdown-body table tr{background-color:#fff;border-top:1px solid #c6cbd1}.markdown-body table tr:nth-child(2n){background-color:#f6f8fa}.markdown-body img{max-width:100%;box-sizing:content-box;background-color:#fff}.markdown-body code{padding:.2em 0;margin:0;font-size:85%;background-color:rgba(27,31,35,.05);border-radius:3px}.markdown-body code::after,.markdown-body code::before{letter-spacing:-.2em;content:" "}.markdown-body pre>code{padding:0;margin:0;font-size:100%;word-break:normal;white-space:pre;background:0 0;border:0}.markdown-body .highlight{margin-bottom:16px}.markdown-body .highlight pre{margin-bottom:0;word-break:normal}.markdown-body .highlight pre,.markdown-body pre{padding:16px;overflow:auto;font-size:85%;line-height:1.45;background-color:#f6f8fa;border-radius:3px}.markdown-body pre code{display:inline;max-width:auto;padding:0;margin:0;overflow:visible;line-height:inherit;word-wrap:normal;background-color:transparent;border:0}.markdown-body pre code::after,.markdown-body pre code::before{content:normal}.markdown-body .full-commit .btn-outline:not(:disabled):hover{color:#005cc5;border-color:#005cc5}.markdown-body kbd{box-shadow:inset 0 -1px 0 #959da5;display:inline-block;padding:3px 5px;font:11px/10px SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;color:#444d56;vertical-align:middle;background-color:#fcfcfc;border:1px solid #c6cbd1;border-bottom-color:#959da5;border-radius:3px;box-shadow:inset 0 -1px 0 #959da5}.markdown-body :checked+.radio-label{position:relative;z-index:1;border-color:#0366d6}.markdown-body .task-list-item{list-style-type:none}.markdown-body .task-list-item+.task-list-item{margin-top:3px}.markdown-body .task-list-item input{margin:0 .2em .25em -1.6em;vertical-align:middle}.markdown-body::before{display:table;content:""}.markdown-body::after{display:table;clear:both;content:""}.markdown-body>:first-child{margin-top:0!important}.markdown-body>:last-child{margin-bottom:0!important}
58.Alert,.Error,.Note,.Success,.Warning{padding:11px;margin-bottom:24px;border-style:solid;border-width:1px;border-radius:4px}.Alert p,.Error p,.Note p,.Success p,.Warning p{margin-top:0}.Alert p:last-child,.Error p:last-child,.Note p:last-child,.Success p:last-child,.Warning p:last-child{margin-bottom:0}.Alert{color:#246;background-color:#e2eef9;border-color:#bac6d3}.Warning{color:#4c4a42;background-color:#fff9ea;border-color:#dfd8c2}.Error{color:#911;background-color:#fcdede;border-color:#d2b2b2}.Success{color:#22662c;background-color:#e2f9e5;border-color:#bad3be}.Note{color:#2f363d;background-color:#f6f8fa;border-color:#d5d8da}.Alert h1,.Alert h2,.Alert h3,.Alert h4,.Alert h5,.Alert h6{color:#246;margin-bottom:0}.Warning h1,.Warning h2,.Warning h3,.Warning h4,.Warning h5,.Warning h6{color:#4c4a42;margin-bottom:0}.Error h1,.Error h2,.Error h3,.Error h4,.Error h5,.Error h6{color:#911;margin-bottom:0}.Success h1,.Success h2,.Success h3,.Success h4,.Success h5,.Success h6{color:#22662c;margin-bottom:0}.Note h1,.Note h2,.Note h3,.Note h4,.Note h5,.Note h6{color:#2f363d;margin-bottom:0}.Alert h1:first-child,.Alert h2:first-child,.Alert h3:first-child,.Alert h4:first-child,.Alert h5:first-child,.Alert h6:first-child,.Error h1:first-child,.Error h2:first-child,.Error h3:first-child,.Error h4:first-child,.Error h5:first-child,.Error h6:first-child,.Note h1:first-child,.Note h2:first-child,.Note h3:first-child,.Note h4:first-child,.Note h5:first-child,.Note h6:first-child,.Success h1:first-child,.Success h2:first-child,.Success h3:first-child,.Success h4:first-child,.Success h5:first-child,.Success h6:first-child,.Warning h1:first-child,.Warning h2:first-child,.Warning h3:first-child,.Warning h4:first-child,.Warning h5:first-child,.Warning h6:first-child{margin-top:0}h1.title,p.subtitle{text-align:center}h1.title.followed-by-subtitle{margin-bottom:0}p.subtitle{font-size:1.5em;font-weight:600;line-height:1.25;margin-top:0;margin-bottom:16px;padding-bottom:.3em}div.line-block{white-space:pre-line}
59  </style>
60  <style type="text/css">code{white-space: pre;}</style>
61  <style type="text/css">
62pre > code.sourceCode { white-space: pre; position: relative; }
63pre > code.sourceCode > span { line-height: 1.25; }
64pre > code.sourceCode > span:empty { height: 1.2em; }
65.sourceCode { overflow: visible; }
66code.sourceCode > span { color: inherit; text-decoration: inherit; }
67div.sourceCode { margin: 1em 0; }
68pre.sourceCode { margin: 0; }
69@media screen {
70div.sourceCode { overflow: auto; }
71}
72@media print {
73pre > code.sourceCode { white-space: pre-wrap; }
74pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
75}
76pre.numberSource code
77  { counter-reset: source-line 0; }
78pre.numberSource code > span
79  { position: relative; left: -4em; counter-increment: source-line; }
80pre.numberSource code > span > a:first-child::before
81  { content: counter(source-line);
82    position: relative; left: -1em; text-align: right; vertical-align: baseline;
83    border: none; display: inline-block;
84    -webkit-touch-callout: none; -webkit-user-select: none;
85    -khtml-user-select: none; -moz-user-select: none;
86    -ms-user-select: none; user-select: none;
87    padding: 0 4px; width: 4em;
88    color: #aaaaaa;
89  }
90pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa;  padding-left: 4px; }
91div.sourceCode
92  {   }
93@media screen {
94pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
95}
96code span.al { color: #ff0000; font-weight: bold; } /* Alert */
97code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
98code span.at { color: #7d9029; } /* Attribute */
99code span.bn { color: #40a070; } /* BaseN */
100code span.bu { color: #008000; } /* BuiltIn */
101code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
102code span.ch { color: #4070a0; } /* Char */
103code span.cn { color: #880000; } /* Constant */
104code span.co { color: #60a0b0; font-style: italic; } /* Comment */
105code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
106code span.do { color: #ba2121; font-style: italic; } /* Documentation */
107code span.dt { color: #902000; } /* DataType */
108code span.dv { color: #40a070; } /* DecVal */
109code span.er { color: #ff0000; font-weight: bold; } /* Error */
110code span.ex { } /* Extension */
111code span.fl { color: #40a070; } /* Float */
112code span.fu { color: #06287e; } /* Function */
113code span.im { color: #008000; font-weight: bold; } /* Import */
114code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
115code span.kw { color: #007020; font-weight: bold; } /* Keyword */
116code span.op { color: #666666; } /* Operator */
117code span.ot { color: #007020; } /* Other */
118code span.pp { color: #bc7a00; } /* Preprocessor */
119code span.sc { color: #4070a0; } /* SpecialChar */
120code span.ss { color: #bb6688; } /* SpecialString */
121code span.st { color: #4070a0; } /* String */
122code span.va { color: #19177c; } /* Variable */
123code span.vs { color: #4070a0; } /* VerbatimString */
124code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
125  </style>
126  <link rel="stylesheet" href="assets/css/darkmode.css">
127  <!--[if lt IE 9]>
128    
128<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
128
129  <![endif]-->
130</head>
131<body>
132<article class="markdown-body">
133<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/darkmode-js.min.js"></script>
vendor: 1 bytes, line 133
133
134<script>
135const darkmode = new Darkmode({label: '🌓'});
136darkmode.showWidget();
137</script>
137
138<header>
139<!-- (disabled) h1 class="title">Coding Standards</h1-->
140</header>
141<h1 id="coding-standards">Coding Standards<a href="#coding-standards"
142id="classes" class="section-link" title="coding-standards"> <i class="small linkify icon"></i></a></h1>
143<p>Good code must be readable, maintainable, and make proper use of
144abstractions, in addition to behaving correctly. As such, we will be
145grading programming projects not just for functionality, but also for
146programming practices and style.</p>
147<!-- toc -->
148<ul>
149<li><a href="#python">Python</a>
150<ul>
151<li><a href="#automated-style-checking-for-python">Automated Style
152Checking for Python</a>
153<ul>
154<li><a href="#advice">Advice</a>
155<ul>
156<li><a href="#visual-conflicts-with-multiline-conditionals">Visual
157Conflicts with Multiline Conditionals</a></li>
158<li><a href="#unused-arguments">Unused Arguments</a></li>
159<li><a href="#positional-arguments-appear-to-be-out-of-order">Positional
160Arguments Appear to be Out of Order</a></li>
161</ul></li>
162</ul></li>
163</ul></li>
164<li><a href="#programming-practices">Programming Practices</a>
165<ul>
166<li><a href="#recursion">Recursion</a></li>
167<li><a href="#object-orientation">Object Orientation</a></li>
168</ul></li>
169</ul>
170<!-- tocstop -->
171<h1 id="python">Python<a href="#python" id="classes"
172class="section-link" title="python"> <i class="small linkify icon"></i></a></h1>
173<p>We will adhere to the standard style guides for Python, specifically
174<a href="https://www.python.org/dev/peps/pep-0008/">PEP 8</a> for code
175and <a href="https://www.python.org/dev/peps/pep-0257/">PEP 257</a> for
176documentation. We recommend reading through both guides before writing
177any code.</p>
178<h2 id="automated-style-checking-for-python">Automated Style Checking
179for Python<a href="#automated-style-checking-for-python" id="classes"
180class="section-link" title="automated-style-checking-for-python">
181<i class="small linkify icon"></i></a></h2>
182<p>Python has a number of automated tools for style checking. We will
183use the following tools:</p>
184<ul>
185<li><a href="https://github.com/PyCQA/pycodestyle">pycodestyle</a> for
186PEP-8 compliance</li>
187<li><a href="https://github.com/PyCQA/pydocstyle">pydocstyle</a> for
188PEP-257 compliance</li>
189<li><a href="https://www.pylint.org/">Pylint</a> for static checking of
190Python code</li>
191</ul>
192<p>As these tools are constantly evolving, we will use pinned versions
193so that you have a fixed set of targets to which you can write your
194code. The following will install these pinned versions in your Python
195environment:</p>
196<pre class="console"><code>$ wget https://eecs390.github.io/website/requirements.txt
197$ pip3 install -r requirements.txt</code></pre>
198<p>We recommend using a <a
199href="https://eecs485staff.github.io/p1-insta485-static/setup_virtual_env.html">Python
200virtual environment</a>.</p>
201<p>For some projects, we will use these tools without any command-line
202options:</p>
203<pre class="console"><code>$ pycodestyle graph.py graph_test.py pagerank.py
204$ pydocstyle graph.py graph_test.py pagerank.py
205$ pylint graph.py graph_test.py pagerank.py
206
207--------------------------------------------------------------------
208Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)
209</code></pre>
210<p>For other projects, we will customize the behavior with command-line
211arguments. We will provide <code>Makefile</code> targets to run the
212tools with the appropriate arguments:</p>
213<pre class="console"><code>$ make style-pycode
214pycodestyle ucbase.py ucexpr.py ucfunctions.py ucstmt.py uctypes.py
215$ make style-pydoc
216pydocstyle ucbase.py ucexpr.py ucfunctions.py ucstmt.py uctypes.py
217$ make style-pylint
218pylint --max-args=6 --max-module-lines=1500 ucbase.py ucexpr.py ucfunctions.py ucstmt.py uctypes.py
219
220--------------------------------------------------------------------
221Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)
222
223$ make style
224pycodestyle ucbase.py ucexpr.py ucfunctions.py ucstmt.py uctypes.py
225pydocstyle ucbase.py ucexpr.py ucfunctions.py ucstmt.py uctypes.py
226pylint --max-args=6 --max-module-lines=1500 ucbase.py ucexpr.py ucfunctions.py ucstmt.py uctypes.py
227
228--------------------------------------------------------------------
229Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)
230</code></pre>
231<p>You may not use any directives to disable the checks in these tools.
232Specifically, we prohibit the text <code>pylint</code> or
233<code>noqa</code> from appearing in any of the Python files you
234submit.</p>
235<h3 id="advice">Advice<a href="#advice" id="classes"
236class="section-link" title="advice"> <i class="small linkify icon"></i></a></h3>
237<p>In some cases, the automated tools take positions that are stricter
238than those in PEP 8. We will discuss some of these situations here and
239provide advice on how to satisfy the tools.</p>
240<h4 id="visual-conflicts-with-multiline-conditionals">Visual Conflicts
241with Multiline Conditionals<a
242href="#visual-conflicts-with-multiline-conditionals" id="classes"
243class="section-link"
244title="visual-conflicts-with-multiline-conditionals"> <i class="small linkify icon"></i></a></h4>
245<p>PEP 8 explicitly takes no position on indentation for multiline
246conditionals, where the second and subsequent lines are not visually
247distinguishable from the nested suite:</p>
248<div class="sourceCode" id="cb4"><pre
249class="sourceCode python"><code class="sourceCode python"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a>    <span class="cf">if</span> (prompt <span class="kw">is</span> <span class="kw">not</span> <span class="va">None</span> <span class="kw">and</span> line <span class="op">!=</span> <span class="st">&#39;&#39;</span> <span class="kw">and</span></span>
250<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a>        <span class="kw">not</span> line.lstrip().startswith(comment)):</span>
251<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a>        <span class="bu">print</span>(prompt <span class="op">+</span> line)</span></code></pre></div>
252<p>On the other hand, Pylint does not permit multiline conditionals to
253be indented as above. Instead, indent the conditional as one of the
254following:</p>
255<div class="sourceCode" id="cb5"><pre
256class="sourceCode python"><code class="sourceCode python"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a>    <span class="cf">if</span> (prompt <span class="kw">is</span> <span class="kw">not</span> <span class="va">None</span> <span class="kw">and</span> line <span class="op">!=</span> <span class="st">&#39;&#39;</span> <span class="kw">and</span></span>
257<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a>            <span class="kw">not</span> line.lstrip().startswith(comment)):</span>
258<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a>        <span class="bu">print</span>(prompt <span class="op">+</span> line)</span>
259<span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a></span>
260<span id="cb5-5"><a href="#cb5-5" aria-hidden="true" tabindex="-1"></a>    <span class="cf">if</span> (</span>
261<span id="cb5-6"><a href="#cb5-6" aria-hidden="true" tabindex="-1"></a>            prompt <span class="kw">is</span> <span class="kw">not</span> <span class="va">None</span> <span class="kw">and</span> line <span class="op">!=</span> <span class="st">&#39;&#39;</span> <span class="kw">and</span></span>
262<span id="cb5-7"><a href="#cb5-7" aria-hidden="true" tabindex="-1"></a>            <span class="kw">not</span> line.lstrip().startswith(comment)</span>
263<span id="cb5-8"><a href="#cb5-8" aria-hidden="true" tabindex="-1"></a>    ):</span>
264<span id="cb5-9"><a href="#cb5-9" aria-hidden="true" tabindex="-1"></a>        <span class="bu">print</span>(prompt <span class="op">+</span> line)</span></code></pre></div>
265<p>The second and subsequent lines of the test are indented a total of
266eight spaces beyond the level of the conditional. This avoids a visual
267confict with the indentation of the nested suite.</p>
268<h4 id="unused-parameters">Unused Parameters<a href="#unused-parameters"
269id="classes" class="section-link" title="unused-parameters"> <i class="small linkify icon"></i></a></h4>
270<p>Pylint will flag function parameters that are unused in the body. In
271some cases, however, the parameter is required to adhere to a specific
272interface, such as when overriding a method or using higher-order
273functions. In such a case, start the parameter name with an underscore
274to indicate that the parameter may be ignored:</p>
275<div class="sourceCode" id="cb6"><pre
276class="sourceCode python"><code class="sourceCode python"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a>    <span class="kw">def</span> <span class="bu">map</span>(<span class="va">self</span>, _func):</span>
277<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a>
277        <span class="co">&quot;&quot;&quot;Map the given function across the items in this list.&quot;&quot;&quot;</span></span>
278<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a>        <span class="cf">return</span> <span class="va">self</span></span></code></pre></div>
279<h4 id="positional-arguments-appear-to-be-out-of-order">Positional
280Arguments Appear to be Out of Order<a
281href="#positional-arguments-appear-to-be-out-of-order" id="classes"
282class="section-link"
283title="positional-arguments-appear-to-be-out-of-order"> <i class="small linkify icon"></i></a></h4>
284<p>If a function call’s arguments are identifiers that are exactly the
285same as the callee’s parameter names, but in a different order, Pylint
286warns that this may be erroneous. The following is an example:</p>
287<div class="sourceCode" id="cb7"><pre
288class="sourceCode python"><code class="sourceCode python"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a><span class="kw">def</span> absdiff(arg1, arg2):</span>
289<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a>    <span class="co">&quot;&quot;&quot;Return the absolute difference between arg1 and arg2.&quot;&quot;&quot;</span></span>
290<span id="cb7-3"><a href="#cb7-3" aria-hidden="true" tabindex="-1"></a>    <span class="cf">return</span> <span class="bu">abs</span>(diff(arg2, arg1))</span>
291<span id="cb7-4"><a href="#cb7-4" aria-hidden="true" tabindex="-1"></a></span>
292<span id="cb7-5"><a href="#cb7-5" aria-hidden="true" tabindex="-1"></a></span>
293<span id="cb7-6"><a href="#cb7-6" aria-hidden="true" tabindex="-1"></a><span class="kw">def</span> diff(arg1, arg2):</span>
294<span id="cb7-7"><a href="#cb7-7" aria-hidden="true" tabindex="-1"></a>    <span class="co">&quot;&quot;&quot;Return the difference between arg1 and arg2.&quot;&quot;&quot;</span></span>
295<span id="cb7-8"><a href="#cb7-8" aria-hidden="true" tabindex="-1"></a>    <span class="cf">return</span> arg1 <span class="op">-</span> arg2</span></code></pre></div>
296<p>Here, the call to <code>diff()</code> passes the identifiers
297<code>arg2</code> and <code>arg1</code> in a different order than they
298appear in the parameter list of the definition of <code>diff()</code>.
299Since <code>absdiff()</code> is commutative, this happens to not be
300erroneous here, but there are other contexts in which such a mismatch is
301likely to be erroneous, motivating the Pylint warning.</p>
302<p>There are several ways to work around this warning if the reordering
303is actually intended. One example is to introduce new variable names
304that are different than those in the callee:</p>
305<div class="sourceCode" id="cb8"><pre
306class="sourceCode python"><code class="sourceCode python"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><span class="kw">def</span> absdiff(arg1, arg2):</span>
307<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a>    <span class="co">&quot;&quot;&quot;Return the absolute difference between arg1 and arg2.&quot;&quot;&quot;</span></span>
308<span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a>    value1, value2 <span class="op">=</span> arg2, arg1</span>
309<span id="cb8-4"><a href="#cb8-4" aria-hidden="true" tabindex="-1"></a>    <span class="cf">return</span> <span class="bu">abs</span>(diff(value1, value2))</span></code></pre></div>
310<h1 id="programming-practices">Programming Practices<a
311href="#programming-practices" id="classes" class="section-link"
312title="programming-practices"> <i class="small linkify icon"></i></a></h1>
313<p>Some projects will also be hand-graded for programming practices such
314as making appropriate use of recursion and object-orientation and
315avoiding code duplication. The following are some of the pitfalls that
316we look for when hand grading:</p>
317<ul>
318<li>significant code duplication</li>
319<li>non-descriptive variable, function, or class names</li>
320<li>avoiding the recursive leap of faith, leading to unnecessary cases
321in recursive functions</li>
322<li>overly lengthy or nested code, where helper functions should be used
323instead</li>
324<li>use of <code>isinstance()</code>, <code>@singledispatch</code>,
325<code>match</code>
325, and similar patterns where method overriding can be
326used more cleanly (note that we do not prohibit all uses of
327<code>isinstance()</code>, <code>@singledispatch</code>, or
328<code>match</code>, just the ones that are unnecessary)</li>
329<li>unnecessary conditional or boolean logic (e.g. comparing to true or
330false, patterns such as “if test then true else false” instead of using
331the truth value of “test” directly, and so on)</li>
332<li>use of a big conditional to test membership in a set rather than
333data structures or functions that are designed for this purpose</li>
334<li>outdated comments or commented-out code, which make the code harder
335to read, understand, and maintain</li>
336<li>missing or uninformative documentation</li>
337</ul>
338<h2 id="recursion">Recursion<a href="#recursion" id="classes"
339class="section-link" title="recursion"> <i class="small linkify icon"></i></a></h2>
340<p>Recursive functions should avoid unnecessary code repetition and
341properly respect the abstraction barrier between an initial case and a
342recursive step. When work can be done by a recursive call, you should
343make the recursive call rather than repeating the computation in the
344caller.</p>
345<h2 id="object-orientation">Object Orientation<a
346href="#object-orientation" id="classes" class="section-link"
347title="object-orientation"> <i class="small linkify icon"></i></a></h2>
348<p>When writing object-oriented code, make appropriate use of
349inheritance and polymorphism to avoid code duplication and hard-coding
350types. Code that is shared among several classes should be written once
351in a base class and inherited. Derived-class methods that add
352functionality to that of the base-class method should make a call to the
353base-class method (using a mechanism such as <code>super()</code> in
354Python) rather than duplicating code. Method overriding should be used
355to customize behavior in a derived class, rather than type introspection
356(e.g. <code>isinstance()</code> in Python) followed by manual dispatch
357to custom code. Implicit dispatch-on-type via
358<code>@singledispatch</code> or <code>match</code> should also be
359avoided when method overriding can be used instead.</p>
360<!-- Prevent this doc from being picked up by search engines -->
361<meta name="robots" content="noindex" />
362</article>
363</body>
364</html>

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.