Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Python classes?

Name: Anonymous 2011-02-12 21:56

Let's say I have the following code in Python:


class dong():
   x = None
   def __init__(self):
      pass
   def dat_func(self):
      print x.upper()


We know that Python is dynamically typed. So I can change the type of the class member x at run-time when ever I want. That means that for every method in a python class where you have code that depends on the type of the class member x you have to check the integrity of x such that the type of x is what you want it to be.

This code demonstrates the problem.
[code]
x = dong()
x.x = 10
x.dat_func() #error, dat_func expects a str object.

For every fucking class member, any time you want to use it . . . You have to check the type to remind retarded developers that they're wrong.

Now if Python had private members it would be easier, but it fucking doesn't.

Prog 1, Python 0.

Name: Anonymous 2011-02-12 22:40

This is what Java programmers actually believe!
Not >>1, though, I don't hope. Though it was nice of you not to play the dynamic/weak typing confusion card.
I shall respond in turn: You should practically never be checking the type before you use something; duck typing and EAFP are tenets of Python programming. Your example is already going to fail, noisily and obviously. An type check isn't going to do shit for you or anyone else.
If you really needed the control, e.g. because an easy mistake to make could cause silent data corruption (you bad designer, you!), you should use a property and check the type at assignment.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List