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
Ask question #Minimum 100 worIn this project, create the pseudo code from the following request. The program must have some sort of menu that allows users to make selections to

Primitives, Composition, Abstraction, and Patterns   We will  start  by thinking about  how  the  PCAP  framework applies to computer programs, in general. We may do that by

A program to count how many files are on the file system which displays summary information regarding the total number of bytes used by all files and a breakdown of the number of b

Finally! After years of adding unimportant sports, the IOC has finally added Shoe Tying to the Olympics. And you’ve been selected to write the software to handle the judging of t

from urllib2 import urlopen # Open http://placekitten.com/ for reading on line 4! response = kittens.read() body = response[559:1000] # Add your ''print'' statement here!

Structured assignment Once  we have  tuples and lists, we may use  a nice trick  in assignment expression, based  on the packing and unpacking of tuples. >>> a, b, c = 1, 2

how to make a python programme for van der waals equation of state with surface discontinouty

You should use for whenever you can, because  it creates  the structure of your  loops clear. Sometimes, however, you require to do an operation various times, but you don't want t

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

Define a function that draws a pentagon of a size you provide when you call the function. Include a ''''''docstring'''''' as the first line of the function''s body — it tells the p