[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to highlight block end in Python-mode indentation

From: Krishnakant
Subject: Re: how to highlight block end in Python-mode indentation
Date: Sun, 21 May 2017 19:16:54 +0530
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1

On Sunday 21 May 2017 05:34 PM, Yuri Khan wrote:
On Sun, May 21, 2017 at 6:38 PM, Krishnakant <address@hidden> wrote:

The base is large enough, more than 1500 lines in a buffer (python module ).
That is a lot. See if any top-level functions or classes want to live
in separate modules.

There is a lot of nesting going on and we all know that we do get lost in
Do you have some solution?
Apply Torvalds’ razor: “if you need more than 3 levels of indentation,
you’re screwed[…], and should fix your program”.

See which deep-nested blocks carry out some action that could be given
a name. Extract those as functions. If you see a block of code with an
explanatory comment before it — that’s a function wanting to break

Also, The Zen of Python, item 5: “Flat is better than nested.”

See if you have this pattern:

def …:
     if some condition:
         do something

Rewrite this to:

def …:
     if not some condition:
     do something

Similarly with loops, using “continue”.

Sometimes replacing conditions with conditional expressions (x if y
else z) and loops with comprehensions and utility functions will do
wonders to your nesting levels.

Basically I have now figured out that spaces instead of tabs makes elpy work
fine with highlight-indentation-mode.  So our team will have to switch to
using spaces again.
You use tabs with Python in a *team*?

Print out PEP8. Discuss it with your team. Unless you have good
reasons, format according to that. (Unfortunately, having lots of
existing code qualifies as “good reasons”.)

PEP8 just says about using space.
It is more of a popular way of doing things rather than a highly convincing advantage. I personally worked with both tabs and spaces and never find any major problem as such. Just that I am myself blind and find managing tabs with screen readers more convenient, but I am not against using any style. Never the less found white-space as the default in Emacs and is ok with my team who needs to see the code (unlike me who depends on speech ).
Happy hacking.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]