classes and functions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Silver Rock

    #1

    classes and functions

    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 misunderstandin gs of the language.

    Please give me a light.

    thanks guys,
    Claire
  • Bruno Desthuilliers

    #2
    Re: classes and functions

    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 misunderstandin gs 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...

    Comment

    • Thomas Dybdahl Ahle

      #3
      Re: classes and functions

      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 misunderstandin gs 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.

      Comment

      • James Stroud

        #4
        Re: classes and functions

        Silver Rock wrote:
        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 misunderstandin gs of the language.
        >
        Please give me a light.
        >
        thanks guys,
        Claire
        Attempt to code a gui.

        James

        Comment

        Working...