Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hidden Whitespace Best Practice

I think most people agree that trailing whitespace is not good practice. A lot of editors will display it for you or automatically strip it out.

Consider this Python function as a simple example:

Whitespace Example Screenshot

The extra whitespace on lines 11 and 13 are wrong. What I'm wondering about is line 10. Should a blank line inside a control block that doesn't change indentation have leading whitespace?

Most editors I've used will keep the cursor at the indentation level from the preceding line, so making a blank line without leading whitespace takes some extra formatting. What's the best practice? Should line 10 have leading whitespace or not?

like image 352
jterrace Avatar asked Dec 20 '22 18:12

jterrace


1 Answers

When it comes to code execution it makes absolutely zero difference; the practice I have seen the most in python IS the one with white spaces, but I don't think anyone can really reasonably say one is objectively better than the other.

like image 200
PinkElephantsOnParade Avatar answered Mar 28 '23 18:03

PinkElephantsOnParade