<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://mscneuro.neuro.uni-bremen.de/index.php?action=history&amp;feed=atom&amp;title=Programming_Recommendations</id>
	<title>Programming Recommendations - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://mscneuro.neuro.uni-bremen.de/index.php?action=history&amp;feed=atom&amp;title=Programming_Recommendations"/>
	<link rel="alternate" type="text/html" href="https://mscneuro.neuro.uni-bremen.de/index.php?title=Programming_Recommendations&amp;action=history"/>
	<updated>2026-06-02T13:25:41Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://mscneuro.neuro.uni-bremen.de/index.php?title=Programming_Recommendations&amp;diff=311&amp;oldid=prev</id>
		<title>Davrot at 15:47, 17 October 2025</title>
		<link rel="alternate" type="text/html" href="https://mscneuro.neuro.uni-bremen.de/index.php?title=Programming_Recommendations&amp;diff=311&amp;oldid=prev"/>
		<updated>2025-10-17T15:47:38Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 15:47, 17 October 2025&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;== The goal ==&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;We want to improve the quality of the code.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;We want to improve the quality of the code.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Davrot</name></author>
	</entry>
	<entry>
		<id>https://mscneuro.neuro.uni-bremen.de/index.php?title=Programming_Recommendations&amp;diff=133&amp;oldid=prev</id>
		<title>Davrot: Created page with &quot; == The goal == We want to improve the quality of the code.  Questions to [mailto:davrot@uni-bremen.de David Rotermund]  = The recommendations =  * Comparisons to singletons like None should always be done with is or is not, never the equality operators. *Use is not operator rather than not … is. While both expressions are functionally identical, the former is more readable and preferred: &lt;syntaxhighlight lang=&quot;python&quot;&gt;# Correct: if foo is not None:&lt;/syntaxhighlight&gt;...&quot;</title>
		<link rel="alternate" type="text/html" href="https://mscneuro.neuro.uni-bremen.de/index.php?title=Programming_Recommendations&amp;diff=133&amp;oldid=prev"/>
		<updated>2025-10-14T16:02:22Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot; == The goal == We want to improve the quality of the code.  Questions to [mailto:davrot@uni-bremen.de David Rotermund]  = The recommendations =  * Comparisons to singletons like None should always be done with is or is not, never the equality operators. *Use is not operator rather than not … is. While both expressions are functionally identical, the former is more readable and preferred: &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;# Correct: if foo is not None:&amp;lt;/syntaxhighlight&amp;gt;...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
== The goal ==&lt;br /&gt;
We want to improve the quality of the code.&lt;br /&gt;
&lt;br /&gt;
Questions to [mailto:davrot@uni-bremen.de David Rotermund]&lt;br /&gt;
&lt;br /&gt;
= The recommendations =&lt;br /&gt;
&lt;br /&gt;
* Comparisons to singletons like None should always be done with is or is not, never the equality operators. *Use is not operator rather than not … is. While both expressions are functionally identical, the former is more readable and preferred:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;# Correct:&lt;br /&gt;
if foo is not None:&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Always use a def statement instead of an assignment statement that binds a lambda expression directly to an identifier:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;# Correct:&lt;br /&gt;
def f(x): return 2*x&lt;br /&gt;
&lt;br /&gt;
# Wrong:&lt;br /&gt;
f = lambda x: 2*x&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Derive exceptions from Exception rather than BaseException.&lt;br /&gt;
* When catching exceptions, mention specific exceptions whenever possible instead of using a bare except: clause:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;try:&lt;br /&gt;
    import platform_specific_module&lt;br /&gt;
except ImportError:&lt;br /&gt;
    platform_specific_module = None&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A bare except: clause will catch SystemExit and KeyboardInterrupt exceptions, making it harder to interrupt a program with Control-C, and can disguise other problems. If you want to catch all exceptions that signal program errors, use except Exception: (bare except is equivalent to except BaseException:).&lt;br /&gt;
* Additionally, for all try/except clauses, limit the try clause to the absolute minimum amount of code necessary. Again, this avoids masking bugs:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;# Correct:&lt;br /&gt;
try:&lt;br /&gt;
    value = collection[key]&lt;br /&gt;
except KeyError:&lt;br /&gt;
    return key_not_found(key)&lt;br /&gt;
else:&lt;br /&gt;
    return handle_value(value)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* When a resource is local to a particular section of code, use a with statement to ensure it is cleaned up promptly and reliably after use. A try/finally statement is also acceptable.&lt;br /&gt;
* Context managers should be invoked through separate functions or methods whenever they do something other than acquire and release resources:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;# Correct:&lt;br /&gt;
with conn.begin_transaction():&lt;br /&gt;
    do_stuff_in_transaction(conn)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Be consistent in return statements. Either all return statements in a function should return an expression, or none of them should. If any return statement returns an expression, any return statements where no value is returned should explicitly state this as return None, and an explicit return statement should be present at the end of the function (if reachable):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;# Correct:&lt;br /&gt;
&lt;br /&gt;
def foo(x):&lt;br /&gt;
    if x &amp;gt;= 0:&lt;br /&gt;
        return math.sqrt(x)&lt;br /&gt;
    else:&lt;br /&gt;
        return None&lt;br /&gt;
&lt;br /&gt;
def bar(x):&lt;br /&gt;
    if x &amp;lt; 0:&lt;br /&gt;
        return None&lt;br /&gt;
    return math.sqrt(x) &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Use ’‘.startswith() and ’’.endswith() instead of string slicing to check for prefixes or suffixes. startswith() and endswith() are cleaner and less error prone:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;# Correct:&lt;br /&gt;
if foo.startswith(&amp;#039;bar&amp;#039;):&lt;br /&gt;
&lt;br /&gt;
# Wrong:&lt;br /&gt;
if foo[:3] == &amp;#039;bar&amp;#039;:&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Object type comparisons should always use isinstance() instead of comparing types directly:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;# Correct:&lt;br /&gt;
if isinstance(obj, int):&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* For sequences, (strings, lists, tuples), use the fact that empty sequences are false:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;# Correct:&lt;br /&gt;
if not seq:&lt;br /&gt;
if seq:&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Don’t write string literals that rely on significant trailing whitespace. Such trailing whitespace is visually indistinguishable and some editors (or more recently, reindent.py) will trim them.&lt;/div&gt;</summary>
		<author><name>Davrot</name></author>
	</entry>
</feed>