Questions tagged [this]

7 questions
14
votes
1 answer

Why was "self" chosen over "this" for the name of the first parameter of python methods?

What was the rationale for choosing the name self instead of this when defining class methods in Python? Yes, of course, you can name it whatever you want - but the widely agreed-upon name for the first parameter is very clearly self. I ask because…
4
votes
3 answers

Why is C++ "this" poorly designed?

For every a and b which are non-const pointers of the same type, you can do a = b;, right? Inside non-const member functions the this keyword exists, which is a non-const pointer. So logicaly if b is same type as this you can also do this = b;…
user3123061
  • 1,609
  • 1
  • 15
  • 17
2
votes
2 answers

Avoid This Pointer

PROBLEM: this points to different instances at different stages of execution (as it should). But it is not always obvious which instance is that. On the other hand we could minimize the use of this, fixing its state with meaningful-name…
Zon
  • 187
  • 6
1
vote
2 answers

C: "this" vs ""

I'm using C in a minimal, efficient OOP style to build a game engine. A problem I've begun to face as the engine code settles is my (erstwhile) choice to use this. For example, I have: void Engine_initialise(Engine * this); void…
Engineer
  • 767
  • 5
  • 16
0
votes
1 answer

Does passing this as argument potentially cause exposure of invalid object state?

This question is based on two premises: First: an object must always have valid state. It is discussed in various posts, too. https://stackoverflow.com/questions/22408804/should-a-c-object-always-be-in-a-valid-state Second: a class can exclusively…
user2180613
  • 1,752
  • 3
  • 14
  • 17
-3
votes
1 answer

Is it possible for $this to return a __construct?

I am currently working on my PHP skills and at the moment I'm working with classes. What I want to do is to create a class for which I can echo the object. I have the following example: class good_stuff { public function __construct() { …
Alex Luigi
  • 1
  • 1
  • 4
-11
votes
1 answer

Using delete this to free memory in class

Whenever we are writing destructors in C++ (though this concept could apply in other languages) could we just not write delete this; and it would delete whatever data is inside of the class? Is this a good or bad idea? If it is bad, would this not…
bkeys
  • 1
  • 1
  • 3