4 ms·
I find that significant white space is a problem mainly when going between editors, and also mainly because of space vs. tab problems. E.g. if I copy-paste fro
by webjprgm 15y ago
I find that significant white space is a problem mainly when going between editors, and also mainly because of space vs. tab problems. E.g. if I copy-paste from vim in Terminal into TextWrangler (free BBEdit) then all the tabs have become spaces, which python will throw a fit about. Similarly if I copy-paste code from a website or blog entry.
In languages with () or {} I can hit a key to reformat copy-pasted code. In Python I have to do it manually.
When it comes to moving blocks of Python code around inside one source file, then it's a simple matter to hit the plus/minus indent hotkey.
- falcolas 15y agoUsing tabs instead of spaces is not a recommended practice for Python, or most white space orientated languages that I'm aware of. Adopting that best-practice would seem to alleviate most of your concerns that you've listed here. Most editors even let you handle that on a filetype basis, so you can use 4 spaces for Python, and tabs for your C files.
- kamaal 15y agoWhy should I even waste my time worrying about supplying spaces or tabs every time I go to a new line while programming. That was supposed to be the compilers job. I am here to do mine. No wonder so many people hate whitespace based parsing.
- Bjartr 15y ago>Why should I even waste my time worrying about supplying spaces or tabs every time I go to a new line while programming. What are you talking about? Why wouldn't you have your editor just insert the correct number of spaces when you press the tab key? It's worked fine for all my python work.
- webjprgm 15y agoWhy can't I reply to the reply to my comment? Anyway, that's tab vs. space flamewar, best practices flame war, etc. Long story short, I don't like spaces because editors do not make it as easy to navigate back/forward 4 (or 2) spaces as it is to navigate 1 tab. Most annoying instance of this: what combination of keypresses does it take to get from the middle of a line to the beginning of a line? In Notepad++ it's easy, but it Xcode its cmd-left-arrow then hit right-arrow for every space/tab you need to pass. (Or in general for a Mac text editor cmd-left-arrow, then opt-right arrow, then opt-left arrow, but that doesn't always work right. In TextWrangler it's cmd-left + opt-right, which is better but still slightly tricky hopping from cmd to opt key.)
- Bjartr 15y agoAnd now I'll introduce the editor flamewar: in vim, moving from anywhere on a line to the first non-whitespace character on that line is just ^, moving to the very first character of the line is 0. In general, navigation in vim is whitespace agnostic (inasmuch as you move around by chunks of text, not character by character)