list manipulation (initialization, slicing).It simply means that you're using Python's idioms and paradigms well in order to make your cleaner, readable, and highly performant. Pythonic code is a set of idioms, adopted by the Python community. If you want to learn more read the official PEP 8 reference. multi-line comments used in functions (docstrings) should have a short single-line description followed by more text.comments should have a space after the # sign with the first word capitalized.comments should not contradict the code.don't use spaces around the = sign when used to indicate a keyword argument.if operators with different priorities are used, consider adding whitespace around the operators with the lowest priority.always surround binary operators with a single space on either side.avoid extra spaces within brackets or braces.method definitions inside a class are surrounded by a single blank line.top-level function and class definitions are surrounded with two blank lines.avoid multiple statements on the same line.lines should not be longer than 79 characters.indent using 4 spaces (spaces are preferred over tabs).single quotes and double quotes are treated the same (just pick one and be consistent).modules should have short, snake_case names and all lowercase ( numpy).constants should be snake_case and all uppercase ( PI = 3.14159).function names should be snake_case and all lowercase ( quick_sort()).variable names should be snake_case and all lowercase ( first_name).class names should be CamelCase ( M圜lass).The most important rules state the following: It's the most popular guide within the Python community. PEP 8 is a style guide that describes the coding standards for Python. code formatting (indentation, declarations, statements).Each programming language comes with its own coding standards, which should be followed in order to write cleaner code. Code StandardsĬode standards are collections of coding rules, guidelines, and best practices. It also tends to require less documentation. easier to maintain, scale, debug, and refactor.Writing clean code has a number of benefits. Expressive code means that even though we're just providing instructions to a computer, it should still be readable and clearly communicate its intent when read by humans. The code we write should be simple, expressive, and free from more than a few duplicates. Writing code is easy, but writing good, clean code is hard. We (developers) spend way more time reading the code than actually writing it, which is why it's important that we write good code. It's one of the most important aspects of writing quality software. Decorators, Context Managers, Iterators, and GeneratorsĬlean code is a set of rules and principles that helps to keep our code readable, maintainable, and extendable. Functions should only perform a single task Do not use different words for the same concept Use descriptive/intention-revealing names
0 Comments
Leave a Reply. |