<p>I've been really enjoying Python programming lately. I come from a background of a strong love for C-based coding, where everything is perhaps more complicated than it should be (but puts hair on your chest, at least). So switching from C to Python for more complex things that don't require tons of speed has been more of a boon than a bane in writing projects.</p>

<p>However, coming from this land of brackets and parentheses and structs as far as the naked eye can see, I come across a small problem: I find Python difficult to read.</p>

<p>For example, the following block of text is hard for me to decipher unless I stare at it (which I dislike doing):</p>

<pre><code>if foo:
   bar = baz
   while bar not biz:
      bar = i_am_going_to_find_you_biz_i_swear_on_my_life()

did_i_not_warn_you_biz()
my_father_is_avenged()
</code></pre>

<p>The problem occurs at the end of that if block: all the tabbing and then suddenly returning to a jarring block feels almost disturbing. As a solution, I've started coding my Python like this:</p>

<pre><code>if foo:
   bar = baz
   while bar not biz:
      bar = i_am_going_to_find_you_biz_i_swear_on_my_life()
   #-- while --
#-- if --

did_i_not_warn_you_biz()
my_father_is_avenged()
</code></pre>

<p>And this, for some odd reason, makes me more able to read my own code. But I'm curious: has anyone else with my strange problem found easier ways to make their tabbed-out code more readable? I'd love to find out if there's a better way to do this before this becomes a huge habit for me.</p>

[{'answer_id': 51505, 'author': 'Anders Sandvig', 'author_id': 1709, 'author_profile': 'https://Stackoverflow.com/users/1709', 'pm_score': 3, 'selected': False, 'text': "<p>You could try increasing the indent size, but in general I would just say, relax, it will come with time. I don't think trying to make Python look like C is a very good idea.</p>\n"}, {'answer_id': 51531, 'author': 'sherbang', 'author_id': 5026, 'author_profile': 'https://Stackoverflow.com/users/5026', 'pm_score': 2, 'selected': False, 'text': '<p>Perhaps the best thing would be to turn on "show whitespace" in your editor.  Then you would have a visual indication of how far in each line is tabbed (usually a bunch of dots), and it will be more apparent when that changes.</p>\n'}, {'answer_id': 51551, 'author': 'Will Harris', 'author_id': 4702, 'author_profile': 'https://Stackoverflow.com/users/4702', 'pm_score': 4, 'selected': False, 'text': '<p>I like to put blank lines around blocks to make control flow more obvious. For example:</p>\n\n<pre><code>if foo:\n   bar = baz\n\n   while bar not biz:\n      bar = i_am_going_to_find_you_biz_i_swear_on_my_life()\n\ndid_i_not_warn_you_biz()\nmy_father_is_avenged()\n</code></pre>\n'}, {'answer_id': 51570, 'author': 'Serafina Brocious', 'author_id': 4977, 'author_profile': 'https://Stackoverflow.com/users/4977', 'pm_score': 3, 'selected': False, 'text': "<p>Rather than focusing on making your existing structures more readable, you should focus on making more logical structures.  Make smaller blocks, try not to nest blocks excessively, make smaller functions, and try to think through your code flow more.</p>\n\n<p>If you come to a point where you can't quickly determine the structure of your code, you should probably consider refactoring and adding some comments.  Code flow should always be immediately apparent -- the more you have to think about it, the less maintainable your code becomes.</p>\n"}, {'answer_id': 52090, 'author': 'Chris Upchurch', 'author_id': 2600, 'author_profile': 'https://Stackoverflow.com/users/2600', 'pm_score': 6, 'selected': True, 'text': "<p>Part of learning a new programming language is learning to read code in that language.  A crutch like this may make it easier to read your own code, but it's going to impede the process of learning how to read anyone else's Python code.  I really think you'd be better off getting rid of the end of block comments and getting used to normal Python.</p>\n"}, {'answer_id': 52111, 'author': 'elarson', 'author_id': 5434, 'author_profile': 'https://Stackoverflow.com/users/5434', 'pm_score': -1, 'selected': False, 'text': "<p>I would look in to understanding more details about Python syntax. Often times if a piece of code looks odd, there usually is a better way to write it. For example, in the above example:</p>\n\n<pre><code>bar = foo if baz else None\nwhile bar not biz:\n    bar = i_am_going_to_find_you_biz_i_swear_on_my_life()\n\ndid_i_not_warn_you_biz()\nmy_father_is_avenged()\n</code></pre>\n\n<p>While it is a small change, it might help the readability. Also, in all honesty, I've never used a while loop, so there is a good change you would end up with a nice concise list comprehension or for loop instead. ;)</p>\n"}, {'answer_id': 3054853, 'author': 'Lloeki', 'author_id': 368409, 'author_profile': 'https://Stackoverflow.com/users/368409', 'pm_score': 0, 'selected': False, 'text': '<pre><code>from __future__ import braces\n</code></pre>\n\n<p>Need I say more? :)</p>\n\n<p>Seriously, <a href="http://www.python.org/dev/peps/pep-0008/" rel="nofollow noreferrer">PEP 8</a>, \'Blank lines\', §4 is the official way to do it.</p>\n'}]
['https://Stackoverflow.com/questions/51502', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5342/']