Tabs, Spaces, and Scripting

Any good editor papers over the difference between tabs and spaces so that it's unnecessary (e.g, a backspace at a 4-space "tab" automatically removes all 4 spaces in one go. This is how it works in VSCode, Sublime, IntelliJ, PyCharm, etc.)

I'm generally pro-spaces, but I'm much more strongly in the camp of "just use an automated formatter and stop bickering about the shape of the code, the AST is the thing that matters". Unfortunately, Python is one of the unicorns with semantic whitespace, so this kind of debate rages forevermore. And obviously Ignition's situation is far from the ideal software development workflow (much as I'd like to change that over time).

Wait, are you indenting with 3 spaces ?
What kind of monster are you ?


Haha, no I have never indented with spaces, I just assumed that's what people used :person_shrugging:

We had a very odd situation today with tabs and spaces. We had the Whitespace Toggle turned off in a Gateway Tag Change Script event, and it was executing the code improperly. Once the Whitespace Toggle was turned on, we discovered that there were a few lines of code that included both spaces and tabs, and those lines of code were skipped without any error thrown.

We were able to replicate the issue in the console. As you can see from the example below, lines 6 and 7 do not execute and no error is thrown for the mixed spaces and tabs.

As soon as we replace the spaces with tabs, the code executes as expected.

I don't know if it is a bug, but I'm curious if anyone knows if this is expected behavior.

It's expected behavior for Python 2. Python 3 fixed it (it will throw an error at mixed tabs & spaces). The else is being interpreted as closing the first if, rather than the second.

1 Like