Tabs vs Spaces vs Compiled

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
User avatar
mcauser
Posts: 507
Joined: Mon Jun 15, 2015 8:03 am

Tabs vs Spaces vs Compiled

Post by mcauser » Thu Oct 19, 2017 4:24 am

The pyboard has limited flash storage, when the SD card isn't being used.

Taking this average size library as an example:
https://raw.githubusercontent.com/adafr ... tsl2561.py

If I convert tabs to spaces I can store a tiny bit more. Wait... hear me out.
Using spaces = 6923 characters (bytes)
Using tabs = 5882 characters (bytes)
Just over 1kb difference.

When I compile the script though, there is no difference between tabs and spaces.
./mpy-cross tsl2561.py
Compiled = 4821 bytes.

I don't want to start an argument over which is better or bring PEP into this... There's limitless blog posts on that:
https://blog.codinghorror.com/death-to- ... -infidels/
https://www.jwz.org/doc/tabs-vs-spaces.html
http://lea.verou.me/2012/01/why-tabs-ar ... -superior/
https://www.python.org/dev/peps/pep-000 ... -or-spaces

How does everyone store their files on their pyboard's flash?
* Uncompiled and editable for convenience?
* Uncompiled and converted spaces->tabs to fit more in?
* Source files on your host and only copy across the compiled version?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Tabs vs Spaces vs Compiled

Post by Roberthh » Thu Oct 19, 2017 6:40 am

a) I NEVER use tabs in the source code. The potential saving of space is not worth the recurring trouble. And file system space is typicall not the limit.
b) Code under test is as source on the device. If it is too large, it will be split.
c) Stable code is stored as frozen bytecode.
d) In any case, only required code is on the device.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Tabs vs Spaces vs Compiled

Post by pythoncoder » Thu Oct 19, 2017 9:59 am

Agree 100% about never using tabs. They are a nightmare in Python.

I always use an SD card while developing. This saves flash wear and avoids worries about space. Files copy across faster too. If a file gets too big to compile on the Pyboard I cross-compile.

When it comes to testing the real system with no SD card, options are to copy the files to Flash, or if they won't fit to freeze some or all as bytecode.

There is a Python source code minimiser https://liftoff.github.io/pyminifier/ which I used in the early days. Since the advent of frozen bytecode and the cross-compiler I've had no need for it.
Peter Hinch
Index to my micropython libraries.

Post Reply