From 5ef80a1f93c395a3aca68b8e7161ecf44843061c Mon Sep 17 00:00:00 2001 From: Vladimir Diaz Date: Mon, 27 Nov 2017 16:35:42 -0500 Subject: [PATCH 1/4] Add guideline for ignored values --- README.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 357afe0..f2bbd6c 100644 --- a/README.md +++ b/README.md @@ -650,7 +650,24 @@ underscore if a separation is needed, such as: popanitem or pop_an_item Variables which are set once and never change value should be all upper case, if a seperator is needed use an underscore. - + +### Ignored Values ### + +The variable name `junk` should be used in cases where a returned valued must be +stored but the variable itself is unneeded. + + No: + +```Python +for _ in range(10): + do_something() +``` + + Yes: +```Python +junk, surname = get_full_name() +print("Hello, Mr. " + surname) +``` ### Exception Names ### From 5b03579a5788254c2cc57364da36e7d164801d2a Mon Sep 17 00:00:00 2001 From: Vladimir Diaz Date: Tue, 28 Nov 2017 11:29:53 -0500 Subject: [PATCH 2/4] Add more examples and explanation --- README.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f2bbd6c..5c3eebd 100644 --- a/README.md +++ b/README.md @@ -656,6 +656,12 @@ if a seperator is needed use an underscore. The variable name `junk` should be used in cases where a returned valued must be stored but the variable itself is unneeded. + Yes: +```Python +junk, surname = get_full_name() +print("Hello, Mr. " + surname) +``` + No: ```Python @@ -665,10 +671,21 @@ for _ in range(10): Yes: ```Python -junk, surname = get_full_name() +for i in range(10): + print(i) +``` + + No: +```Python +firstname, surname = get_full_name() print("Hello, Mr. " + surname) ``` +The majority of static analysis tools complain if a variable is assigned but not used thereafter. +By convention, unused variables are assigned to `i`, `j`, `k`, and `_` (underscore character) and +understood as such. However, we think `junk` is more readable than `_` and easier for newcomers +to understand. + ### Exception Names ### Because exceptions should be classes, the class naming convention applies here. From 8adefe059b9f4f7e6d6dfea464a667d10678a81c Mon Sep 17 00:00:00 2001 From: Vladimir Diaz Date: Tue, 28 Nov 2017 15:14:45 -0500 Subject: [PATCH 3/4] Replace word: variable -> value --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5c3eebd..8d26f86 100644 --- a/README.md +++ b/README.md @@ -682,9 +682,9 @@ print("Hello, Mr. " + surname) ``` The majority of static analysis tools complain if a variable is assigned but not used thereafter. -By convention, unused variables are assigned to `i`, `j`, `k`, and `_` (underscore character) and -understood as such. However, we think `junk` is more readable than `_` and easier for newcomers -to understand. +By convention, unused values are assigned to `i`, `j`, `k`, and `_` (underscore character) and +are understood as such. However, we think `junk` is more readable than `_` and easier for +newcomers to understand. ### Exception Names ### From f843e088ad43bc94f8a4daa6f55978a77b6f029b Mon Sep 17 00:00:00 2001 From: Vladimir Diaz Date: Wed, 29 Nov 2017 10:17:34 -0500 Subject: [PATCH 4/4] Revise sentence --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8d26f86..ef948f1 100644 --- a/README.md +++ b/README.md @@ -681,7 +681,7 @@ firstname, surname = get_full_name() print("Hello, Mr. " + surname) ``` -The majority of static analysis tools complain if a variable is assigned but not used thereafter. +The majority of tools for static code analysis complain if a variable is assigned but not used thereafter. By convention, unused values are assigned to `i`, `j`, `k`, and `_` (underscore character) and are understood as such. However, we think `junk` is more readable than `_` and easier for newcomers to understand.