5 ms·
"PHP is overly verbose and terribly inconsistent and lacks powerful methods of abstraction and proper closures and easy-to-use meta-programming goodness" Somet
by wvenable 16y ago
"PHP is overly verbose and terribly inconsistent and lacks powerful methods of abstraction and proper closures and easy-to-use meta-programming goodness"
Sometimes I wonder how much closures and meta-programming is just code for coding sake. I've seen lots of examples of 5 line LISP code that does something totally amazing but you don't really know what it means but it's so abstract. If you have a quick job to do, I don't see that it's a limitation in using a language that requires to build the most straight forward solution.
PHP is ugly, but for the most part it isn't horrible -- these days you can easily avoid some of the worst parts and concentrate on making code that would be very equivalent to the same code in, say, Java. PHP is very straight forward -- it means what it says.
"Your web framework in PHP probably isn't continuation-based, it probably doesn't compile your s-expression HTML tree into assembler code before rendering it."
This just sounds like over-engineering the problem.
- sedachv 16y ago"This just sounds like over-engineering the problem." Except the problem was never defined. Of the five commercial Lisp applications I've worked on, two are addressing domains (large-scale financial calculations, and a web platform/OS) where using PHP makes absolutely no sense, and the current one (ERP) where PHP was previously attempted and found not to make any sense. All three use basic techniques like closures, markup generation and metaprogramming, and one of them is continuation-based (which I think is a mistake, but opinions differ).
- eru 16y agoI find e.g. closures in Lisp overly verbose. The ML family of languages has a much lighter weight syntax for functions. This makes amazing stuff look less like code for code's sake. (Though I do admit that I immensely like Lisp's macros.) In e.g. Haskell abstractions are the straightforward way to solve a problem. Abstractions are cheap.
- Zak 16y agoClosures in most Lisps are a bit verbose, but it's easy to create an alternate syntax using a macro. Arc and Clojure provide built-in shorthand for function literals that makes them much more convenient to use.
- eru 16y agoIndeed. Though with variable arity (which can be a good thing!), currying will always be at least slightly more cumbersome than in languages with fixed arity of the ML type syntax for function application. Currying and combinators are my preferred ways of creating new functions. Having infix symbols can help a bit, but I don't see it as crucial. Incidentally I only really began to use reduce/fold in Clean and Haskell, though I had been exposed to the concept in Scheme before, and used it a few times. But perhaps that was just a learning effect of prolonged exposure and would have happened while staying with Scheme, too. I still like Scheme. Matthias Felleisen is doing great work using it for education.
- jockc 16y agoVerbose how?
- eru 16y agoPartial application is slightly harder to do in Lisp. Compare: (define (list-reverse l) (foldl cons '() l)) listReverse = foldl (flip (:)) [] I hope both versions are fairly idiomatic. Here are two combinators that I have actually used in my code (the first one is fairly common): dot :: (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c dot = ((.).(.)) swing :: (((a -> b) -> b) -> c -> d) -> c -> a -> d swing = flip . (. flip id) Imagine (or better: provide!) Scheme versions or their idiomatic equivalents. Of course the point-free definitions makes them a bit hard to understand, but I wanted to demonstrate terseness. `dot' also has a nice point-full definition: dot f g a b = f (g a b) The use case for `dot' should be obvious from the latter definition. I leave the point-full definition (and a use case) for `swing' as an exercise. Let me just note that Lisp would carry some more syntactic baggage for the definition and use of both of these combinators. However, you can't beat Lisp, when it comes to Quines: ((lambda (x) `(,x ',x)) '(lambda (x) `(,x ',x))) Haskell's facilities for talking about Haskell code are more verbose. P.S. for completeness sake, to make the exercise above easier without doing a search: id a = a flip f a b = f b a
- oconnore 16y agoThe problem is most people building meaningful programs are not people with "just a quick job to do". For those people, having abstractions available allows them to focus on the harder problems that actually matter, instead of constantly reinventing the wheel. The mental energy is probably not worth it if you are just building a blog for yourself, but in that case, the mental energy of learning PHP is not worth it either. If the job is really that quick, why are you using dynamically generated content in the first place? HTML one-off's are the most straight forward solution. On the other hand, if you want to build a bulletproof web application, you should probably use powerful tools, figure them out once, and then actually solve your problem.
- wvenable 16y ago> the mental energy of learning PHP is not worth it either You probably already know PHP. It's so much like many other languages and it doesn't require much knowledge to get started. Many of the "gotchas" about PHP are more academic than practical and if you are ignorant about these things then you are more likely to do it right. Some of the horrible stuff, like huge body of non-namespaced functions, is pretty easy to search though and then use without a lot of knowledge overhead. I actually write very large business web applications in PHP. Crazy? Maybe. There is a bit of a sunk cost here, when the app was started most other solutions were pretty immature. However even with potentially "better" options now, PHP isn't going to burn down the house.
- swannodette 16y agoSometimes I wonder how much closures and meta-programming is just code for coding sake. I've seen lots of examples of 5 line LISP code that does something totally amazing but you don't really know what it means but it's so abstract You could the same for so many PHP frameworks. Why are there so many classes? Why do I have to inherit from a class I don't understand? Why am I forced to define classes at all? Why are my custom classes 50% getters/setters? Why are my objects mutable? etc. etc. etc. (map :last-name people) The point is if the language provides the proper level of abstraction, you end writing less of your own hand rolled abstractions. Again the only thing I'm hearing here is arguments from people who are too lazy to actually see how things are done from a functional perspective. Get off your ass and find out. Then tell me you have a problem with it.
- wvenable 16y ago> You could the same for so many PHP frameworks. You don't even have to include the word "PHP" in there. A lot of frameworks include a massive amount of functionality that you're almost never going to use. And for the few times you might need to use it, it'll probably take less and less learning and less dependency on code you don't control just to code up something by hand. But my complaint isn't about frameworks or their relative complexity. It's about how most people touting some of these solutions pride themselves on how terse the end result is. This goes well beyond DRY. A good abstraction is great for providing a clean view of the logic, but some abstractions and meta-programming take it so far that now the logic is no longer obvious. > Again the only thing I'm hearing here is arguments from people who are too lazy to actually see how things are done from a functional perspective. I've done functional programming work in the past (ML) but the fact is, it's just much harder to just get things done in functional languages. When you find the perfect domain mapping for functional work, it's great, but most of the time you don't have that. It's like arguing the Esperanto is a nicer and cleaner language than English -- that's probably true -- but if you want to get work done you use English.
- swannodette 16y ago> I've done functional programming work in the past (ML) but the fact is, it's just much harder to just get things done in functional languages. This is 2010, we're not living in a FP vs. OO world anymore. Clojure (and I've heard Scala) preserves the greats parts about OO programming. I'm sure this is the just the beginning.
- brlewis 16y agoSay you want to connect to a database, fetch some data, and present it using HTML. Here's how it can be done using a DSL based on Scheme macros: http://brl.codesimply.net/brl_4.html#SEC31 http://brl.codesimply.net/brl_4.html#SEC31 I can't forget to fetch the next row from the database. I can't forget to check that I'm at the end of the result set. Grouping the results is easy and straightforward. The statement and connection objects are automatically closed when the request is done. Compare that to PHP. I'm getting better, but even today I feel a little irritated when someone says PHP was designed for simple web/database apps. I know what a language designed for simple web/db apps looks like, and PHP is not it.
- jacquesm 16y agosql_apply("select id,somefield from sometable","applicator_function"); PHP is a programming language, it was not designed for 'simple web/database apps' any more than any other language, you can use the building blocks provided to create access at the level you require. But you can customize it so that it does become usable for 'simple web/database apps'. The above is a short sample of how I'd do the thing you describe and I don't have to remember to fetch the next row from the table and I don't have to check that I'm at the end of the result set, grouping is as easy as SQL will make it and all cleanup is automatic.
- brlewis 16y agoI want to abstract away the ways my app is like every other web app. I don't want to abstract away what's unique about it. If you abstract away everything, all languages are the same.
- btilly 16y agoPHP is a programming language, it was not designed for 'simple web/database apps' any more than any other language... Um, yes it was. See http://en.wikipedia.org/wiki/PHP#History http://en.wikipedia.org/wiki/PHP#History to verify that PHP started as a bunch of CGI binaries to serve some simple dynamic web pages. The database bit came later, but at the start it was explicitly designed for quick and dirty web pages.