[Tutor] (Convergence && Divergence) || Nonsense

avi.e.gross at gmail.com avi.e.gross at gmail.com
Mon Aug 29 21:03:47 EDT 2022


Alan,

I waited till I read more of the book and I want to amend what I said.

The topic, loosely, was about the meaning of object oriented as implemented
partially in various languages.

In python, I encountered a rather late stage of various things that LOOSELY
I associated with O-O after having been exposed to versions in languages
like C++ and Java and some very different ideas in languages like R.

JavaScript so far is throwing me for a loop. In a very real sense, it has
had some odd concepts that at first looked more like a struct to me as most
things are a bit like an object minus the ways I am used to. I mean it is a
bot like a Python object in that any arbitrary variable can have associated
parts added and removed as sort of attributes. JavaScript in earlier
versions took that quite far. In a sense, functions can be made parts of
objects as a sort of attribute but can also be integrated so they have an
extra argument point at the object as a "this" but functions can also point
elsewhere as in the main environment. Then again, functions not only already
are such objects that can have attributes added, but must have some
attributes if they are to be a constructor for objects. 

Arrays, unlike in many languages, are also just the same objects with a few
twists. When doing some things with them, other non-numeric attributes are
ignored other than ones that look like integers but are converted to string
like "123" which are used to look up values using that key much like a
python dictionary. Some changes make the darn thing RENUMBER them, sheesh!

What got me is you can do all kinds of O-O things in a sort of primitive way
and those generally still work. But over the years ADDITIONAL ways have been
added with many simply being syntactic sugar such as a way to declare one
using the "class" keyword that simply re-does it the old way. Some new ideas
are mentioned in the book as on the way in a new release to extend the
abilities of what can be done such as making things static or whatever.

So, yes, it allows all kinds of O-O including perhaps more that can be done
than in Python and things that can be done dangerously or in weird ways like
allowing private variables by making them look like an illegal name of
"#something" which can only be reference by functions/methods defined within
the new class statement and not visible/usable anywhere else, or using
closures to hide a variable which otherwise a programmer could make changes
to.

It adds up to a very powerful design using some interesting paradigms but
one that had some painful aspects and keeps being "improved" as languages
co-evolve.

The book suggests inheritance, which they sort of implement in a different
way, should not be used too much and currently does not support anything
like multiple inheritance. They suggest embedding other objects within your
object as a way to supply some functionality. But if they keep trying to
improve, multiple inheritance may well be in the offing in some
idiosyncratic way!

People keep finding ways to try different variations. I am studying Ratchett
now which seems to be made by people who like LISP but conceded to make the
darn deeply nested parentheses more livable and readable by allowing three
kinds of paired parentheses so you can write something like:

(+ [- 1 {* 2 3} ] 4)

I seem able to wrap my head around many programming paradigms but admit some
appeal to me more than others. 

-----Original Message-----
From: Tutor <tutor-bounces+avi.e.gross=gmail.com at python.org> On Behalf Of
Alan Gauld via Tutor
Sent: Saturday, August 20, 2022 6:27 PM
To: tutor at python.org
Subject: Re: [Tutor] (Convergence && Divergence) || Nonsense

On 20/08/2022 19:31, avi.e.gross at gmail.com wrote:

> My reading so far indicates that if Dave were to read the same book 
> (or do his own study) he might be interested. I see many added or 
> changed features that indicate emulation and borrowing between 
> languages and places where some very loose features that may be easy 
> to use but lead to all kind of (sometimes subtle) errors are in some ways
reined in.

Javascript has many interesting features (and some horrid ones too) and that
is why I chose it as one of the 3 that I use in my tutorial.

> others. A very loose and almost non-existent object-oriented set of 
> abilities

Au contraire Javascript implements a powerful set of OOP capabilities.
They are just not based on classes but protypes. but that was not unique in
the OOP language of the late 80s and early 90s. (When Javascript first saw
light of day.) But Javascript supportas all the main OOP characteristics -
encapsulation, polymorphism and message passing. It even supports
inheritance although that is not an essential OOP feature.

> functions which I associated with python but also various asynchronous 
> methods and functions some of which may be done differently in python 
> now but for all I know may at some point be adopted.

Javascripts async capabilities are argiuably superior to Python, especially
when considering server-side Javascript. And there are at least 2 frameworks
that enhance that capability even further.
Good enough for EBay to run their site almost entirely on Javascript.

> Is Python likely to move into some areas like web browsers where 
> JavaScript is a major built-in with JAVA (completely unrelated) also 
> has some ability to be integrated? I heard somewhere they once tried 
> to include some of python in Mosaic but JavaScript sort of won that
battle.

Deveral languages, including Python, have gone down that route but
Javascript is now almost alone in that area. The most succesful attempt to
put Python inside a browser was, rather ironically, from Microsoft with
their Windows Script Host engine which supported JScript and VBScript and
Python within Internet Explorer. But with the death of WSH so died Python's
life in a browser. (The all-Python Grail browser hardly counts.)

> So, aside from issues like getting everyone to change, is there 
> anything about Python that would be incompatible from being used in 
> browsers either instead of or alongside JavaScript and be able to 
> access and manipulate the DOM and other allowed services?

No, but why would you want to? Javascript is filling that space and the
number of sites using it is vast (even my own humble web-page which is
almost entirely static HTML uses a few script snippets). Any browser
therefor must support Javacript, anything else is just added bloat with no
established code base and no guarantee of one forming!

The closeest thing is coffee-script which looks somewhat like Python and get
translated at the server into Javascript when sending the page to the
browser. If you must write Python client-side code Coffee-script is probably
your best bet today. (Although personally I'd rather ust use Javascript,
it's really not that bad if you stick to "the good bits(*)"
and program functionally)


(*)Ref: Javascript, The good bits" by Cockford, O'Reilly press.

> that JavaScript, even changed, has huge deficiencies,

True but the JS community has learned how to avoid the worst aspects and
leverage the best features - especially its support for functional
programming, which far exceeds Python's lacklustre nod in that direction.

> get more bloated browsers where multiple scripting languages can be 
> embedded.

MS tried with WSH by embedding a single language host that could dynamically
load whichever interpreter was needed.
But even they couldn't make it fly due to the need for web pages to work on
ALL browsers and OS and device types etc. To do that requires a relatively
simple lowest common denominator and, like it or loath it, Javascript has
picked up that role.

It's a bit like trying to replace C in the low-level OS and device-driver
realm. Rust is having a go at that but its a huge struggle. Rust is clearly
a "better language"
for modern computing but the legacy factor is a huge hurdle.


> used alongside each other or even intertwined. I think> at this point 
> you can embed JavaScript in HTML and a Java applet in <APPLET>

That's pretty much it. Although HTML5 is acquiring some dynamic coding
capabilities of its own. but even HTML5 is not a full blown scripting
language yet.


> ...or PHP using <?Php . ?> or something like that. 

But that only acts at the server. PHP is a webv server scripting language
like Microsofts ASP or Java's JSP and most of the Pyhon (and other) web
frameworks. And let us not forget that Javascript too has server side
implementations and these often work in tandem with browser side code.

In fact, many modern web apps have almost no traditional HTML.
Instead they simply load up a Javascript script which directly populates the
DOM within the browser using database calls back to the server. This is
faster than loading HTML which then has to be interpreted and converted to a
DOM model which then gets queried by a script and modified from a database.
It also has the advantage(?) of being almost impossible to screen-scrape and
is much more secure.
It's also mind-bendingly difficult for programmers other than the original
coders (with access to a documented DOM structure) to penetrate.

> But do note a detail. JavaScript has no IO built-in at least in some
sense.
> In browsers you can only write to a console with console.log() or 
> perhaps pop up an alert. You are not allowed to read or write files 
> any time you feel like it on the users computer, except through 
> controlled interface for storing local data in restricted ways. If you 
> use Javascript on a server, as in Node, you get other forms of I/O
attached that let you do what is needed.

Javascript is not expected to need I/O, it was created to read and write to
the DOM. The browser displays the DOM.
It is equivalent to working in a GUI. There you update widgets and the GUI
displays the widgets when next it draws the screen. You have to adjust your
mental programming model in Javascript to view the world as a DOM. It is
when programmers  try to use Javascript outside the DOM that the nasties
start to appear!

Javascript on the server is a whole different beast and with vastly
different capabilities. Large and sophisticated applications have been
written entirely in server-side Javascript (as in millions of lines of
code!).

> Just to make sure of my main point, languages started off often by 
> diverging but as they converge, often some of their differences become 
> less and easy to get around. It may become very hard to explain why 
> you insist on a specific language when all the others also have grown up.

So true. All successful language evolve and pick up features from others.
Even Python has acquired things like list comprehensions from Haskell and
some of its async capabilities from Javascript. Likewise Java and C++ have
picked up Python-like features. More modern languages like swift have
started out blatantly borrowing the best of C++, Objective C, Python, Java,
Lisp, Haskell and others.
And for this we should rejoice!


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




_______________________________________________
Tutor maillist  -  Tutor at python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list