Python style, Python Programming

Python  Style

Software  engineering courses  often  provide very  rigid  guidelines on the style of programming, generally the appropriate value of indentation, or what  to use, or whether to capitalize  underscores in variable characters.   Those things may be useful  for uniformity and  readability of program, especially when  a lot of engineers are working on a software.  But they are mostly  arbitrary: a style is chosen for consistency and according to some person's aesthetic preferences.

There  are other  method of style that look, to us, to be more  fundamental, because  they  directly affect the readability or ef?ciency  of the code.

  • Avoid recalculation of the similar value.

You should compute it once and  assign  it to a variable instead; otherwise, if you have  a bug in the calculation (or you  want  to change  the program), you  will have  to modify  it multiple ways.  It is also not efficient.

  • Avoid repetition of a structure of computation.

 

You should use a method instead, again  to avoid  having to change  or debug the same basic code multiple times.

 

  • Avoid numeric indexing.

 

You should need destructuring if possible, since it is much  easier to read the code and therefore easier to get right and to modify later.

 

  • Avoid excessive numeric constants.

 

You should name  the constants, since it is much  easier to read the code and therefore easier to get right and to modify later.

 

Here  are some  examples of simple  procedures that  exhibit  several ?aws.  We'll talk about  what creates  them  problematic.

 

Posted Date: 8/9/2012 7:23:02 AM | Location : United States







Related Discussions:- Python style, Assignment Help, Ask Question on Python style, Get Answer, Expert's Help, Python style Discussions

Write discussion on Python style
Your posts are moderated
Related Questions
Non-local references in procedures There  is an important subtlety in the  way  names  are handled in the  environment created by a function call. When  a value  that  is not

Perimeter of a polygon Now, let's consider the problem of computing the length  of the perimeter of a polygon. The input is a structure of vertices,  encoded as a list of list

Your assignment for the semester will involve the development of a system for drawing trees using the Python programming language and the turtle graphics module (turtle.py). Comple

Modules As you start to write larger programs, you will want  to save the function de?nitions in multiple ?les, collected together according to what  they  do.  So, for exampl

I have a C++ code (10-15 line) which i need to re-write in python with the help of ctypes library. Is it possible i can get some help with it? Thanks & regards Tanmoy

inputWithinRange (prompt, lowValue, highValue) This function will ask for a number using the prompt parameter. The function will only return a value that is within the inclusive ra


Write a program that requests a password after the author/program information is displayed. Make the password "hello". The program should then ask the user for their name: if the n

Write a program that asks the user to enter a number of seconds. The responses of the program will vary depending on the length of seconds: • If the number of seconds is under 60

There are three seating categories at a stadium. For a softball game, Class A seats cost $15, Class B seats cost $12, and Class C seats cost $9. Write a program that asks how many