classes and functions

S

Silver Rock

Friends,

I don´t see why using classes.. functions does everything already. I
read the Rossum tutotial and two other already.

Maybe this is because I am only writing small scripts, or some more
serious misunderstandings of the language.

Please give me a light.

thanks guys,
Claire
 
B

Bruno Desthuilliers

Silver Rock a écrit :
Friends,

I don´t see why using classes.. functions does everything already. I
read the Rossum tutotial and two other already.

Maybe this is because I am only writing small scripts, or some more
serious misunderstandings of the language.

or both ?-)

If you only write small scripts, then you may not have a use for
classes. OTOH, everything in Python (including functions) is an object -
that is, an instance of a class. So as soon as you're coding in Python,
you are at least using classes one way or another. The nice thing is
that you can safely ignore this if doesn't make sens to you !-)

One of the benefit of classes is that they allow you to have many
instances of the same object, each with it's own values - while if you
only use functions + global variables (to share state between
functions), you only have one set of values (one 'instance') at a time.
This is probably no big deal in your case, but it becomes quite useful
as soon as your scripts start to turn into a full blown application.

My 2 cents...
 
T

Thomas Dybdahl Ahle

Den Fri, 02 Mar 2007 19:26:08 -0300 skrev Silver Rock:
Friends,

I don´t see why using classes.. functions does everything already. I
read the Rossum tutotial and two other already.

Maybe this is because I am only writing small scripts, or some more
serious misunderstandings of the language.

Please give me a light.

I guess you are fimiliar with the string methods. You can do stuff like
"hi hi".split(" ") or " hi".strip().
This is because a string is a class.
The same functionality could be done by functions:
split("hi hi", " ") and strip(" hi")
but it feals more inituitive to put the dot after the variable.
It also makes it easier to know where to look for functions related to
the object.

And yes, I'm sure you will see the light, when doing larger programs :)
Don't worry.
 
J

James Stroud

Silver said:
Friends,

I don´t see why using classes.. functions does everything already. I
read the Rossum tutotial and two other already.

Maybe this is because I am only writing small scripts, or some more
serious misunderstandings of the language.

Please give me a light.

thanks guys,
Claire

Attempt to code a gui.

James
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top