Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 386943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:37:31+00:00 2026-05-12T15:37:31+00:00

I try to avoid global statements in python and Do you use the "global"

  • 0

I try to avoid “global” statements in python and Do you use the "global" statement in Python? suggests this is a common view. Values go into a function through its arguments and come out through its return statement (or reading/writing files or exceptions or probably something else I’m forgetting).

Within a class, self.variable statements are in effect global to each instance of the class. You can access the variable in any method in the class.

Do the same reasons we should avoid globals apply within classes, so that we should only use values in methods that come in through its arguments? I’m especially thinking about long classes that can be just about an entire program. Does the encapsulation inherent in a class eliminate the concern? In any case, we should make inputs, outputs and side effects clear in comments?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T15:37:32+00:00Added an answer on May 12, 2026 at 3:37 pm

    Do the same reasons we should avoid
    globals apply within classes, so that
    we should only use values in methods
    that come in through its arguments?
    I’m especially thinking about long
    classes that can be just about an
    entire program.

    Classes exist to couple behaviour with state. If you take away the state part (which is what you’re suggesting) then you have no need for classes. Nothing wrong with that, of course – much good software has been written without object-orientation.

    Generally, if you’re following the Single Responsibility Principle when making your classes, then these variables will be typically used together by a class that needs access to most or all of them in each method. You don’t pass them in explicitly because the class exclusively works with behaviour that could reasonably access the entire state.

    To put it another way, if you find yourself with a class that doesn’t use half of its variables in a lot of its methods, that’s probably a sign that you should split it into two classes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 188k
  • Answers 188k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I don't think this can be done. When a DirectX… May 12, 2026 at 5:39 pm
  • Editorial Team
    Editorial Team added an answer You didn't provide any information about the wxWidgets version or… May 12, 2026 at 5:39 pm
  • Editorial Team
    Editorial Team added an answer Actually I've encountered this problem before and I believe the… May 12, 2026 at 5:39 pm

Related Questions

I have a C# database layer that with static read method that is called
The idea is to create a class that exposes a context but handles the
I have a JavaScript widget (a piece of embedded JS and HTML code) that's
I'm writing a global error handling module for one of my applications. One of
In my ASP.NET application using InProc sessions, Session_End calls a static method in another

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.