recommends of redesign OO feature of python !!!

dieter dieter at handshake.de
Thu Oct 25 02:41:58 EDT 2018


iamybj--- via Python-list <python-list at python.org> writes:
> I am an engineer of java and c#, I want to some personal projects in free time, and I choose python.
>
> After try python, I hava some suggestion.
>
> The first thing is that python’s class is not well designed than other programming languages. 
> Using dictionary as data model is the 20th century style, but now is 21t century.We usually use strong typed class to express a data model.
> For example,  the code presentation of a person in Java/c++/c# may be:
> public class Person {
> 	public String name;
> 	public String email;
> 	public int age;
> }
> The corresponding Python code:
> class Person:
> 	def __init__(self):
> 		self.name = None
> 		self.email = None
> 		self.gage = None
> It is very strange to define instance members of a class in constructor.

Nothing prevents you from using

  class Person:
    name = None
    email = None
    gage = None


You can also have typed instance members (with help of some
other packages), e.g.:

  from zope.schema import String, Int
  from zope.schema.fieldproperty import FieldProperty

  class Person:
    name = FieldProperty(String(u'Name'))
    email = FieldProperty(String(u'Email'))
    gage = FieldProperty(Int(u'Gage'))

This gives you even more control than the simple types
you know from other languages. E.g. "gage" could be defined as

    gage = FieldProperty(Int(u'Gage', min=0))

To force "gage" to be an integer >= 0.

> ...
> Second, python is too complex. 
I have implemented large projects in assembler, Algol, C, C++, Java and Python.
I achieved the highest productivity as a developper with Python.

In addition, Python is far less complex than e.g. C++. The strong
typing of C++ forces it to define the incredible complex concept "template"
to build general purpose data structure libraries.
Due to its dynamic typing, this is trivial in Python.

My projects typically gain much from the use of multiple inheritance.
This allows to implement single features in so called mixin classes
which can easily be integrated via inheritance in any context
that needs the feature. Something, I dearly miss in Java.

> Python is an old programming language.At that time, enterprise programming style is very popular, witch like making simple things become complex, so force the costumer to pay more money.But now is WWW and Internet and Linux time, people like simple production and simple programming styles. Every new programming language wants to keep simple.

In fact, I am developing internet applications - and I much prefer
Python over Java in this domain.


> Third, python is too slow.

Python can be slow at runtime.
Mostly, it does not matter. If it does, you can implement
performance critical portions in C/C++. The Python C API is
far easier to use than Java's JNI for such tasks. In addition,
"cython" (a Python++ to C compiler) can avoid the direct use
of Python's C API, thus making optimizations even easier.

You could argue that Java's JIT compilers often do quite
a good job in optimizing performance critical code, thus often
avoiding the need to optimize manually. One point for Java.

> ...
> Totally speaking, simple and performance are mostly required by this times. I suggest the python team should stop any new work, and start to rebuild a new python with simple grammar and better performance.

Obviously, you do not like Python. Thus, stay with Java/C++/C#.

I, on the other side, do like Python (far better than C++ and Java)
and I hope your suggestion remains unheard.




More information about the Python-list mailing list