Tuesday, September 26, 2017

Five Dimensions of Python

Understand that I'm using the term "dimension" loosely, perhaps to structure a TED Talk, or TEDx or something similar.

The Roman orator, Cicero a role model, learned to break it down into chunks.  If the chunks were too fine:  a host of problems.  Too big:  problems there too.

The goal of the accomplished orator was to get the chunk size "just right" for the intended audience.

The first dimension is like your utility belt, so close to home base you consider its content basic, and full of "built-ins" as these tools are called.

Here is your basic vocabulary for bootstrapping all the rest.  Any classic Python shell provides them natively.

In __builtins__ you get your "import" (for expanding the vocabulary) and your "open" (for streaming), your several workhorse types: list and range (sequences), some number types (int, float, bool), the string type (str, another sequence), the dictionary (dict) and the set (the not-sequences or mappings).

Functions such as "iter" "next" and "divmod" grace the builtins, with "property" a built-in class (used as a decorator when the time comes).  The large number of built-in exceptions are not "junk DNA" but rather the signalling system used to recover gracefully from inevitable glitches.

Before dimension one though, is dimension zero: the keywords. Forgive me for going out of sequence.  The builtins are actually somewhat easier to grasp, as objects, than these more ephemeral tokens of the Python grammar.  Words like "if" "else" and "lambda".

In any case, I propose we should number our dimensions from zero like Python does.

Dimension Zero are the keywords and related punctuation, such as colon, square brackets, quote marks (single and double, then triple of either).  Dimension Zero provides the original syntax you'll need to structure your programs, to tell a story of what happens among its several players (the objects).

Only three of the keywords are uppercase: True, False and None.  About 35 in all, for looping, branching, making functions and classes (callables).  No keyword is a callable.  In prehistoric Python, before the great leap, "print" was a keyword, yet today is a built-in function.

By dimension two, we're looking at "special names" (or call them __ribs__), provided by the language, meaning new ones get added from version to version, but they're not for the Python coder to create.

Like the keywords and builtins, we accept them as given.  They have that funny look:  __getitem__, __getattr__, __setitem__, __setattr__ ... __add__, __mul__ and __call__.  With these "puppet strings" we're able to control the behavior of our objects down to the syntactical level.

What should be the effect of using square brackets right up against my objects?  What should it do when "called" with curved parentheses?  How should two objects of my own devising interpret the addition or multiplication operator?

I'm empowered to devise alternative languages, or to approximate existing ones more closely. M1 @ M2 might result in matrix multiplication, while (f * g)(x) might be massaged to mean the same as f(g(x)).

Such sinewy flexibility, built right in to the language, could easily become a justification for the snake motif.  A snake is a subtype of dragon.  Perhaps Python has the connotation of "dragon language" in a more Chinese take on computer science.

Dimension three: the Standard Library.  Here, with "batteries included" we reach a frontier.  Any Python distribution is likely to come with all of the above, after which we reach dimension four.

Dimension four includes anything from simple one-module libraries, to frameworks and distributions.  One might further differentiate between these levels, however keeping it all zero to four has its advantages.

When I teach Python to others, I'll be specific about these dimensions and then begin spiraling in all five over time.

In a given lesson, we'll add a couple more keywords here, a special name there, a built-in, and then a module.

By "add" I mean "add to the student's knowledge base" i.e. to the student's awareness of a complete ecosystem, still evolving. Python is a moving target, but it's never too late to catch up.

Even core Python is evolving, both as a language specification and in terms of its implementations.

Python has been implemented in C, C#, Java (Jython) and in a more simplified version of itself (PyPy).  Python has likely been implemented in languages I don't know about.

Then we have Cython, a superset of Python with more compile time goodness.

We should expect people not that conversant with this variegated geography (territory) to get somewhat lost in it sometimes.

Partly why I offer these simplifying schematics and "dimension talk" is to tame the wilderness or wildness (entropy) and bring some order out of chaos.

Monday, September 25, 2017

Curriculum Segments

Above:  Discussing issues of scope, comparing and contrasting the block-based MIT Scratch with Python in Codesters.

Below:  giving a sense of where it goes after Codesters.

Then I continue demonstrating what object oriented programming looks like, comparing the Spyder and Codester IDEs.

This sequence continues in Control Room.

Sunday, September 17, 2017

Business Meeting

I don't think P&SC has had enough time to address the Chelsea Manning affair at Harvard, in which somehow Morell got mixed up. We do have a minute asking Friends Everywhere to consider the newly minted UN treaty banning (criminalizing) nuke WMDs.  That'd be a step beyond banning bio and chemo, except for authorized doctor use in the war on cancer, other diseases.  Nuclear medicine is still OK.

I'm planning to bring Deviled Eggs to potluck, there being no prohibition against same, the name notwithstanding. We're considered Liberal Friends, meaning eggs "of the Devil" have not been banned, and indeed they usually go quickly, either alone or as an ingredient with potato salad, like Sonya does.

I once had a long conversation with Christine, not a big believer, thinking the kitchen conversation she'd recounted was with Sonya, not Sonja -- we have both.  Silly me for getting the whole scene wrong in my head.  We've all gotta watch that.  Constructing one's own reality (liberals believe in constructivism usually, per Piaget), is a weighty responsibility, as any weighty Friend worth her salt will attest.

I did my walking meditation up the mountain this morning, which sounds so dramatic. Mt. Tabor is the neighborhood hill, full of decorative lakes, a tribute to Portland's former glory when, like ancient Rome, it enjoyed an entirely gravity fed water system.  Engineers may be forgiven for not having the training and background to keep that up into the 21st century.  We switched over to pump-driven because that's what engineers today can understand.

The new sandals from Bi-Mart are on a maiden voyage this morning, as boats for my feet.  Time to visit Fred Meyer, a Kroger brand shopping center, for the requisite deli offering.

Carol is here with complete versions of the UN Nuke Weapons Ban Treaty, ready for distribution at Business Meeting after potluck.  Quakers know nation-states thrive in war mode, like a drug, and have no ability to go cold turkey where WMDs are concerned.  However, we've been able to orchestrate a gradually introduced safety and security program wherein we safeguard future generations from our radio-toxic stockpiles.

Containing fires in the heavy element sphere has not been our forte.  Chernobyl, Fukushima, Three Mile Island... how many others don't we know about?  The tick tick ticking of the time bomb nuclei, nano-hazards, have been released and the genii won't go back in the bottle.  Yes they occur naturally in some cases.  In other cases, you need a freak of nature, like hominid species of a self-destructive bent.  Then there's the depleted uranium issue.  Lots to study at OSU.

Multnomah Friends Meeting is based in Portland, Oregon.

Lastly, for today, a brought a free sample of C6XTY for the kid programs, letting them know there's more where that came from if there's interest.  I have exhibits I could bring in.  Friday was a gala event wherein we got the super bowl commercials in the can.  Just kidding.  This stuff is a tad esoteric for the NFL.  When it comes to soccer clubs on the other hand...

I'm literally in the meetinghouse on Stark Street as I write this.  This used to be Doug Strain's electronics factory (his company's) and Jantzen's before that (swimwear factory).

Wednesday, September 13, 2017

FrackNation (movie review)

This documentary is a direct response to the award winning Gasland by Josh Fox.

I recommend viewing it.

did a lot of homework, starting with Kickstarter.

The director engages in a point by point refutation of the Josh Fox documentary.

I notice there's a Gasland 2 out by now.  I haven't seen it yet.

I'm all for public debate about public policy.

The MSM comes in for some severe criticism in this film as well, especially the NYT.

Tuesday, September 05, 2017

Task Management

Conway's Law says organizations reflect outwardly how they communicate inwardly, and that gets me thinking about task management both individually and at more collective levels.

How we write computer programs may have an impact on how we conceptualize about multi-tasking more generally. That's something I sometimes talk about with Dr. David DiNucci. He was at Wanderers this evening, which adjourned early on account of unhealthy air quality.

In the Python asynchronous model, a Task is like an egg working towards hatching, with an event loop scheduler checking each egg, almost round robin, until any one of them cracks.

The syntax expresses putting a wind-up toy into the mix, but how fast it unwinds depends on many environmental factors, such as the slowness, or speed, of the network.

Tick tick tick go the eggs, somewhat like time bombs but we want and expect them to go off eventually, and each one is enveloped in a waiting handler, less a callback function than a surrounding context, the enveloping Task.

However, Python's means of maximizing or optimizing a single thread is only the beginning.  Spawning threads and processes is likewise possible, using tools from the same asyncio library or other places.

A procrastinator will often beat himself or herself up for delaying an important task just thought of, however queuing up stuff to do later is likewise a signature activity of the self-organized.  Putting things off is not a dodge, but intelligent scheduling.

Let tasks come to you and don't feel compelled to jump up and immediately attend to them in the order dreamed. Acting immediately is what we call "impulsive" and many seemingly important tasks will appear "half baked" looking back.

Doing jobs in the same order you think of them may be a higher risk lifestyle than you need indulge in, is the mantra here.

Go ahead and stay in the lotus position, even if your jobs queue grows in the meantime. You'll need downtime to optimize.  Seeing how to kill many virtual birds, with no real birds harmed in the process, with one stone, will be your saving grace in many cases.

Yes, sometimes we need fast reflexes to take over.  Things do happen too fast for a lot of, or any, conscious consideration sometimes.  However don't treat your whole life like a twitch game.  Practice the art of creative delay i.e. scheduling.  Computers do it.  Multitasking is a science and an art.  Learn to both divide, and undivide, your attention.