[Python-ideas] 80 character line width vs. something wider

Ben Finney ben+python at benfinney.id.au
Wed May 20 02:04:57 CEST 2009


Aaron Rubin <aaron.rubin at 4dtechnology.com>
writes:

> Regarding this and the other notion of 5 or 6 being the proper level of
> indentation:
> 
> class a(object):
>     def method1(simulation=False):
>         try:
>             if simulation:
>                 for x in range(10):
>                     if x>5:
>                         try:
>                             # here might begin some actual math, with two or
> three more levels of logic, interfacing with other libraries such as NumPy,
> etc. where you might need specific error handling
>         except CustomError:
>             # customer error handling

This is fairly clearly a contrived example. Can you give an example of
actual in-use code which suffers from such deep indentation?

I've no doubt you can produce such code, but it's far easier to discuss
ways to improve (and *that* it will improve) an example of actual code
than a contrived example.

> i.e. the logic code *started* at the 7th indentation level.

This would almost certainly be improved by taking some of those
deeply-indented parts and re-factoring them to separate functions. But
again, it's hard to show that without a real example.

-- 
 \        “Holy uncanny photographic mental processes, Batman!” —Robin |
  `\                                                                   |
_o__)                                                                  |
Ben Finney




More information about the Python-ideas mailing list