11 ms·
Rasmus generally promotes abstention from using frameworks, and the use of PHP as more of a templating language. from watching a recent talk (http://ontwik.co
by there 16y ago
Rasmus generally promotes abstention from using frameworks, and the use of PHP as more of a templating language.
from watching a recent talk (http://ontwik.com/php/php-performance-by-rasmus-lerdorf/ http://ontwik.com/php/php-performance-by-rasmus-lerdorf/) he gave, i didn't get the impression that he hated frameworks, but more that he hated most php frameworks because they were slow.
in the video he says a big problem with current frameworks is that they deploy to production the same code used in development, which still includes all of the knobs and extra includes that have to be pulled in on every request to support things that aren't used. he would rather see frameworks turn code into a streamlined bundle of code that gets pushed to production.
- bkudria 16y agoThat's be much easier if there were some decent reflection and metaprogramming support in the language.
- nuclear_eclipse 16y agoPHP has had reflection support for years: http://php.net/manual/en/book.reflection.php http://php.net/manual/en/book.reflection.php And define metaprogramming; PHP has supported all of what I would consider metaprogramming as part of their core API since PHP 4. It may not be as pretty as what you can do in Ruby or Python, but you can do it just the same.
- andrewvc 16y agoUmm, did you read what you linked to? PHP reflection is a verbose, ugly mess. Example PHP vs. Ruby PHP: $a = new A(); $reflector = new ReflectionClass('A'); $properties = $reflector->getMethods(); Ruby: a = A.new a.methods
- nuclear_eclipse 16y agoI never said it was pretty, in fact I said quite explicitly that it wasn't as pretty as Ruby or Python, but it doesn't take good looks to work well. Java and C# are even more verbose than PHP but they can also do reflection just as well as Ruby and PHP can.
- bad_user 16y agoJava and C# are even more verbose than PHP but they can also do reflection just as well as Ruby and PHP can. Err, no, they cannot -- in Java/C# you cannot create or redefine functions / methods / entire classes at runtime. To do that, you need to get into bytecode generation, and that's not a feature of the language anymore; not to mention problems with the fact that their respective VMs weren't designed to allow the regeneration of methods/classes at runtime, so you run into problems like the permanent-generation in the GC (i.e. classes aren't garbage collected, so if not careful you may end up with a huge memory leak). "more verbose" doesn't really describe the shit you must do to make available the same tricks you can pull in Python/Ruby. Comparing this to C + assembly generated at runtime would be stretching it, but just a little -- having the ability to generate assembly doesn't mean that C has meta-programming facilities ;)
- damncabbage 16y agoIn all fairness, you're restricted as to how much you can do that PHP as well: The best you can do is modify the class definition in the code itself, and declare a __call() or __get()/__set() functions that park themselves in front of method calls and variable accesses. You can't go re-opening classes or directly adding methods or variables. (To make matters worse, __call() and friends are also more than a little slow as well.)
- nuclear_eclipse 16y agoRedefining or extending methods or classes at runtime isn't reflection; that's monkeypatching and/or rebinding new definitions to existing names. I would agree that Java, C#, and PHP lack the ability to do this without a lot of overcomplications, but at the same time, I've never really found myself in a situation where rebinding or extending classes at runtime was really the best solution. I would actually be quite interested in seeing a usage of that sort of magic that actually makes the solution easier and simpler than other options.
- troels 16y agoIt's verbose, but it's not a mess. It's quite coherent actually. For smaller encounters, there are a number of procedural reflection functions available. For this case, you could do: get_class_methods('A');
- andrewvc 16y agoverbosity creates messes.
- eru 16y agoPerhaps. Though it would certainly be nicer, if A was a first-class citizen in PHP, and you would not have to pass its name around as a string.
- roel_v 16y agoWhat if the name of A is only known at runtime? Referencing function and class names and if need be, also variable names, as string is very transparent to me. It also maps nicely to how it's implemented underneath - everything is stored and accessed in hashes.
- eru 16y agoThe name of A doesn't matter. Look at how e.g. Python solves this: class A: pass class B: pass a = A() b = B() # only known at run-time: c = random.choice([a,b]) print c.__class__ No mucking around with names needed. The same applies to functions---like PHP's array_map function which takes the name of the callback as an argument, instead of the function itself. I also don't understand why PHP's syntax treats variables whose type is a function different than variables which have a more mundane type. I.e. nearly all variables need prefixing with a $, but variables which hold a function need no such thing. And you can not assign to those function-variables.
- roel_v 16y agoSo now you want to instantiate a variable of type "A", where "A" is a string that you read in from a configuration file. How do you do it in Python? (I guess it's possible somehow, I'm just wondering what the syntactic advantages are). Your second sentence I don't understand - what do you mean 'variables whose type is a function'? The equivalent of a function pointer? For variable functions, you take a regular variable (i.e., with a $) and assign it the name of the function you want to call: function call_me($arg) {} $func = 'call_me'; $func(1);
- bkudria 16y agoThat's be much easier if there were some decent reflection and metaprogramming support in the language.