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
Data array A has data series from 1,000,000 to 1 with step size 1, which is in perfect decreasing order. Data array B has data series from 1 to 1,000,000, which is in random order.

The goal of this exercise is to write a \business phrase" generator, which each time it is called produces lines of business speak, such as: It's time that we became uber-effici

Rewrite the program (shown below, or in the Creating Functions section of the tutorial) so that it has separate functions for the perimeter and area of a square, a rectangl

I need server, client and trusted side communicating and charging a service with that protocol (or needham shroeder)

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

Java programs are  what  is known as statically and  strongly defined.  Thus,  the  kinds  of all the variables must  be known at the time that the program is written. That seems

We encourage you to adopt an interactive style of debugging and programming. Use the Python shell a lot. Write short pieces of code and check them.  It is much  simpler to test the

protocol rdt2.2 considers there is a bit errors between sender to receiver and also from receiver to sender. So now we have to consider checking bit errors introduced in reply from

Non-local references So far, whenever we needed to compute a variable, there  was  a binding for that  variable in the 'local' environment (the environment in which  we were e