ZEN


Why Python

Here are some comments from RISC OS folk when Python was mentioned at a recent Zoom meeting.

"Python is a rubbish language"

"We don't need two languages for beginners. We have BASIC and supporting Python is not the best use of scarce RISC OS developer resources."

"I am too old to learn another programming language."

Age does not come into it. Some people enjoy the experience of a new challenge, some don't.
As Mark Twain put it: "It is purely a matter of temperament. Beliefs are ACQUIREMENTS, temperaments are BORN; beliefs are subject to change, nothing whatever can change temperament."

Python is functionally a bit richer than BASIC. It has more data types and it implements encapsulation, abstraction, inheritance, and polymorphism of an object-oriented-programming language. On the other hand BASIC has the ability to run inline assembler. If you are coding just using the native language features there is not a lot of difference in practice. With enough time, determination and effort you can do pretty well anything in BASIC or in Python.

What makes Python worth considering is that it comes with easy access to a shedload of easily accessible and freely available external library resources for making applications.

For example there are Python libraries for:-

And there are lots of large scale "Real-world" Applications which are written in Python such as:

But for me the best argument for learning Python is that it has brought back the "Joy of Coding". The thrill of starting up a BBC model B and writing BASIC games programs or drill type to help my school age children learn spelling or arithmatic.

Python is fun to learn and use. It has an elegant syntax and has ocasional surprises. Monty Python fans will appreciate the in-jokes.

In the change from Python2 to Python3 the print command syntax was altered. Instead of >>>print "hello" you had to write ...print("hello"). This broke thousands of programs. In order to ease the transition some modules were added to the Standard Library of Python3.

from the Python prompt try this:
>>> from __future__ import braces
or this:
>>> import antigravity

 

The following two parts are taken verbatim from the official Python sources. They are somewhat whimsical, but they do give a feel for the language.

In my view, the Pythonic code example is problematic. It is elegant and so passes Zen test 1, but arguably fails at 2, 3, 6, 7, 9, 13,and 17; but this might just be an example of the Dutch sense of humour.

Pythonic

An idea or piece of code which closely follows the most common idioms of the Python language, rather than implementing code using concepts common to other languages. For example, a common idiom in Python is to loop over all elements of an iterable using a for statement. Many other languages do not have this type of construct, so people unfamiliar with Python sometimes use a numerical counter instead:

for i in range(len(food))
  print(food[i])

As opposed to the cleaner, Pythonic method:

for piece in food:
  print(piece)

The Zen of Python

  1. Beautiful is better than ugly.
  2. Explicit is better than implicit.
  3. Simple is better than complex.
  4. Complex is better than complicated.
  5. Flat is better than nested.
  6. Sparse is better than dense.
  7. Readability counts.
  8. Special cases aren't special enough to break the rules.
  9. Although practicality beats purity.
  10. Errors should never pass silently.
  11. Unless explicitly silenced.
  12. In the face of ambiguity, refuse the temptation to guess.
  13. There should be one-- preferably only one--obvious way to do it.
  14. Although that way may not be obvious at first unless you're Dutch.
  15. Now is better than never.
  16. Although never is often better than *right* now.
  17. If the implementation is hard to explain, it's a bad idea.
  18. If the implementation is easy to explain, it may be a good idea.
  19. Namespaces are one honking great idea -- let's do more of those
>>> import this

© 2021 JR