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 6292
Mutability is an interesting area. I just added an unmutable bit in the
Prothon internal object which makes the read_lock call a no-op and causes a
write_lock call to throw an exception. This makes the object
write-protected and makes the lock code run much faster.
I did this for internal performance reasons, but after doing it I realize
that extending it to the Ruby freeze() level would be really good. Tying
the freezing in somehow to the bang! methods is also in interesting area of
research.
Mark Hahn (Prothon Author)
P.S. If this belongs in the Prothon list instead of Python, let us know.
"David MacQuigg" <dm*@gain.com > wrote in message
news:bi******** *************** *********@4ax.c om... On Sun, 28 Mar 2004 11:15:34 -0500, "John Roth" <ne********@jhr othjr.com> wrote:
"Paul Prescod" <pa**@prescod.n et> wrote in message news:ma******* *************** *************** @python.org... John Roth wrote:
> It's certainly true that in a prototype based language all objects > exist: there are no objects that the compiler deals with but does > not put into the resulting program. And it's quite true that it does > open up the floodgates for a lot of messiness.
Ummm. This is also true for Python. Python classes exist at runtime.
foo = 5
class foo: # oops. I've overwritten foo def bar(self): pass
print foo print dir(foo) print type(foo)
Paul Prescod
Sure. But misusing classes as instances is quite rare in practice, and plugging members into instances is also quite rare in practice. Python's highly dynamic nature opens it up to a lot of difficulty in principle, but most deveopers seem to be quite disciplined in their use of dynamism.
The difficulty here is simply that there is no way of isolating a base object that is supposed to be the platform for other objects from objects that are supposed to be updatable with new behavior.
The higher a tower you want to build, the firmer the foundation. Conventions help, but if the conventions are helped along by the language, that's even better.
In Ruby you can freeze() any object. But it seems like in this case, just giving your base object a distinct name, like PrototypePolygo n will remind you not to change its definition later as you create triangles, rectangles, etc.
I also would have no objection to some syntactic lock, like any object name ending in an underscore is an immutable object. We could also do this the other way around. Objects, by default are immutable. That would take care of most uses. If you want a mutable object, give it a name ending in ! (bang).
-- Dave
"Mark Hahn" <ma**@prothon.o rg> wrote in message
news:AHF9c.4904 8$cx5.33872@fed 1read04... I didn't know I was going the opposite direction from Python. I guess I'll have to change that.
I guess I didn't make it clear that no design decisions were frozen in the language.
Mark Hahn (Prothon Author)
Thank you. That wasn't the impression I had picked up from
the third party discussion of the issue earlier.
John Roth "John Roth" <ne********@jhr othjr.com> wrote in message news:10******** *****@news.supe rnews.com... "Mark Hahn" <ma**@prothon.o rg> wrote in message news:v0r9c.3898 8$cx5.22021@fed 1read04... > although for reasons I've mentioned elsewhere, I won't use Prothon.
Can you please point me to those reasons?
Since I got into a minor flame war over them, including a very snide and oh so superior response from one yahoo who almost hit my killfile over it, I'll just mention that there are ***very good***, that is ***extremely good*** reasons why the Python standard is to use spaces for indentation, and why the option of using tabs will be removed in 3.0.
There are enough interesting languages out there to investigate that I simply won't bother with candidates that don't play fair with ***all*** the tools I use, or that people I communicate with use.
John Roth
"Mark Hahn" <ma**@prothon.o rg> wrote in message
news:ZNF9c.4910 8$cx5.10276@fed 1read04... Mutability is an interesting area. I just added an unmutable bit in the Prothon internal object which makes the read_lock call a no-op and causes
a write_lock call to throw an exception. This makes the object write-protected and makes the lock code run much faster.
I did this for internal performance reasons, but after doing it I realize that extending it to the Ruby freeze() level would be really good. Tying the freezing in somehow to the bang! methods is also in interesting area
of research. Mark Hahn (Prothon Author)
I think that's a very rational way to go about it. I don't think that
lexical
labeling will work, though. It makes initialization too difficult.
John Roth
P.S. If this belongs in the Prothon list instead of Python, let us know.
"David MacQuigg" <dm*@gain.com > wrote in message news:bi******** *************** *********@4ax.c om... On Sun, 28 Mar 2004 11:15:34 -0500, "John Roth" <ne********@jhr othjr.com> wrote:
"Paul Prescod" <pa**@prescod.n et> wrote in message news:ma******* *************** *************** @python.org... > John Roth wrote: > > > It's certainly true that in a prototype based language all objects > > exist: there are no objects that the compiler deals with but does > > not put into the resulting program. And it's quite true that it
does> > open up the floodgates for a lot of messiness. > > Ummm. This is also true for Python. Python classes exist at runtime. > > foo = 5 > > class foo: # oops. I've overwritten foo > def bar(self): > pass > > print foo > print dir(foo) > print type(foo) > > Paul Prescod
Sure. But misusing classes as instances is quite rare in practice, and plugging members into instances is also quite rare in practice. Python's highly dynamic nature opens it up to a lot of difficulty in principle, but most deveopers seem to be quite disciplined in their use of dynamism.
The difficulty here is simply that there is no way of isolating a base object that is supposed to be the platform for other objects from objects that are supposed to be updatable with new behavior.
The higher a tower you want to build, the firmer the foundation. Conventions help, but if the conventions are helped along by the language, that's even better.
In Ruby you can freeze() any object. But it seems like in this case, just giving your base object a distinct name, like PrototypePolygo n will remind you not to change its definition later as you create triangles, rectangles, etc.
I also would have no objection to some syntactic lock, like any object name ending in an underscore is an immutable object. We could also do this the other way around. Objects, by default are immutable. That would take care of most uses. If you want a mutable object, give it a name ending in ! (bang).
-- Dave
I'm totally confused. There was a statement of fact about how compilers
work which I refuted. Now it's shifting to a question of programming style.
Let's recap:
John Roth wrote: "Paul Prescod" <pa**@prescod.n et> wrote in message news:ma******** *************** **************@ python.org...
John Roth wrote:
It's certainly true that in a prototype based language all objects exist: there are no objects that the compiler deals with but does not put into the resulting program. And it's quite true that it does open up the floodgates for a lot of messiness.
I responded:
Ummm. This is also true for Python. Python classes exist at runtime.
Given
class A:
pass
a = A()
Both "a" and "A" are put in the "resulting program" (bytecodes) just as
they would in a prototype-based language. A() is a completely
first-class object, just like a prototype in a prototype-based language.
Paul Prescod
Mark,
I see most discussion about Prothon is concerning prototypes.
Can you explain to me in easy words, why it is NOT possible to integrate
prototypes into Python to stand "side by side" with classes?
I never had a problem to "add an attribute" to an existing object; I really
can't see why it should be more than some small hacks to allow "adding a
function to an existing object".
Harald
They're planning to remove tab indention support in 3.0? I for one would
be pissed off at such a change. I don't mind people using spaces if they
like but I see no reason I shouldn't be able to use tabs if I like. I
can't see how it should make any difference to Python which you use so
why not allow for personal preference? I'll just mention that there are ***very good***, that is ***extremely good*** reasons why the Python standard is to use spaces for indentation, and why the option of using tabs will be removed in 3.0.
"Harald Massa" <cp*********@sp amgourmet.com> wrote in message
news:Xn******** *************** **********@62.1 53.159.134... Mark,
I see most discussion about Prothon is concerning prototypes.
Can you explain to me in easy words, why it is NOT possible to integrate prototypes into Python to stand "side by side" with classes?
I never had a problem to "add an attribute" to an existing object; I
really can't see why it should be more than some small hacks to allow "adding a function to an existing object".
As you note, you can do that with a simple assignment,
and it will work. The two problems are:
1. The clone operation
2. Syntax sugar to make it all nice and palatable.
I suspect that a usable clone() operation is less
than 10 lines. The syntax sugar, on the other hand,
will IMNSHO, take forever to get agreement.
John Roth
Harald
They're planning to remove tab indention support in 3.0? I for one would
be pissed off at such a change. I don't mind people using spaces if they
like but I see no reason I shouldn't be able to use tabs if I like. I
can't see how it should make any difference to Python which you use so
why not allow for personal preference? I'll just mention that there are ***very good***, that is ***extremely good*** reasons why the Python standard is to use spaces for indentation, and why the option of using tabs will be removed in 3.0.
Michael <mo*****@mlug.m issouri.edu> wrote: They're planning to remove tab indention support in 3.0? I for one would be pissed off at such a change. I don't mind people using spaces if they like but I see no reason I shouldn't be able to use tabs if I like. I can't see how it should make any difference to Python which you use so why not allow for personal preference?
I'll just mention that there are ***very good***, that is ***extremely good*** reasons why the Python standard is to use spaces for indentation, and why the option of using tabs will be removed in 3.0.
This space-vs-tab war is just insane. I wish Prothon/Python would use
block terminator, if only to kill this silly trollings.
--
William Park, Open Geometry Consulting, <op**********@y ahoo.ca>
Linux solution for data processing and document management.
William Park wrote: Michael <mo*****@mlug.m issouri.edu> wrote: They're planning to remove tab indention support in 3.0? I for one would be pissed off at such a change. I don't mind people using spaces if they like but I see no reason I shouldn't be able to use tabs if I like. I can't see how it should make any difference to Python which you use so why not allow for personal preference?
>I'll just mention that there are ***very good***, that is >***extremely good*** reasons why the Python standard is to use spaces >for indentation, and why the option of using tabs will be removed in >3.0.
This space-vs-tab war is just insane. I wish Prothon/Python would use block terminator, if only to kill this silly trollings.
Right. Then we can have "does the brace go on the same line or the
next line" wars.
--
CARL BANKS http://www.aerojockey.com/software
"If you believe in yourself, drink your school, stay on drugs, and
don't do milk, you can get work."
-- Parody of Mr. T from a Robert Smigel Cartoon This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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...
|
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...
|
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...
|
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
| |
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...
|
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,...
|
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...
|
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...
|
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,...
|
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...
| |
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();...
|
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...
|
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: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |