Style Guide Kinne

From Computer Science
Revision as of 02:09, 22 April 2020 by Jkinne (talk | contribs) (Created page with "This is a programming style guide for Jeff Kinne's courses that use Python. For other faculty, ask if they want you to follow this or something else. Note that all of these...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This is a programming style guide for Jeff Kinne's courses that use Python. For other faculty, ask if they want you to follow this or something else.

Note that all of these help your code be more readable/understandable and should also reduce the number of mistakes you make. An example file that follows these rules - http://cs.indstate.edu/~jkinne/cs151-f2019/code/multiply.py

Variable names - use meaningful names. You can use i, n, j, k, x, y for integers or numbers if you only have a few of these in your program. The more different variables you are using, the more important that you use a descriptive name.

Function names - use good names for functions that describe what they are doing.

Variable and function names - use camelCase for variable and function names that consist of multiple words. For example, countLines or countEvenLines.

Function comments - right before a function include a brief description of what it does, what the parameters are supposed to mean, if there is a return value what it means, and anything else someone would need to know to be able to call your function properly.

Using functions - break your code into smallish separate tasks that can each be solved with a function. You should not have more than about 20 lines of code in each function, and your main program that uses the functions should not be more than about 20 lines of code.

Empty lines - one before any loop, two before any function definition.

Line length - make your code so it still looks good in the default putty/terminal size (which is normally 80 characters widw).

Top of the file - at the top of your file include - basic purpose of the file / what it does, the name of the authors, a change-log, if you took anything as a starting point (e.g., code from class or something you found online), if you received assistance from anyone (instructor, unix lab, friend, aunt, etc.), and anything someone would need to keep in mind to run your program properly.