[Tutor] global variables
Alan Gauld
alan.gauld at btinternet.com
Thu Aug 22 16:10:55 CEST 2013
On 22/08/13 14:43, Matthew Ngaha wrote:
> On Thu, Aug 22, 2013 at 1:40 PM, Chris Down <chris at chrisdown.name> wrote:
>> It sounds like you want to use a class.
>> Why would you not just use a class if you want to store state?
Local coding conventions or programmer skill levels may preclude it.
> I don't feel my program needs a class.
But in this case it sounds like a class is the best solution.
Why would you "feel" that you don't need a class when you have a
situation where several functions share common state? That's
almost the definition of a class.
> Also i have been told to stop using classes by some very
> experienced Python programmers on irc
Really? What reasons did they give.
Unless they are talking about very specific circumstances
that doesn't sound like good advice!
> It's confusing being told different things.
Software engineering, like any branch of engineering, is about learning
to use many different tools and selecting the best set for a problem.
There are cases where classes are not in the best set, there are cases
where many global variables are a good fit. But both of these are the
exceptions to the rule and the engineer's job is to identify when a
genuine exception exists and make the right choice. There is never a
single right answer. Sorry, but that's life.
HTH
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list