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

  • SEARCH
  • Home
  • 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 8612925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:44:49+00:00 2026-06-12T04:44:49+00:00

Say I got a simple class with one public and one private method. If

  • 0

Say I got a simple class with one public and one private method. If I call the private method in the public method – should it return a value, or should that value be set as a field in my object, for example,

class Test:
    def __init__(self, path):
        self.path = path
    def __getNoOfFiles(self):
       'count files in self.path'
       return no_of_files
    def readDir(self)
        ...
        no_of_files = __getNoOfFiles()

or

class Test:
    def __init__(self, path):
        self.path = path
        self.no_of_files = 0
    def __getNoOfFiles(self):
       self.no_of_files = 'count files in self.path'
    def readDir(self)
        __getNoOfFiles()
        no_of_files = self.no_of_files
  • 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-06-12T04:44:50+00:00Added an answer on June 12, 2026 at 4:44 am

    It makes little difference in most circumstances, but there are minor reasons for choosing one way or the other. If the value is likely to be used more than once and it costs something to compute, it may be helpful to cache it in the class instance. But classes often include methods that do nothing but return values from the instance, so the return-value option fits with that style.

    In general, whatever looks better to your eye.

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

Sidebar

Related Questions

Say we've got a class like public class Doer { public int Timeout {get;set;}
Say I've got an array of User : class User : IUserDowngraded { public
Say I've got a domain model created from C# classes like this: public class
Say you've got two simple table cells next to each other. One contains a
I have created a simple RAII class in one of my DLLs (let's call
Let's say we have very simple Java class MyClass . public class MyClass {
I've got a large collection of simple pair class: public class Pair { public
Say I've got a class where the sole data member is something like std::string
Using Delphi 2010, let's say I've got a class declared like this: TMyList =
Let's say I have a class Voucher: public class Voucher { public Guid Id

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.