match braces?

L

lallous

Hello

In C/C++ you use the braces where as in Python you use the indentation
levels.
Most editors offer a Ctrl+[ to match the braces so that you can easily
identify the scopes (more correctly "statements blocks").

I am finding it difficult to see blocks and/or jump from end to start
with some IDE hotkeys, when coding in Python. Any advise?


Thanks,
Elias
 
C

Chris Rebert

Hello

In C/C++ you use the braces where as in Python you use the indentation
levels.
Most editors offer a Ctrl+[ to match the braces so that you can easily
identify the scopes (more correctly "statements blocks").

I am finding it difficult to see blocks

Erm, how does the indentation itself not make it plainly and explicitly clear?
Perhaps you need to set your tabstops wider?

Cheers,
Chris
 
T

Tim Chase

In C/C++ you use the braces where as in Python you use the indentation
levels.
Most editors offer a Ctrl+[ to match the braces so that you can easily
identify the scopes (more correctly "statements blocks").

I am finding it difficult to see blocks and/or jump from end to start
with some IDE hotkeys, when coding in Python. Any advise?

Any editor worth its salt will offer indentation-based folding (I
know vim does, and I would be astonished if emacs didn't. With
other editors, YMMV). You can just collapse the indented section
to get a big-picture view.

-tkc
 
J

Joshua Judson Rosen

Grant Edwards said:
There's only one problem: it doesn't work out-of-the-box. At
least it never has for me. The only thing it knows how to hide
is the entire body of a function definition. I never want to
do that. What I want to do is hide/unhide the blocks within
if/then/else or loops so that the control flow is clearer.
Emacs hs-minor-mode won't do that (at least not for me).

Hm. I wasn't aware of hs-minor-mode. But I've often used
set-selective-display (C-x $), which hides all lines that are indented
more than ARG columns (and un-hides them if you don't give an argument).

But to fulfill the specific request of moving up to the top of a given
block, there's also a `python-beginning-of-block' command in
python-mode (bound to C-c C-u). If you set the mark (C-SPC) before you
do python-beginning-of-block, then you can use `C-x C-x' or `C-u SPC'
to jump back where you were.
 
J

John Nagle

lallous said:
Hello

In C/C++ you use the braces where as in Python you use the indentation
levels.
Most editors offer a Ctrl+[ to match the braces so that you can easily
identify the scopes (more correctly "statements blocks").

I am finding it difficult to see blocks and/or jump from end to start
with some IDE hotkeys, when coding in Python. Any advise?

Write more subroutines.

If indentation gets deep enough that you have problems following
your own code, it's time to break some of the code out as another
function.

John Nagle
 
L

lallous

Hello,

Thank you all for your replies.

A simple suggestion as Chris' actually might help.

I am used to two spaces indentation since years, and apparently two
spaces won't make it clear if no visuals were present (braces, or
begin/end, ...)

Though it is not comfortable to change a style, I will play with 8
spaces indentation, it would naturally make it clearer ;)

--
Elias

In C/C++ you use the braces where as in Python you use the indentation
levels.
Most editors offer a Ctrl+[ to match the braces so that you can easily
identify the scopes (more correctly "statements blocks").
I am finding it difficult to see blocks

Erm, how does the indentation itself not make it plainly and explicitly clear?
Perhaps you need to set your tabstops wider?

Cheers,
Chris
 
S

Steven D'Aprano

Hello,

Thank you all for your replies.

A simple suggestion as Chris' actually might help.

I am used to two spaces indentation since years, and apparently two
spaces won't make it clear if no visuals were present (braces, or
begin/end, ...)

I'm not sure about that.
A two space indent seems pretty obvious to me.
But perhaps that's because I'm using a monospaced font.
I suppose if you use a proportional font, spaces will be much narrower,
and it may be harder to notice the indent.
Though it is not comfortable to change a style, I will play with 8
spaces indentation, it would naturally make it clearer ;)

How about trying four spaces first?
Eight spaces is rather a lot, especially once you get to the third
indent level and a third of the page is whitespace.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,470
Messages
2,571,809
Members
48,797
Latest member
PeterSimpson
Top