CiscoDevNet / devnet-express-code-samples

Archived: This repository holds code samples for DevNet Express DNA Track
47 stars 102 forks source link

Standardize Python Indentation - Tabs or Spaces #7

Open cmlccie opened 7 years ago

cmlccie commented 7 years ago

Several students are experiencing 'inconsistent indentation' errors when editing and then executing the sample files.

Current Formating: The sample files (today) are using tabs for indentation.

Problem: The default settings of the Notepad++ editor that many of them are using defaults to converting tabs-to-spaces. When they add new lines to the sample files, their editor is replacing their 'tabs' to spaces and causing the execution errors.

Recommendation: PEP 8 recommends using spaces as the 'leading practice', and recommends that "Tabs should be used solely to remain consistent with code that is already indented with tabs."

Either way (whether we go with tabs or spaces), I recommend that the sample-code files and the IDE settings (at least those in the dCloud environment) be set to use the same formatting. Additionally, with spaces being the 'leading practice', defaulting to this would likely provide greater 'compatibility' with IDEs on users' laptops.

austinMarcos commented 7 years ago

In triage meeting today, decided that this requires further discussion to determine the standard that we want all authors to apply to code samples. Furthermore, will need to decide how we educate and enforce the standard. Our new curator, Diane, might be able to help monitor the usage of tab vs spaces.

cmlccie commented 7 years ago

That's great! I'm glad coding standards are being considered.

Rather than creating something from scratch, and to align with the industry, I would recommend that we simply adopt the industry leading practices (with modification only if it is justifiably necessary). For Python, this would mean adopting PEP8 and possibly either PEP257 or the Google style-guide for docstrings convention.

Another benefit of adopting these industry practices, is that monitoring for consistency also doesn't take too much work, as a code linter (like flake8 or the like) can be used to automate the testing of contributors code.