473,778 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Prothon Prototypes vs Python Classes

Playing with Prothon today, I am fascinated by the idea of eliminating
classes in Python. I'm trying to figure out what fundamental benefit
there is to having classes. Is all this complexity unecessary?

Here is an example of a Python class with all three types of methods
(instance, static, and class methods).

# Example from Ch.23, p.381-2 of Learning Python, 2nd ed.

class Multi:
numInstances = 0
def __init__(self):
Multi.numInstan ces += 1
def printNumInstanc es():
print "Number of Instances:", Multi.numInstan ces
printNumInstanc es = staticmethod(pr intNumInstances )
def cmeth(cls, x):
print cls, x
cmeth = classmethod(cme th)

a = Multi(); b = Multi(); c = Multi()

Multi.printNumI nstances()
a.printNumInsta nces()

Multi.cmeth(5)
b.cmeth(6)
Here is the translation to Prothon.

Multi = Object()
with Multi:
.numInstances = 0
def .__init__(): # instance method
Multi.numInstan ces += 1
def .printNumInstan ces(): # static method
print "Number of Instances:", Multi.numInstan ces
def .cmeth(x): # class method
print Multi, x

a = Multi(); b = Multi(); c = Multi()

Multi.printNumI nstances()
a.printNumInsta nces()

Multi.cmeth(5)
b.cmeth(6)
Note the elimination of 'self' in these methods. This is not just a
syntactic shortcut (substiting '.' for 'self') By eliminating this
explicit passing of the self object, Prothon makes all method forms
the same and eliminates a lot of complexity. It's beginning to look
like the complexity of Python classes is unecessary.

My question for the Python experts is -- What user benefit are we
missing if we eliminate classes?

-- Dave

Jul 18 '05
145 6375
In article <8e************ **************@ posting.google. com>,
Hung Jung Lu <hu********@yah oo.com> wrote:

I often don't know how to take it when I see people talking about OOP
by using definitions like: polymorphism, data hiding, etc. As if these
definitions were something of utmost importance. To me, OOP is just a
tool for factorizing code, just like using for-loops and using
functions to factor out repetitive code. Polymorphism, data hiding,
etc. are all secondary features: code factorization is the heart and
soul of OOP. Class-based OOP is a way of factorizing. Prototype-based
is just another way of factorizing, which seems to be more elegant:
instead of two concepts (classes and instances), you unify them and
have only one concept (objects). Moreover, in a prototype-based
language like Io, even scopes and objects are unified.


Seems to me that Lisp is the counter-datapoint that disproves, not your
thesis at the theoretical level, but the ways in which your thesis gets
applied in practice. From my POV, Python demonstrates that syntax
counts and that using different syntactical forms for different kinds of
factorization makes people enormously productive.

So saying "just factorization" misses the point IMO. Factorization
needs to be elegantly defined and easy mechanisms for applying it
created. What you call the secondary features are the user interfaces
for factorization and they are a necessary component for the successful
use of factorization.
--
Aahz (aa**@pythoncra ft.com) <*> http://www.pythoncraft.com/

"usenet imitates usenet" --Darkhawk
Jul 18 '05 #121
Right. So if we'd all just settle on top-posting things wouldn't be so
bad after all. It's all you bottom-posters that are screwing things up
for the rest of us. ;o)

Markus.

Stephen Horne wrote:
This is actually better than top-posting. At least the reading
direction is _consistently_ upwards, rather than requiring people to
leap forwards and back through the post in a desperate attempt to find
the clues they need.
On Wed, 31 Mar 2004 02:31:08 -0800, Michael
<mo*****@mlug.m issouri.edu> wrote:

top.
to
bottom
read
to
learn
to
you
forcing
be
would
this
No,

Jul 18 '05 #122
Amen! Well said, Mr. Baumann.

R Baumann wrote:
I belong to several newsgroups, some prefer top-posting, and some prefer
bottom posting. A few posters will spend the time to intersperse their
replies. And a few will even split a post into additional posts to reply
specifically to each question or comment that was made in a previous
post(pretty anal). Personally, I don't care how you post, it doesn't
irritate me a bit whether the post is top or bottom, replies interspersed,
or broken into multiple posts. My only real irritation, is the people that
feel that they have to include all the prior postings in the thread in their
post. I know what the thread's about, and if I want to see the previous
posts, I know how to go back and look at them. I'm just interested in the
answer(s). Period.

My point being?...There' s no "correct" way to reply to a post. Out of
courtesy, one follows the "standard" of the newsgroup one is participating
in. Complaining whether one top posts or bottom posts is just a waste of
time, and you, me, we, all know it. We just don't have anything better to
do but bitch, right?

This particular silly argument always has the same effect; it gets us
off-topic from the original post, and for those of us trying to follow that
topic, this is more irritating than whether one is "posting in the approved
manner". This thread was renamed to a different subject, but that was a
half-dozen rants later in the thread than it needed to be.

Get my point? Naw, too much to expect. I've wasted both your time and my
time with my own rant against your rants. :-)
A lot of you guys seem far more interested in starting arguments and keeping
them running, than you are discussing the pros and cons of Python and
providing helpful answers. Rein in your egos, no one, and I include myself,
has anything helpful to contribute in this kind of "dust-up".

Jul 18 '05 #123
has
Joe Mason <jo*@notcharles .ca> wrote in message news:<sl******* *********@gate. notcharles.ca>. ..
In article <69************ **************@ posting.google. com>, has wrote:
# Library pseudocode

_fooRegistry = []

obj _Foo: # prototype object
# Foo's code goes here

def Foo(): # constructor function
newFoo = _Foo.copy()
_fooRegistry.ap pend(newFoo)
return newFoo
Dirt simple with not an ounce of class metaprogramming in sight.


Is Foo() the standard syntax for making a new _Foo object? If this is a
new wrapper you just created, then it's no different than adding a
register() method - the user has to know that something different is
being done.

If Foo() is the standard syntax, and you're just overriding the
implementation here, does that get inherited? If so, this missed the
condition that only some of the descendants should get added to the
registry. If not - well, inheriting the constructor seems like the more
useful behaviour in general, so why not?


Don't think you've quite got the point of prototype-based OO yet.
There's no real 'standard syntax' for making objects; nor is there any
inheritance, classes, metaclasses, or instances. To create a new
object from scratch, execute the code that defines it. Alternatively,
duplicate an existing object.

Think of prototype-based languages as taking the more traditional,
two-tier class-based OO system and lopping off the entire upper tier.
The result is a much simpler, more direct, less formal and more
flexible approach to OO programming. If you're used to class-based
programming you may find the lack of predefined rules and formal
convention and ceremony a bit offputting. I expect Java programmers
feel the same when they first encounter Python's type system. Devise
rules to suit yourself, abstract away as little or as much as you
like. Can be quite refreshing getting right down to basics like this,
even if it's a little scary at first. :)
Jul 18 '05 #124
This is actually better than top-posting. At least the reading
direction is _consistently_ upwards, rather than requiring people to
leap forwards and back through the post in a desperate attempt to find
the clues they need.

That'd get really interesting when posting code examples. Why on Earth
would you leap forwards and back through a top post to find anything?
You start reading at the top and read until you run into the quoted
text. You only read the quoted text if you're curious to see which
specific message this message was in reply to. Top-posting should
require you to scroll your screen less. I think if I started posting
bottom-top text as you say you like better than top-posting then I'd
rightly be killed by the list Gods.

Jul 18 '05 #125
I find it surprising to see programmers arguing for top-posting. They
are arguing that exchanging the single author's time and brain cycles
for the time and cycles of many readers is a good trade-off. Perhaps
they just feel their time is infinitely more valuable than anyone
else's. I'm sure every top-poster present can think of vendors who
work from the point of view that their time and effort is more
valuable than the user's. The result of this philosophy is alienating
to users of software AND articles.

I follow more than 300 mailing lists on a regular basis (I get around 3
gigs of mail a day just from these lists) and I much prefer people that
top-post. I can click through messages with interesting topics and skim
the relevant text without having to scroll anything down. So IMO it's
more about saving the readers effort than saving the poster effort.

Of course the only people I really hate are those that quote text
without quoting it.. so it's all on the same level and you can't tell
what they wrote from what others have written. THAT drives me nuts.

Jul 18 '05 #126
On Wed, 31 Mar 2004 15:08:38 -0800, Michael wrote:
Why on Earth would you leap forwards and back through a top post to
find anything?
Why on Earth would to include the quoted material if it's irrelevant to
your post?
You start reading at the top and read until you run into the quoted
text. You only read the quoted text if you're curious to see which
specific message this message was in reply to.
That information is already provided in the message headers
(specifically, the "References :" header on Usenet posts, the
"In-Reply-To:" header on emails).
Top-posting should require you to scroll your screen less. I think if
I started posting bottom-top text as you say you like better than
top-posting then I'd rightly be killed by the list Gods.


If you only include the stuff you actually want to be read, then your
post is able to be read once, in a single direction.

Quote only the part of the original message you are replying to.

Reply below each part you're responding to, in chronological order.

Anything else is confusing and irritating for anyone who has learned to
read any human writing system.

--
\ "It takes a big man to cry, but it takes a bigger man to laugh |
`\ at that man." -- Jack Handey |
_o__) |
Ben Finney <http://bignose.squidly .org/>
Jul 18 '05 #127
On Wed, 31 Mar 2004 15:08:38 -0800, Michael
<mo*****@mlug.m issouri.edu> wrote:
This is actually better than top-posting. At least the reading
direction is _consistently_ upwards, rather than requiring people to
leap forwards and back through the post in a desperate attempt to find
the clues they need.
That'd get really interesting when posting code examples. Why on Earth
would you leap forwards and back through a top post to find anything?
You start reading at the top and read until you run into the quoted
text.


Rubish. You read the top post until you don't know what it's talking
about, and then you have to read stuff in the quoted text to find the
context, then you return to the top until you hit the next problem,
and then you're back to the quoted text again and so on.

You only read the quoted text if you're curious to see which
specific message this message was in reply to.


My memory isn't that good that I can remember everything about some
post written days ago just from identifying which particular one it
was. Even if I did, I won't necessarily understand the logical
connections between parts of the reply and parts of the replied-to
message unless they are ordered such that each piece of the reply
follows a quote identifying the specific thing it is replying to.
--
Steve Horne

steve at ninereeds dot fsnet dot co dot uk
Jul 18 '05 #128
In article <69************ **************@ posting.google. com>, has wrote:
Joe Mason <jo*@notcharles .ca> wrote in message news:<sl******* *********@gate. notcharles.ca>. ..
In article <69************ **************@ posting.google. com>, has wrote:
> # Library pseudocode
>
> _fooRegistry = []
>
> obj _Foo: # prototype object
> # Foo's code goes here
>
> def Foo(): # constructor function
> newFoo = _Foo.copy()
> _fooRegistry.ap pend(newFoo)
> return newFoo
>
>
> Dirt simple with not an ounce of class metaprogramming in sight.


Is Foo() the standard syntax for making a new _Foo object? If this is a
new wrapper you just created, then it's no different than adding a
register() method - the user has to know that something different is
being done.

If Foo() is the standard syntax, and you're just overriding the
implementation here, does that get inherited? If so, this missed the
condition that only some of the descendants should get added to the
registry. If not - well, inheriting the constructor seems like the more
useful behaviour in general, so why not?


Don't think you've quite got the point of prototype-based OO yet.
There's no real 'standard syntax' for making objects; nor is there any
inheritance, classes, metaclasses, or instances. To create a new
object from scratch, execute the code that defines it. Alternatively,
duplicate an existing object.


There certainly is a standard syntax for making objects. I need to know
how to "duplicate an existing object". Is it "obj.dup()" ?
"obj.clone( )"? "duplicate obj"? Most probably, the language (or
standard library) defines one of these, and I expect most objects to be
duplicated in the same way.

If I want to duplicate an object and add it to a registry, I can
obviously say "obj2 = obj.dup(); registery.appen d(obj2)". But if I were
designing a library defining objects of this type which were *always*
intended to be added the registry, it would be preferable for the
standard "obj.dup()" syntax to do this automatically as well, so the
user doesn't need to know about the extra registry step.

Whether it's "the point" of prototype-based OO or not, such hiding of
complexity is a valuable thing for the language to do. If it turns out
that you just can't do this because it's not part of the philosophy,
then the philosophy is lacking. (Unless you can give me an equivalent
procedure which is covered by the philosophy, and demonstrate that it's
just as good.)
In the example you gave, the way to make this object was "Foo()".
Because we're talking about several different languages here, which have
syntax which are mild variations on each other, it can be confusing to
tell what exactly a bit of posted code is referring to. That's why I
asked (rhetorically) if "Foo()" was the standard way to create an
object. I assume you're talking about Prothon, in which it *is*. In
that case, my second question stands - how do you inherit the behaviour
of adding to the registry, without rewriting the "_fooRegistry.a ppend()"
line for each cloned object?

Joe
Jul 18 '05 #129
Markus Wankus <ma************ **************@ hotmail.com> writes:
Right. So if we'd all just settle on top-posting things wouldn't be
so bad after all. It's all you bottom-posters that are screwing
things up for the rest of us. ;o)


Did you actually _understand_ what he wrote? Yes, I did notice the
smiley, but I also noticed the apparent complete failure to get the
point. Complete failure to get the point, I find, is often strongly
correlated to top-posting.

Even if _everyone_ top-posts, then the reading direction is still
inconsisitent and requires the reader to jump back and-forth, to
understand what is going on.

Please _think_ about it. It really doesn't take very much thought to
understand that top-posting sucks, but it does require some. More than
top-posters seem to be able to muster, it seems.
Jul 18 '05 #130

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1400
by: Mark Hahn | last post by:
I would like to announce a new interpreted object-oriented language very closely based on Python, that is Prototype-based, like Self (http://research.sun.com/research/self/language.html) instead of class-based like Python. I have named the language Prothon, short for PROtotype pyTHON. You can check it out at http://prothon.org. The prototype scheme makes object oriented computing very simple and complicated things like meta-classes...
0
1314
by: Mark Hahn | last post by:
Ben Collins and I have developed a new interpreted object-oriented language very closely based on Python, that is Prototype-based, like Self (http://research.sun.com/research/self/language.html) instead of class-based like Python. I have named the language Prothon, short for PROtotype pyTHON. You can check it out at http://prothon.org. The prototype scheme makes object oriented computing very simple and complicated things like...
28
3306
by: David MacQuigg | last post by:
I'm concerned that with all the focus on obj$func binding, &closures, and other not-so-pretty details of Prothon, that we are missing what is really good - the simplification of classes. There are a number of aspects to this simplification, but for me the unification of methods and functions is the biggest benefit. All methods look like functions (which students already understand). Prototypes (classes) look like modules. This will...
7
3563
by: Michele Simionato | last post by:
So far, I have not installed Prothon, nor I have experience with Io, Self or other prototype-based languages. Still, from the discussion on the mailing list, I have got the strong impression that you do not actually need to fork Python in order to implement prototypes. It seems to me that Python metaclasses + descriptors are more than powerful enough to implementing prototypes in pure Python. I wrote a module that implements part of what...
49
2628
by: Mark Hahn | last post by:
As we are addressing the "warts" in Python to be fixed in Prothon, we have come upon the mutable default parameter problem. For those unfamiliar with the problem, it can be seen in this Prothon code sample where newbies expect the two function calls below to both print : def f( list= ): print list.append!(1) f() # prints
20
1814
by: Mark Hahn | last post by:
Prothon is pleased to announce another major release of the language, version 0.1.2, build 710 at http://prothon.org. This release adds many new features and demonstrates the level of maturity that Prothon has reached. The next release after this one in approximately a month will be the first release to incorporate the final set of frozen Prothon 1.0 language features and will be the Alpha release. You can see the set of features still...
0
9464
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10292
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10122
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8954
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7471
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6722
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5368
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4031
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.