[Tutor] (Convergence && Divergence) || Nonsense
Alan Gauld
alan.gauld at yahoo.co.uk
Sat Aug 20 18:26:58 EDT 2022
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
More information about the Tutor
mailing list