Style guidelines.pdf - CPSC 111 Introduction to Computing...

This preview shows page 1 - 3 out of 16 pages.

1 CPSC 111: Introduction to Computing Fall 2017 Notes on Python Programming Style A goal of CPSC 111 is for you to learn to write programs that are not only correct but also understandable. These guidelines should help you toward that goal. We ask that you follow these guidelines when writing programs in this course. They will give you a good basis for developing a style of your own as you become a more experienced programmer. This handout includes guidelines for Python constructs that will be covered later in the semester. Skim these sections now and read them more carefully later when the topics are discussed. Reasons for a Disciplined Programming Style Your computer program should be readable, because if it is not readable, the chances of it being correct are slim. Moreover, if your program is unreadable, it will be difficult and time- consuming to find and correct the errors in it. Therefore, The major reason for using a disciplined style of programming is that it will save you time whenever you have to read your program or debug it. Your program should be readable by others, not just you. Consider a program you will write in this course. A grader who has trouble understanding it is not likely to give you good a grade. The more understandable, the simpler your program appears to a grader, the better the grade they will be willing to give you. Outside this course, making programs readable by others becomes even more important. Most programs live a long time and require "maintenance"; changes to adapt to new and different requirements, upgrades in other software, new hardware, etc. Further, the author of the program is quite likely not going to be around when the maintenance is required; someone else must read the program and understand it enough to update it successfully. Even the programs you write for yourself should be readable; if not, four weeks after finishing it you will not remember it enough to make changes simply. Thus, simply for your own sake and for the sake of others, it makes sense to develop programming habits that lend themselves to writing readable, understandable, and correct, programs.
2 Part of these habits concern simple, syntactical measures like indenting program parts properly and using a few conventions for names of variables, methods, etc. However the more important part concerns recording enough information in comments for the reader to understand how a program is designed and why. A computer program is the result of many design decisions. These decisions why this variable was introduced, what that function does, etc. are often not reflected in the final Python code, which consists of low-level, detailed declarations and statements. But, the higher-level design must be understood if a programmer is to modify the program successfully. Trying to understand decisions that are not recorded in comments in the code is tedious, error-prone, and aggravating --but all too common.

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture