[Tutor] (Convergence && Divergence) || Nonsense
Alan Gauld
alan.gauld at yahoo.co.uk
Tue Aug 30 07:11:43 EDT 2022
On 30/08/2022 02:03, avi.e.gross at gmail.com wrote:
> 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. ..., 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"
Functions in Javascript are first class objects and the core element of
the language. Objects in Javascript are just a type of function.
I like the description by Crockford:
" Javascript...is Lisp in C's clothing"
Javascript looks like it should be part of the C/C++/Java family of
languages but in fact is much closer to Lisp/Logo/Clojure and Haskell
> Arrays, unlike in many languages, are also just the same objects with a few
> twists.
JS arrays are like a combination of Python classes, lists and
dictionaries. Very powerful but apparently simple.
> What got me is you can do all kinds of O-O things in a sort of primitive way
> and those generally still work.
Yes, but the prinitive way is usually not the "correct"
way in the JS world. The JS designers made it easy for people from the
C++/Java world to come to JS and build objects like they used to. But
the best way to do it in JS is to use the native approach of protyping.
That is somewhat like using the metaclass features of Python to create
objects. But JS exposes the prototyping mechanism much more explicitly
than Python does its meta programming features.
You might find my description of "OOP in JS" interesting. It's found
at the end of the OOP topic in my tutorial(see .sig) It demonstates
both the JS classic mechanism for creating "classes" via prototypes
as well as a more traditional "simplified" version.
> 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.
I don't follow current JS developments so I have no idea what
those might be.
> 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
That's the problem. There is a very solid subset of JS that can be
used with discipline to build large reliable systems. But there
is a huge bag of bits hanging off the side that can bite you if
used carelessly.
> 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.
That's true of most "interesting" languages. Even Fortran and Cobol
are still getting new features added. And C++ has changed beyond all
recognition over the last 40 years. To the point that nearly
everything I was taught to do in C++ is now considered bad practice!
And Python too of course. Comparing modern python best practice with
version 1.3 say!
> 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.
That's a common limitation, mainly as a response to OOP neophytes using
inheritance as a code reuse tool rather than as a genuine "type
specialisation" mechanism. Even Bjane Stroustrup at one point said
he wished he had not added multiple inheritance to C++ but focused
on templates instead. (He thought templates - aka generics - would
be too dificult to implement so did MI instead. Then, when he later
added templates, discovered they were much easier to do than expected)
> improve, multiple inheritance may well be in the offing in some
> idiosyncratic way!
Smalltalk, the purest OOP language around, has had at least 2
attempts to add MI but neither stuck. It remains a single
inheritance language to this day.
> 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
I played with Ratchett a while back. kind of fun but lacking
the infrastructure to do much more than teaching tasks.
--
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