4 ms·
"variable = getattr(my_types_module, string_from_file) (arguments)" Right, and how is that more readable or more clear than the PHP equivalent? $myclass = new
by roel_v 16y ago
"variable = getattr(my_types_module, string_from_file) (arguments)"
Right, and how is that more readable or more clear than the PHP equivalent?
$myclass = new $classname; vs variable = getattr(my_types_module, string_from_file) (arguments) and you claim the second is cleaner?
Furthermore you are making several normative claims like 'Right Thing' but don't offer anything to back that opinion up. Function pointers are strongly typed too, does that make them superior? No just different, and I think the PHP way fits perfectly well with a consistent theme: you can substitute any name that you'd hard-code with a variable and it will work.
$var = 'test';
// Call function called 'test' with argument value of 'test';
$var($var);
// Set variable called '$test' to a new instance of class 'test'.
$$var = new $var;
// Call method 'test' on variable '$test' with argument 'test'.
$test->{$test}($var);
Straightforward and no need for strange 'getattr' indirection functions (see how I turned an in itself neutral design decision into a normative statement there?)
- eru 16y agoOh, I don't like getattr myself. If you want, we can continue the discussion via email---it's getting a bit unwieldy for the comments here. My email is in my profile. Thanks.