The content of this blog is my personal opinion only. Although I am an employee - currently of Nvidia, in the past of other companies such as Iagination Technologies, MIPS, Intellectual Ventures, Intel, AMD, Motorola, and Gould - I reveal this only so that the reader may account for any possible bias I may have towards my employer's products. The statements I make here in no way represent my employer's position, nor am I authorized to speak on behalf of my employer. In fact, this posting may not even represent my personal opinion, since occasionally I play devil's advocate.

See http://docs.google.com/View?id=dcxddbtr_23cg5thdfj for photo credits.

Friday, May 20, 2016

I like Python's brevity

I like Python's brevity.


Actually, I like Python's use of indentation.  It makes the code more readable.  It closely corresponds to how many people write pseudocode on paper.  (Now, if the code could only contain vertical bars down the left, the number of which indicate the nesting level.  Hmm, I wonder

In most respects, Python is NOT a language of brevity.   Python code is often verbose.

But the use of indentation is elegant and reduces clutter.

(Perl's sigils? clutter!)

I am amused that Python3 is increasing the amount of syntactic clutter, by requiring parentheses around the arguments to print - print("a") versus pythin2 print "a".

It's a pity that Python3 could not figure out a way to allow function calls without ()s.

less than function Block scope in Python

Block scope in Python - Stack Overflow: "No, there is no [python] language support for creating block scope. The only means to create scope is functions, classes or modules."
Someone else goes on to say: "The idiomatic way in Python is to keep your functions short. If you think you need this, refactor your code! :) "
I could very much like Python - but whenever I try to use it, I run into things like this very quickly.

I like Python's use of indentation.

But I imagine that the reasoning runs like this:
  • Python uses indentation and hence doesn't need {...} to provide blocks for constructs like IF, functions, etc.
  • But since Python doesn't have {...} blocks, we have no way to provide lexial scope except for def: and class: and modules.
  • "Who needs it anyway?" says the chorus of unimaginative twerps. "Just refactor".
So think about refactoring: you could introduce a function with def, and then call it immediately.  Must make sure tat the function cannot be called from elsewhere, but Python allowing local definitions (not-quite-closures) is sufficient for that. But that requires typing the name in twice.  

I have been doing the following in some python code:
if 1:
when I want to emphasize the relatedness of statements3.1 and 3.2.

The equivalent of 
in Perl or C.

(Amusingly, emacs often requires me if add an if(1) to the blocks {}.  It doesn't like indented "blocks in space".  After all, what crazy person would want to create lots of local blocks?)

I like indicating the relatedness.

Plus, if I need a temporary variable or to import a function, I like to be able to do so in the smallest scope possible.

Yes, it can be refactored to be a function that is immediately invoked.  But that is repetitive.

This explores aspects of one of my rules "The most important thing in programming is the ability to give something a name.  The second most important thing is to not be required to give something a name."

Python requires scopes to have names.   It fails the second most important test.


The obvious way to support scopes in an indentation oriented language like Python would be:

i.e. introduce a keyword "scope" or the like.

Wanted: portable labelmaker, USB charge, upload label and location to database

I just spent ... more time than I want to admit ... searching for the lost AC adapter for my label printer.
DYMO LabelManager 280D Label Maker:
Rechargeable Battery Pack
USB Cable
Charging Adapter
Damn! You would think that if it has a USB port, it could be charged via USB!!!!

I can understand that it might not be possible to operate via USB, if the labelmaker thermal printer takes too much power during operation.  But at least it could charge the battery!

Here's a Product I Want:
  • LabelMaker
  • Battery powered
  • USB
    • to charge battery
    • for data communication with a controlling device
      • PREFERRED: to mobile device (cell phone, tablet)
      • LESS PREFERRED: to PC (Windows/Mac/*x/..., desktop/laptop/...)
OPTIONAL: freestanding, with the sort of lousy membrane keyboard that most label makers have.

ALTERNATE: use controlling device (cell phone, tablet, or PC) to write the label, etc.
  • PREFERRED: cell phone and/or tablet
    • Form factor of labelmaker such that it can easily be attached to mobile device.  
      • E.g. clip over the edge of a cellphone, although that makes product specific to particular phones
      • Myself, I would probably velcro it or otherwise attach it to my cellphone. 
  • MUCH LESS PREFERRED: PC or laptop as controlling device for labelmaker
    • Kills the usage model of composing and printing labels at storage shelves
Frankly, being able to write the label on a phone/tablet/laptop/PC is NOT a big selling point for me.  (Unless there is no keyboard on the labelmaker.)

Much more important to me would be having the ability to upload the text labels written and printed while walking around to a database.

I.e. PC--->LabelMaker or phone--->LabelMaker not important

LabelMaker ---> phone/PC/... is more important

USAGE MODEL: putting stuff away in storage. Print and label storage box or file, upload text of label (along with date and location) to a database.   So that you almost automatically get a database telling you WHERE you have stored a physical box or file.

Bonus points for allowing a photograph of what is being put away to be taken and recorded to the database.

The need to have location (GPS/other) and photo motivates having a labelmaker that is controlled by a mobile phone via USB or similar.  Plus, it gives you a much better input device than the lousy membrane keyboard typical of labelmakers.  Cost reduction for the labelmaker.

PlusPlus, if you have a need to download long lists of labels to print, phone/PC--->LabelMaker gives you that ability.

Location: GPS or wifi or or other usual wireless a start.   But if you want to record which room of a house or which shelf in a storage closet of an apartment you have put the box or file in, GPS not fine grain enough.   This partly motivates photographs - e.g. photograph a shelf, possibly with an ID number.  But it might also motivate something more convenient for user, such as RFID on shelves. Slightly more advanced tech, but more convenient. If you have home automation, e.g. for light switches, those IDs may be sufficient.


Further: standalone portable LabelMaker with wifi or other wireless - to update database immediately.  (Of course, it would need the usual lousy labelmaker keyboard, if not attached to a mobile phone.)