News for hackers. Stuff that matters.
Re:OK, here's the thing: this is only the entrance of the ra... by Eliezer on Monday October 18, 2010 @09:28PM (#1805831)
Call me loony but I see nothing surprising here. It's just indirection... I guess I've probably got some Elder Thing blood in me.
Re:OK, here's the thing: this is only the entrance of the ra... by jbm on Monday October 18, 2010 @10:05PM (#1805899)
For what it's worth, I used variable variables when making a DB class for a project I was working on last year.

It isn't something you can easily debug and it is complicated. That said, it isn't the gates to hell that it is represented as. It's a tool, and it can make code cleaner if you want it to.

function __tostring(){ $items = ['title','header','comment'] foreach($items as $item){ echo $this->$item; } }

Make that list of class variables much longer and you start to see the benefits in certain cases.

There are times when I do miss variable variables.

Re:OK, here's the thing: this is only the entrance of the ra... by bad_user on Tuesday October 19, 2010 @05:07AM (#1806573)
Python has it in a more object-oriented way ...

    def print_string(self):
        items = ['title', 'header', 'comment']
        for item in items:
            print getattr(self, item)
Where "getattr" is just a pretty protocol for calling ...

    self.__dict__[item]
This extends to whatever you want, including members of namespaces (like declared classes, functions, other namespaces, etc...)
Re:OK, here's the thing: this is only the entrance of the ra... by hagy on Tuesday October 19, 2010 @06:10AM (#1806665)
There is actually a little more to getattr in that __dict__ just has attributes local to that instance where as getattr (also instance.attribute syntax) also accesses class attributes, non-bound methods, and properties. Additionally, these non-local attributes can also be inherited from parent classes.
Re:OK, here's the thing: this is only the entrance of the ra... by jfb on Tuesday October 19, 2010 @12:33AM (#1806229)
I laughed at TFA, largely because it's clever and lucidly written, and cringed at the thought of what sorts of horror an unskilled operator could inflict with this on the poor dumb bastards charged with maintenance; but I'd rather my language err on the side of lunacy.
Re:OK, here's the thing: this is only the entrance of the ra... by othermaciej on Tuesday October 19, 2010 @03:31AM (#1806462)
The loony thing is that the indirection is by name, not by reference, which allows the indirection to be a lot less predictable. Compared to pointers, it's like the data structure equivalent of using dynamic scope instead of lexical scope.
Re:OK, here's the thing: this is only the entrance of the ra... by robertk on Monday October 18, 2010 @10:34PM (#1805965)
Indeed, call me when you're using complicated string-returning lambda functions inside the brackets and maybe then I'll--well, probably just redirect you to an obfuscated PHP contest, but cheers.
Re:OK, here's the thing: this is only the entrance of the ra... by folz on Monday October 18, 2010 @09:40PM (#1805849)
It's not even really indirection. Variable variables using strings is a useful feature for quickly getting functionality up and running (although there are usually security trade-offs, especially if you accept user input as the string to be evaluated).

Edited for clarity