diff options
author | mjfernez <mjf@mjfer.net> | 2021-12-22 16:40:46 -0500 |
---|---|---|
committer | mjfernez <mjf@mjfer.net> | 2021-12-22 16:40:46 -0500 |
commit | d0595724cd13a2274e34a813119cf457a796af75 (patch) | |
tree | 90a3b6d44ff929c47f05b354a5f682f6df6e30f1 /thoughts/syntax/random-python-idiosyncrasies.html | |
parent | 3e87511c9ded4663150d6c4c4a1d829b53a16ed4 (diff) | |
download | site-files-d0595724cd13a2274e34a813119cf457a796af75.tar.gz |
Table of Contents! Adds some works in progress
This commit adds a table of contents generated in the panupdate script.
It also changes some links on the homepage to conform with removing
'/site' as the parent directory
Diffstat (limited to 'thoughts/syntax/random-python-idiosyncrasies.html')
-rw-r--r-- | thoughts/syntax/random-python-idiosyncrasies.html | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/thoughts/syntax/random-python-idiosyncrasies.html b/thoughts/syntax/random-python-idiosyncrasies.html new file mode 100644 index 0000000..80e4563 --- /dev/null +++ b/thoughts/syntax/random-python-idiosyncrasies.html @@ -0,0 +1,85 @@ +<!DOCTYPE html> +<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang=""> +<head> + <meta charset="utf-8" /> + <meta name="generator" content="pandoc" /> + <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" /> + <title>random-python-idiosyncrasies</title> + <style> + code{white-space: pre-wrap;} + span.smallcaps{font-variant: small-caps;} + span.underline{text-decoration: underline;} + div.column{display: inline-block; vertical-align: top; width: 50%;} + div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;} + ul.task-list{list-style: none;} + </style> +</head> +<body> +<nav id="TOC" role="doc-toc"> +<h2 id="toc-title">Contents</h2> +<ul> +<li><a href="#coding-style-guide">Coding Style Guide</a> +<ul> +<li><a href="#strings-are-double-quoted.-keys-and-chars-are-single-quoted.">1) <em>Strings</em> are <em>double-quoted</em>. <em>Keys</em> and <em>chars</em> are <em>single-quoted</em>.</a></li> +<li><a href="#long-strings-belong-in-parentheses">2) Long strings belong in parentheses</a></li> +<li><a href="#tabs-are-four-spaces-and-spaces-are-always-prefered-to-tabs">3) Tabs are four spaces and spaces are <em>ALWAYS</em> prefered to tabs</a></li> +<li><a href="#always-add-spaces-between-arithmetic-but-never-for-brackets">4) Always add spaces between arithmetic, but never for brackets</a></li> +<li><a href="#everything-should-be-snake_case">5) EVERYTHING should be snake_case</a></li> +</ul></li> +</ul> +</nav> +<h1 id="coding-style-guide">Coding Style Guide</h1> +<p>The purpose of this document is twofold: 1) To ensure that anyone who might like to make my code better understands why I write python the way I do 2) to ensure <em>I</em> adhere to my own style because I'm terribly inconsistent</p> +<p>Being terribly inconsistent, the guidelines are not set in stone and if you have a good argument for doing things a particular, I don't really care.</p> +<p><em>BUT</em> first and foremost, <em>code must comply with PEP8 first</em>. This is easy to automate. I like coala since it's friendly but there' plenty of advanced linters out there.</p> +<p>That aside, I have the following idiosyncracies:</p> +<h2 id="strings-are-double-quoted.-keys-and-chars-are-single-quoted.">1) <em>Strings</em> are <em>double-quoted</em>. <em>Keys</em> and <em>chars</em> are <em>single-quoted</em>.</h2> +<p>This is really just because I like how C does it. And Cpython's C-based so why not?</p> +<p>Like so:</p> +<pre class="code"><code>string = "This is a phrase" +word = "word" +cur_char = 'a' +newline = '\n' # note, two characters, but it's still ONE char out +# keys are single-quoted to avoid confusion +dictionary = { 'key' "1245dqw3w431", 'return': newline }</code></pre> +<p>The only exception is for strings with quotes in them (anything to avoid escapes, really)</p> +<pre class="code"><code>quoted_string = ( + '"You miss 100% of the shots you don't take - Wayne Gretsky"' + ' - Michael Scott' +)</code></pre> +<p>That brings me to my next point.</p> +<h2 id="long-strings-belong-in-parentheses">2) Long strings belong in parentheses</h2> +<p>As in:</p> +<pre class="code"><code>longboi = ( + "This is a really long string usefull when making help menus. Be\n" + "sure to leave s space at the end of each line, or add a new line\n" + "when needed.\n\n" + + "Try your best to keep formatting accurate like this." +)</code></pre> +<h2 id="tabs-are-four-spaces-and-spaces-are-always-prefered-to-tabs">3) Tabs are four spaces and spaces are <em>ALWAYS</em> prefered to tabs</h2> +<p>Again, see PEP8.</p> +<h2 id="always-add-spaces-between-arithmetic-but-never-for-brackets">4) Always add spaces between arithmetic, but never for brackets</h2> +<p>It's a pain to read:</p> +<pre class="code"><code>1/(2*sqrt(pi))*exp(x**2)</code></pre> +<p>Do this</p> +<pre class="code"><code>1 / (2 * sqrt(pi)) * exp(x ** 2)</code></pre> +<p>The same goes for logic operators</p> +<pre class="code"><code>true & false ^ true</code></pre> +<h2 id="everything-should-be-snake_case">5) EVERYTHING should be snake_case</h2> +<p>This is python. Unless there's a compatibility thing (like a library's code was written that way, or it matches an API variable), snake_case is preferred.</p> +<pre class="code"><code>user_input = int(input()) # variable +MAX_INPUT = 1000 # constant +def judge_input(_input, _max): # function + if _max > _input: + print("Too big!") + +judge_input(user_input, MAX_INPUT +class Input_Judger: # a class + # etc etc</code></pre> +<p>Example exception:</p> +<pre class="code"><code># this doesn't actually work, but you get the idea +r = requests.get("www.debian.org") +pageSize = r.json()['pageSize'] # camel case ok</code></pre> +</body> +</html> |