Take the following text, analyze, understand, reformat. Good Coding Practices Daniel…
- User
Take the following text, analyze, understand, reformat.
Good Coding Practices Daniel Perrefort – University of Pittsburgh What is a Best Practice? Best practices are any procedure that is accepted as being the most effective either by consensus or by prescription. Practices can range from stylistic to in-depth design methodologies. "A universal convention supplies all of maintainability, clarity, consistency, and a foundation for good programming habits too." —Tim Peters on comp.lang.python, 2001-06-16 A Roadmap PEP’s and good styling Writing good documentation How to organize your project Python Enhancement Protocol (PEP) Important Fundamentals PEP 8: Style Guide for Python Code PEP 20: The Zen of Python PEP 257: Docstring Conventions Bonus PEPs PEP 484: Type Hints PEP 498: Literal String Interpolation PEP 572: Assignment Expressions “A PEP is a design document providing information to the Python community, or describing a new feature for Python or its processes or environment.” (PEP 1) PEP 20: The Zen of Python Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than right now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let's do more of those!
import this PEP 8: Style Guide for Python Code Code is read much more often than it is written. Easy to read means easier to develop. Well written code conveys professionalism. Code is a deliverable part of your project! PEP8: Code Layout Using 4 spaces per indentation level (not tabs!) Putting two blank lines before functions and classes Limiting line lengths to: 79 characters for code 72 characters for long blocks of text It is okay to increase the line length limit up to 99 characters Your probably already familiar with… PEP8: Code Layout
!/usr/bin/env python3.7
-- coding: UTF-8 --
"""This is a description of the module.""" import json import os from astropy.table import Table, vstack from my_code import utils version = 0.1 def my_function(): ... PEP 8: Naming Conventions TYPE NAMING CONVENTION EXAMPLES Function Use lowercase words separated by underscores. function, my_function Variable Use lowercase letters or word, or words separated with underscores. (I.e., snake_case) x, var, my_variable Class Start each word with a capital letter. Do not separate words with underscores. (I.e., CamalCase) Model, MyClass Method Use lowercase words separated with underscores. class_method, method Constant Use an uppercase single letter, word, or words separated by underscores. CONSTANT, MY_CONSTANT Module Use short lowercase words separated with underscores. module.py, my_module.py Package Use short lowercase words without underscores. package, mypackage PEP8: General Recommendations Use when comparing singletons Use instead of
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.