Tabs not spaces (in GHPython's editor)

Here’s something nobody wants: You hit tab to indent some Python code and four little dots appear in the editor. You continue writing code and indenting a few times until sixteen little dots begin each new line of code. Then you need to dedent out and you find yourself having to carefully remove 8 little spaces that you never wanted in the first place.

This has to change. I don’t care why Rhino doesn’t like tabs, it has to find a way to deal with them. Grasshopper is a forward-thinking, flow-based, user-friendly interface and yet the GHPython editor is even worse than IDLE (which is itself trapped in the year 1999).

Presumably the GHPython editor has to support unicode anyway, so for the life of me I can’t imagine why you can’t store tabs even if it is just some kind of an ugly patch for the text editor. You only need ASCII for tabs, for crying out loud.

You can always convert to spaces when the code is executed, but there is no good reason to have forced tab → space conversions in a tab-centric language like Python.

FWIW Python is a space-indentation based language, as also mentioned in the PEP-8 coding guidelines for Python. IOW the Python way is to have 4 spaces for every indentation…

1 Like

The Python editor is a small utility meant to help to get started writing scripts. You can use full-blown IDEs if you are a developer that is used to a particular platform. For VS tools for Python, we have a guide on even set up debugging, in addition to editing. It’s also possible to do this with other IDEs.

This being said, given the small utility we provide*, we are following PEP8 as @nathanletwory mentions. And, you can move left by 4 spaces using Shift+Tab on a normal cursor. If you select a few lines, and hit Shift+Tab, then the indentation of all those lines moves left of one level (4 spaces each). You can also select a few lines and add indentation by using selection+Tab.

I hope this last part helps, at least a little bit.

*@Alain has been working on a new text area control (the part of the editor where you type text) for Rhino 7 WIP. Maybe he can chime in regarding this particular topic.

It looks like you’re talking about Rhino for Windows. The default follows the PEP-8 recommendation of 4 spaces like mentioned above. There’s a Convert tabs to spaces setting in the Python Options dialog that may help.
There’s a new editor for Rhino for Mac that we’re working on. The default will be the same but it will be configurable.

4 spaces are recommended by PEP 8 but you can use any number of tabs or spaces if you are consistent throughout each individual file.

Sure. Except that any PEP-8 check tool will shout at you for using tabs instead of spaces, and much of the Python world along with those tools.

I personally prefer tabs over spaces.

You can shout back with the first subheading of PEP 8 PEP 8 – Style Guide for Python Code | peps.python.org (and change the settings on your tools)

Though I guess if you want them to adopt and contribute to your open-source Python project then you need to shout judiciously… :slight_smile:

I’ve done that for years, but it appears that Python aficionados are turning a deaf ear and a blind eye to that particular paragraph :slight_smile:

In Blender Python API PEP-8 was lobbied for in 2008-2009 ([Bf-taskforce25] Proposal to follow PEP8 for all python scripting for Blender 2.5 and [Bf-committers] (re) proposal for pep8 for blender scripts). We had many heated discussion in the IRC channel #blendercoders on freenode.net (no longer that active since discussions moved to #blender-coders on https://blender.chat ). The fact remains that foolish consistency warning in Python community means nothing - strongly encouraged means in reality enforced.

1 Like

You are absolutely correct about PEP-8, it does recommend spaces, although IIRC it is meant to apply to Python standard library development, not external projects. As such it based its reasoning on the trend for spaces at the time of its writing. In defense of spaces, Google’s style guide for Python also recommends spaces.

You may notice that Python’s own internal editor (IDLE) does not do a tab to space substitution on its users, nor do any other IDEs or editors that I have used.

User-configurable spacing absolutely works for me. As long as I can say “use tabs not spaces” I won’t get super pissed writing code in the GHPython editor!

Some of us come from Posix environments and despise spaces. To quote our benevolent stable genius GvR:

“My recommendation is to always use tabs on the Mac – then it will
look good on the Mac and at least parse correctly everywhere.
For the same reason I recommend always using tabs on Unix as well
(thus indenting by 8 positions there), but the majority of Python
users seem to be against me.”

https://legacy.python.org/search/hypermail/python-1994q2/0205.html

I am very well aware of the recommendations. You missed the implicit fact that I don’t like PEP-8.

I am a tabs person.

I saw that you said that. I don’t see why any of us have to be affected by PEP-8 if we don’t want to be.
My entire point with this post is that it is regressive to force conversions to spaces in the GHPython editor when the user inputs tab. I threw a wrench in it by referring to Python as “tab-centric”!

The new text area control, as mentioned by @Alain,

so we are listening to your concerns.

Maybe can I ask a favor? Maybe next time can I ask to keep the tones a little more subtle? “I don’t care”, “This has to change”, “for the life of me” and “for crying out loud” are too much, especially because this is the first time you or anyone reports this: a “please” would work just as well. Also, try not to confuse “me/some” with “anybody” (this is a “faulty generalization” fallacy). That you don’t like spaces, is a good enough argument for us. To add to your cause, I don’t like spaces either.

Giulio

3 Likes

This is great, thanks Giulio. Of course I’ll try to keep the tone friendlier next time, communicating over written text has the inherent downside of muddling tone. Cheeky and critical can become one and the same, my intention was the former.

I just saw this rejected Python Enhancement Proposal and thought back to this discussion :smiley: :snake:

Could the ghPython editor have the same super handy option that in the default python editor pleeeeeaaaaase !

image

…Unindenting with spaces is so annoying regardless of whatever standards.

Regards

I’d say please include menu options and keyboard shortcuts for shifting text and text passages left and right, which kind of makes it agnostic of whether the indentation is done with spaces or tabs.

On macOS, you can use either tabs or spaces in the GHPython editor, however it doesn’t seem to recognize 4 spaces from other editors, when copying and pasting, and then you have to go in an change every indentation manually or set the other editor to tabs, which it seems to get.

Hi,
We’re working on the next version of the editor where the tab size can be configured as well as whether tabs or spaces are inserted. When a file is opened the indentation settings will be based on its contents if detect indentation is set.

I logged the request to indent/unindent a selected block of text.

Thanks

1 Like

Hi,

What about a new file ?
Will it be space or tab indented ?
I prefer to have the choice over auto detection which is not bad but should be optional.

Regards.