[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: how to highlight block end in Python-mode indentation
From: |
Yuri Khan |
Subject: |
Re: how to highlight block end in Python-mode indentation |
Date: |
Sun, 21 May 2017 19:04:47 +0700 |
On Sun, May 21, 2017 at 6:38 PM, Krishnakant <krmane@openmailbox.org> 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
> it.
> 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
out.
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:
return
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”.)
- how to highlight block end in Python-mode indentation, Krishnakant, 2017/05/19
- Re: how to highlight block end in Python-mode indentation, Joost Kremers, 2017/05/19
- Re: how to highlight block end in Python-mode indentation, Tomas Nordin, 2017/05/19
- Re: how to highlight block end in Python-mode indentation, Krishnakant, 2017/05/21
- Re: how to highlight block end in Python-mode indentation, Skip Montanaro, 2017/05/21
- Re: how to highlight block end in Python-mode indentation, Krishnakant, 2017/05/21
- Re: how to highlight block end in Python-mode indentation,
Yuri Khan <=
- Re: how to highlight block end in Python-mode indentation, Krishnakant, 2017/05/21
- Re: how to highlight block end in Python-mode indentation, Skip Montanaro, 2017/05/21
- Re: how to highlight block end in Python-mode indentation, Yuri Khan, 2017/05/21
- Re: how to highlight block end in Python-mode indentation, Krishnakant, 2017/05/21
- Re: how to highlight block end in Python-mode indentation, Skip Montanaro, 2017/05/21
Re: how to highlight block end in Python-mode indentation, Joost Kremers, 2017/05/21