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 8701607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:26:30+00:00 2026-06-13T02:26:30+00:00

One thing that I find most annoying about OOP is that whenever you need

  • 0

One thing that I find most annoying about OOP is that whenever you need a new variable in a member function, and you need that this variable “attaches” the object on which this function is called, you have basically no choice but creating a new private field. This is ugly in my opinion, because this mean that the variable is initialized at object instantiation (and you can possibly never make use of it if you don’t call the method that needs it), it’s not hidden from the other entities that can access the private members of the object, and on top of all this means can clutter your class definition (think about C++ classes, which most often come with an header with the entire definition of the fields in it).

Speaking in the C++ lingo, I want the behaviour of the static modifier on a variable in a global function, but in member functions, and the storage must be in the object.

I don’t know that many languages, but I have the feeling that in dynamic programming languages it’s easier to do it. I can think of Lua: I would just add a new index in the current table. This doesn’t hide the new “field” from the rest of the world, but unless you tamper the metatable, everything in Lua is public, so it is not really a problem in the Lua mindset. But the problem of initialization is addressed.

So, my question is: is there any static programming language (i.e., one in which the layout of an object is known at compile time) where this thing is possible?

And by the way, is there a neat workaround in C++ to get a similar result?

  • 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-13T02:26:31+00:00Added an answer on June 13, 2026 at 2:26 am

    As the general idea in object oriented programming is to encapsulate behaviour as a set of methods (functions) and the data as a set of instance variables, this behaviour is not present in any static programming language that I can think of.

    However, the idea to separate the concerns of a single class into multiple units (as to make it less monolithic) has been considered in a few languages. The idea is to separate the various concerns within the single class of object. Although the variable is not created at runtime (this would make the type non static), it can be declared in a unit separate from other units.

    This is actually sort of available in C#. Although the implementation is purely cosmetic, you can declare a single class as multiple partial classes. One of the benefits is to separate concerns to avoid a single big declaration of everything encapsulated by the class (another use is code generation scenarios).

    This lets you do the following:

    File1:

    partial class Foo {
       int X;
       void DoSomethingWithX() {
            X++;
       }
    }
    

    File 2:

    partial class Foo {
       int Y;
       void DoSomethingWithY() {
            Y++;
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using this css file but one thing that is annoying me is the
One thing that bothers me about nHibernate is that it is not 100% compile
One thing that really bothers me about Google Code is that fact that it
I am relatively new to Xcode and one thing that has bothered me is
I am new to using numpy and one thing that I really don't understand
Coming from a C++ background, one thing that confuses me about Objective C is
I'm currently evaluating CodeRush and one thing that I liked most when reading the
One thing that really interests me that I don’t see much written about or
I'm new to the android side of development, and one thing that I know
One thing that's bothered me with vi is that paste (p) inserts lines after

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.