From: Yuri Khan <yuri.v.khan@gmail.com>
To: Krishnakant <krmane@openmailbox.org>
Cc: Skip Montanaro <skip.montanaro@gmail.com>,
"help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
Subject: Re: how to highlight block end in Python-mode indentation
Date: Sun, 21 May 2017 19:04:47 +0700 [thread overview]
Message-ID: <CAP_d_8VtA_RoaJuFXvOFzcriAY_Tzs3XzsPNiUPk9htZcJCgag@mail.gmail.com> (raw)
In-Reply-To: <6624ae5f-ff47-ebd4-2c0f-871c9845d29b@openmailbox.org>
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”.)
next prev parent reply other threads:[~2017-05-21 12:04 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-19 12:01 how to highlight block end in Python-mode indentation Krishnakant
2017-05-19 12:18 ` Joost Kremers
2017-05-19 12:30 ` Krishnakant
2017-05-20 6:37 ` Krishnakant
2017-05-20 8:49 ` Joost Kremers
2017-05-19 19:18 ` Tomas Nordin
2017-05-19 19:43 ` Joost Kremers
2017-05-21 11:16 ` Krishnakant
2017-05-21 11:27 ` Skip Montanaro
2017-05-21 11:38 ` Krishnakant
2017-05-21 12:04 ` Yuri Khan [this message]
2017-05-21 13:46 ` Krishnakant
2017-05-21 14:16 ` Skip Montanaro
2017-05-21 14:45 ` Yuri Khan
2017-05-21 15:58 ` Krishnakant
2017-05-21 12:40 ` Skip Montanaro
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAP_d_8VtA_RoaJuFXvOFzcriAY_Tzs3XzsPNiUPk9htZcJCgag@mail.gmail.com \
--to=yuri.v.khan@gmail.com \
--cc=help-gnu-emacs@gnu.org \
--cc=krmane@openmailbox.org \
--cc=skip.montanaro@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).