Page 1 of 1

Obscenely long variable names

Posted: Sat Feb 27, 2016 6:14 am
by fe2o3
No, I don't use variables names like this but I was testing a thought.

Code: Select all

MicroPython v1.6 on 2016-02-01; PYBv1.0 with STM32F405RG
Type "help()" for more information.
>>> AReallyLongVariableNameThatIsNotAllThatUseful = 42
>>> dir()
['c', 'AReallyLongVariableNameThatIsNotAllThatUseful', '__name__', 'machine', 'pyb', 'Candle']
>>> x="FooBarBazQuux"*20
>>> x
'FooBarBazQuuxFooBarBazQuuxFooBarBazQuuxFooBarBazQuuxFooBarBazQuuxFooBarBazQuuxFooBarBazQuuxFooBarBazQuuxFooBarBazQuuxFooBarBazQuuxFooBarBazQuuxFooBarBazQuuxFooBarBazQuuxFooBarBazQuuxFooBarBazQuuxFooBarBazQuuxFooBarBazQuuxFooBarBazQuuxFooBarBazQuuxFooBarBazQuux'
>>> exec("%s = 69" % x)
>>> dir()
['machine', 'pyb', 'c', 'Candle', 'x', '__name__', 'FooB', 'AReallyLongVariableNameThatIsNotAllThatUseful']
>>> FooB
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'FooB' is not defined
>>> FooBa
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'FooBa' is not defined
>>>
While the little PyBoard held up, I'm more worried about the integrity of RAM at this point. Tab expansion wasn't working on the longest variable name. Just thought I'd throw this out to you developers.

Re: Obscenely long variable names

Posted: Tue Mar 01, 2016 8:03 am
by Damien
If you ran this on the unix port of MicroPython then it should fail an assertion. Such cases should be handled with a proper error message so I think it is worth creating an issue on github for this. It's low priority though :)