From 5a0d5c2bb7d700343adbef66185675215cc983e5 Mon Sep 17 00:00:00 2001 From: mjfernez Date: Tue, 11 Jul 2023 23:31:16 -0400 Subject: HTML generation --- thoughts/syntax/my-worst-habit.html | 173 +++++++++++- thoughts/syntax/random-python-idiosyncrasies.html | 308 ++++++++++++++++++---- 2 files changed, 417 insertions(+), 64 deletions(-) (limited to 'thoughts') diff --git a/thoughts/syntax/my-worst-habit.html b/thoughts/syntax/my-worst-habit.html index 05a7cb4..65f19d8 100644 --- a/thoughts/syntax/my-worst-habit.html +++ b/thoughts/syntax/my-worst-habit.html @@ -6,18 +6,169 @@ my-worst-habit

Overuse of parentheses, by far.

-

Why is this a bad thing? Parentheses, as read by most readers, tend to contain additional superfluous information when read. So naturally, the mind tends to pay less attention to what's inside (or at least my mind does). I also believe it represents some repressed psychological trauma, since a Professor once circled how many times I abused the double dash, "--", and I haven't quite felt comfortable using it since--unless it feels right. As a result, I've found a new punctuation mark to abuse.

-

The parentheses and double dash work all right in that last paragraph, but relying on it leads to bad habits, and usually, sentences that droll on for far longer than welcome. Consider the following example from Naked Lunch:

+

Why is this a bad thing? Parentheses, as read by most readers, tend +to contain additional superfluous information when read. So +naturally, the mind tends to pay less attention to what's inside (or at +least my mind does). I also believe it represents some repressed +psychological trauma, since a Professor once circled how many times I +abused the double dash, "--", and I haven't quite felt comfortable using +it since--unless it feels right. As a result, I've found a new +punctuation mark to abuse.

+

The parentheses and double dash work all right in that last +paragraph, but relying on it leads to bad habits, and usually, sentences +that droll on for far longer than welcome. Consider the following +example from Naked Lunch:

Doc Browbeck was party inna second part. A retired abortionist and junk
 pusher (he was a veterinarian actually) recalled to service during the
 manpower shortage. Well, Doc had been in the hospital kitchen all
@@ -42,12 +193,22 @@ family in use among the Indians of South America. They are usually
 administered by sniffing a dried powder of the plant. The medicine
 men take these noxious substances and go into convulsive states. Their
 twitchings and mutterings are thought to have prophetic significance.")
-

This is the only example I know that dares to put parentheses and a long quote within parentheses, unless we're counting math textbooks. In a way it works, since if information is ever superfluous, the history of sailors getting high on nutmeg fits that bill. A careful reader might easily pick up on that, but to everyone else, I think a full paragraph of text in parentheses signals the reader to scroll down in the hopes that the story continues.

-

But just in case you think I'm just picking on William S. Burroughs, here's an example I regrettably wrote to a coworker recently with some details removed:

+

This is the only example I know that dares to put parentheses +and a long quote within parentheses, unless we're counting math +textbooks. In a way it works, since if information is ever +superfluous, the history of sailors getting high on nutmeg fits +that bill. A careful reader might easily pick up on that, but to +everyone else, I think a full paragraph of text in parentheses signals +the reader to scroll down in the hopes that the story continues.

+

But just in case you think I'm just picking on William S. Burroughs, +here's an example I regrettably wrote to a coworker recently with some +details removed:

[...] As a precaution, I did review $NOBODY's recent
 $THING_I_WAS_ASKED_TO_REVIEW (if you would like a detailed report on
 that, I can pull that together for you).
-

Somehow, I managed to take the one point worth emphasizing (an entire sentence at that!) and de-emphasized it.

-

It's a habit I can't break. So please, if you are a caring reader, do complain when I overuse parentheses. I deserve it.

+

Somehow, I managed to take the one point worth emphasizing +(an entire sentence at that!) and de-emphasized it.

+

It's a habit I can't break. So please, if you are a caring reader, do +complain when I overuse parentheses. I deserve it.

diff --git a/thoughts/syntax/random-python-idiosyncrasies.html b/thoughts/syntax/random-python-idiosyncrasies.html index fd2336d..dc67e4d 100644 --- a/thoughts/syntax/random-python-idiosyncrasies.html +++ b/thoughts/syntax/random-python-idiosyncrasies.html @@ -6,6 +6,146 @@ random-python-idiosyncrasies @@ -82,78 +224,128 @@

Coding Style Guide

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. -
  3. To ensure I adhere to my own style because I'm terribly inconsistent
  4. +
  5. To ensure that anyone who might like to make my code better +understands why I write python the way I do
  6. +
  7. To ensure I adhere to my own style because I'm terribly +inconsistent
-

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.

-

BUT first and foremost, code must comply with PEP8 first. This is easy to automate. I like black since it's easy to use but there' plenty of advanced linters out there.

-

I usually invoke it like this to turn off forcing double quotes and force the line length to 72:

-
black -S -l 72 file.py
+

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.

+

BUT first and foremost, code must comply with PEP8 +first. This is easy to automate. I like black since it's easy to use +but there' plenty of advanced linters out there.

+

I usually invoke it like this to turn off forcing double quotes and +force the line length to 72:

+
black -S -l 72 file.py

That aside, I have the following idiosyncracies:

-

1) Strings are double-quoted. Keys and chars are single-quoted.

-

This is really just because I like how C does it. And Cpython's C-based so why not?

+

1) +Strings are double-quoted. Keys and +chars are single-quoted.

+

This is really just because I like how C does it. And Cpython's +C-based so why not?

Like so:

-
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 }
-

The only exception is for strings with quotes in them (anything to avoid escapes, really)

-
quoted_string = (
-    '"You miss 100% of the shots you don't take - Wayne Gretsky"'
-    ' - Michael Scott'
-)
+
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 }
+

The only exception is for strings with quotes in them (anything to +avoid escapes, really)

+
quoted_string = (
+    '"You miss 100% of the shots you don't take - Wayne Gretsky"'
+    ' - Michael Scott'
+)

That brings me to my next point.

-

2) Long strings belong in parentheses

+

2) Long strings belong in +parentheses

As in:

-
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."
-)
-

3) Tabs are four spaces and spaces are ALWAYS preferred to tabs

+
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."
+)
+

3) +Tabs are four spaces and spaces are ALWAYS preferred to +tabs

Again, see PEP8.

-

4) Always add spaces between arithmetic, but never for brackets

+

4) +Always add spaces between arithmetic, but never for brackets

It's a pain to read:

-
1/(2*sqrt(pi))*exp(x**2)
+
1/(2*sqrt(pi))*exp(x**2)

Do this

-
1 / (2 * sqrt(pi)) * exp(x ** 2)
+
1 / (2 * sqrt(pi)) * exp(x ** 2)

The same goes for logic operators

-
true & false ^ true
-

5) EVERYTHING should be snake_case

-

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.

-
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
+
true & false ^ true
+

5) EVERYTHING should be +snake_case

+

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.

+
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

Example exception:

-
# this doesn't actually work, but you get the idea
-r = requests.get("www.debian.org")
-pageSize = r.json()['pageSize'] # camel case ok
-

6) If it's over 100 lines, you probably need a new file (and a class)

-

This is more of a general coding thing, but I've encountered so many 1000 line monster out there, I need to reiterate it. I understand how these things come to be, having made a few myself in the beginning. You get an idea and want to see it through in full. Like On the Road it comes out as a scroll Merlin himself would be proud of.

-

But coming back to the scroll in a week half-drunk and half-tired is not a situation you want to be caught in. You can always import any python code you write with a simple:

-
import filename
+
# this doesn't actually work, but you get the idea
+r = requests.get("www.debian.org")
+pageSize = r.json()['pageSize'] # camel case ok
+

6) +If it's over 100 lines, you probably need a new file (and a class)

+

This is more of a general coding thing, but I've encountered so many +1000 line monster out there, I need to reiterate it. I understand how +these things come to be, having made a few myself in the beginning. You +get an idea and want to see it through in full. Like On the +Road it comes out as a scroll Merlin himself would be proud of.

+

But coming back to the scroll in a week half-drunk and half-tired is +not a situation you want to be caught in. You can always import +any python code you write with a simple:

+
import filename

As long as it's in the same directory.

-- cgit v1.2.3