Ewww, You Use PHP?
blog.mailchimp.com
blog.mailchimp.com
I think good TDD/agile/architecture cultures are more prevalent in ruby/python but as those languages have become more mainstream the quality of the average dev in those environments has dropped quickly. A few years ago only really good devs ventured into ruby stuff. Now everyone is trying it as the tools have made the language much more accessible for the average developer. I am seeing more and more programming mistakes in the ruby code I dive into than I used to.
Language choice doesn't matter too much from a technical perspective. It matters from a practical perspective. Consider the jQuery/prototypejs war. Prototypejs was technically superior for a long time, yet due to jQuery's more accessible plugin culture and prettier web site they were over time able to build a more robust community and took the mindshare lead in the js space. I still think one of the core reasons ruby/rails and python/django got big is that for a long time there was only one major framework available for the language and this caused a better community than the php landscape, which pre-dated frameworks by a long time (this happened to perl as well). So there wasn't "one true way" in php to build apps quickly, and this hurt the php community when rails got big. I think as a community we lost a lot of talent to ruby/rails in the last few years.
Bottom line is that accessibility, pervasiveness and low-learning-curve are critical to the initial and continued success of any platform, whether it's a language (ruby > php > perl), OS (ios > android > rim), etc.
Language advances in PHP (circular gc, traits, closures, etc) have brought php's language capabilities forward enough that it's a respectable platform for sticking with. However, you can't fix the community really since it's so fragmented. Fortunately some frameworks are getting enough traction to have rich ecosystems, and that's definitely a great thing for the language and the community.
Can you expand on that at all? What made Protoype technically superior?
(this is all with the understanding that prototype adding methods to standard objects was dangerous...)
I was at php|works Atlanta, but I didn't present. I have presented it at ATLPHP before. I've presented on other topics as well though and usually at least mention that I created phocoa during my bio.
Our position isn't just PHP actually, but that is our primary back-end language. Probably makes the other commenters' posts about multi-language experience all the more relevant. We do a lot of front-end work in Javascript and we use ruby a decent amount as well (rake, chef, capistrano).
Can I ask you what your language of choice was before FB and would you have taken a php job somewhere that wasn't FB?
And, might I add, PHP is so easy to understand and read.. You don't even have to know PHP to read the majority of code written in it ;-) Compare that to, say, haskell or scheme, where it's a whole new paradigm.
This is a crucial blunder from all no-tech people I know who are trying to hire great programmers. Seek Great Programmers, not Great "insert a language" Programmer! A good programmer will be good in any languages; a bad one will be bad in all languages.
Alternately there are 5 comments showing boilerplate for the most common use case, and none of them are quite what I'm looking for.
Compare to Python, 9 times out of 10, the boilerplate 4-line example (in the primary documentation) is exactly what I'm looking for.
I think PHP might actually have a good language lurking inside of it, but someone would need to rewrite most of the standard functions and classes by going through the comments on their documentation and asking "Why doesn't this function solve the problem this bit of boilerplate solves?"
I am not a super-dev, but I can write code in an unfamiliar language in a day or two (non-idiomatic, of course). Better people than I can do better, I am sure.
I am sure you will be able to find great engineers if you open up your playing field.
Of course a quick glance at a program in an unfamiliar non-procedural language defeats me.
If somebody's got the attitude that 'Java sucks, I only want to code Ruby', that person's not a pro in my book.
Anecdotally, I took a job as Rails developer some years back. I had zero experience with it before starting (Having worked mainly with PHP before), but because the environments are so similar (http is the same, gnu/linux is the same, mysql is the same, architecture and oop is the same etc. etc.), I was creating value after about three weeks and I would say that I was fully up to speed after something like 3 months. Consider that it can easily take the same time to get the business, the problem domain and your new colleagues to know, I'd say that the cost for my employer was close to nothing.
Now, I'm not saying that anybody can do this - I consider myself a fairly good developer and beside PHP, I have tinkered with a broad spectrum of languages, which surely helped my transition. And the point isn't that Ruby is such an easy language that it can be learned in 3 weeks either (In fact, I think it is a rather complex language). What I take from my experience is that a good (and diverse) developer, with a motivation can jump from related technologies with relative ease.
I do agree with your sentiment that it might be easier to sell a jump from php than to, but that is a different problem. If your project is interesting in it self, I'm sure you can find good developers who don't fret too much over what particular language they write in.
I am amused by the perception that a pro software engineer is assumed to only be proficient in the programming language they used in their last job. If an engineer is applying for your job, talk to them and make sure they are a good personality fit for your team. They are probably going to take more time understanding your dev tools and procedures than boning up on PHP.
I guess seeing all the PHP-bashing that happens in the world (especially on HN) made me a little gunshy about approaching high-level devs to work on our project.
Fortunately thanks to some very well-made points and stories shared on this thread, I am now optimistic that I should be able to convince devs used to "better" languages that working on a PHP project could still be cool and a good learning experience.
This thread has been really great for me. Thanks, HN!
I believe I meet your criteria but can only work remotely. I am currently looking so if remote is an option please let me know and I can send you more details.
I'm talking about Wordpress and vBulletin.
While MVC isn't the only valid design pattern, some varient of it is rather nice when working with websites and these two seem to ignore it through and through. Testing? What's that?
I know that better can be written in PHP, but for apps that I've had to deal with, PHP normally looks like an overpowered scripting language that's just a mess. I'll stay with Rails and Sinatra when I can.
MediaWiki is all over the place and the themes included in the install are just horrifying. Whoever made the original (monobook) theme should get slapped in the face.
Why am I calling "validate_purchase" on the server?
Client Clicks Buy -> JSONP to Payment Gateway -> Gateway to Server (with all the info) -> Server to Client Confirming Transaction
All my server is doing is recording the transaction and forwarding the info to the client. The gateway is trusted, since they are processing payments.
I'm serious. This is where we're headed. Yes, you will have a hell of a lot of server-side code on the gateway, but that's a service, not the application.
So?
> You'll need some (server-side) validation logic if you don't want people buying new high-end smartphones for a penny.
That validation logic should be expressed in SQL. It's really really simple. If inventory id and price match in your inventory table, insert into your transaction table.
Again, see my original point. PHP is just the glue for the database.
- you're running a promotion
- the price changed in between the time the person added it to their shopping cart and checkout
- two people are processed for a payment on the last item in inventory at the same time
- there are different options on the item, e.g. color, that change the price
- other people bought the last item in inventory already, but there's an equivalent product at the same price
- the person bought the product using a combination of real money and gift card money, which the payment processor does not handle
- the person bought other things in the same transaction, e.g. a gift card, that do not have an inventory ID
Those are just a few cases off the top of my head, but the short end of it is that expressing all of this with a combination of SQL and client-side logic is just madness. If you're saying that we don't need to write business logic in PHP any more, I think you just don't work with the same constraints that most businesses do.
I think you are uncomfortable with SQL.
Ultimately it is the designer's choice where the business rules are handled...but to abstract those rules to levels above where the 'business' actually happens seems like a poor practice.
In fact, I would love to see you design a query that branches on the condition that the item is out of stock and automatically returns the top 3 equivalent parts for each brand using a junction table containing equivalencies, ordered by a column in the junction table containing the closeness of fit. Go ahead, humor me. Then try to pretend that that query will ever stand up under scale.
The main drawbacks I can see to that are:
1) Most developers couldn't write enough SQL to escape a paper bag. That's fine; usually, you don't need to escape a paper bag with SQL. The problem is that this only works for people who are very comfortable with SQL. I'm decent with it, and perhaps I'll lean a bit more that way for my next project, but I'm not seeing most people doing this.
It's also not quite as simple as you say, because multiple items are typically combined into one. This is many:many, so you'll need a table to cross-reference them.
So, you'll need to have a transaction table and a subtransaction table. The subtransaction table can match against inventory, and the transaction table can sum the subtransactions to make sure the total is correct. This gets a little hairy around foreign keys, but it's pretty easy to code around.
2) This example is fine, but for any transaction more complex than this, you risk tying yourself to a particular DB backend. That's probably OK, as the DB backend contains most of your app code: it's like tying yourself to Python on the backend. It's just something to be aware of.
3) This is likely to result in a large number of transaction rollbacks, due to price changes and whatnot. This might be OK, or it might trip anti-fraud features on your payment processor.
Agreed, but you can split your SQL queries into really simple ones and glue them with PHP. What I don't see anymore in my code is a hundred lines of unbroken PHP. Actually, I don't even see a dozen. A few lines, SQL, a few lines, SQL ... that sort of thing. That's what I'm talking about.
You don't need to be puritanical, although of course, you can. That's personal choice.
Matters for a single 15 years-old developer. Deployment is never easy when you get do anything non-trivial, and the cheap hosting... hosting for other languages start at $5 or $10... The only cheaper hostage PHP has is free.
> good documentation
That's highly debatable. I've also seen the PHP doc comments being pimped, I could never find anything worth more than a laugh in that cesspool.
Node.js wins for deployment if you ask me. Node.js + riak handily beats the pants off of the LAMP stack. It's so easy I'll tell you how to do it right now:
1. Install node, ./configure && make && make install
2. Install riak, make all rel && mv rel/riak /usr/local && export PATH="/usr/local/riak/bin:$PATH"
3. Install your app: scp -r remote:/my/app /web
4. Install dependencies: cd /web/app && npm install
5. Run your app: node /web/app/do/something/cool.js
Back to my coffee.(I'm being somewhat facetious and these instructions don't get you startup services and such, but I do believe that Node.js stacks are much simpler than traditional stacks and easier for devs that have to wear the sysadmin hat too)
Noobs can't do what you just outlined; they'll be puzzled the first time one of the commands fail (missing compiler, failed dependencies, whatever).
If they can install and configure Apache on a remote server, they can install and run node. I don't think it requires any more skill to copy and paste different commands into the console and you don't have to edit any configs or ask questions like "what distro? does your distro configure apache for vhosts out of the box? do you have an httpd.conf or vhost.enabled? run nano and hit ctrl-o to "write out" the file..."
Honestly though I don't think noobs do these things anyway. They will just ftp stuff into a directory on their host if they're using PHP. If they're using node I think the easiest deployment scenario is doing a git push. So practically speaking PHP is still the easiest for a clueless Windows noob to use.
It's just as easy to get mod_python working as it is mod_php.
mod_wsgi on the other hand... 4 lines in your apache config file. 6 if you're using a daemon process (which is better).
So I stand by my point!!
Compare that to getting CodeIgniter up and running: SFTP the files into the server, and you're up. No server configuration needed.
One could argue that this is not a feature of PHP itself, but that doesn't change the fact that "normal" PHP solutions are simply faster to get up and running.
In what circumstances does the fact that a Hello World can be setup in 5 mins versus 10 actually matter?
We spend thousands of hours developing software.
Five mins versus 10 is truly moot.
Besides, you're going to get into httpd.conf to configure a vhost before long -- mod_php or mod_wsgi -- so it's not as if it's a hands-off experience with PHP.
Can't speak for rails, but for Django we're talking 15 lines and a pair of commands for a clean setup:
* Create a virtualenv with all your dependencies and your django application checked out (0 lines)
* Extract static files to whatever directory you're serving static files from (1 command in 1.3)
* Create your wsgi handler script (4 lines, because you have to setup the DJANGO_SETTINGS_MODULE env)
* WSGIScriptAlias and the relevant directory allow (5 lines)
* WSGIDaemonProcess and WSGIProcessGroup configuration directives (2 lines)
done.
Sure, PHP comes pre-configured out of the box. But there are no real differences between `apt-get install python-django` (comes with a development web-server, runnable as ./manage.py runserver) and `apt-get install apache2 libapache2-php`.
Let's take your VPS example. Install nginx, gunicorn, and your database of choice. Set up gunicorn to serve your app, set up nginx to serve static and proxy to your gunicorn instance. Do any app-specific setup.
That doesn't take any longer than deploying a PHP app, at least not for me.
Well, you do need to install the AMP part. Since you're installing and configuring three components, why not install and configure different ones? It's not more or less work either way.
If you're talking about AMI/StackScript-style pre-built VPSes, there are plenty for various Ruby, Python, and Node stacks as well as PHP.
In my view the only problem with PHP array functions is the fact that the naming scheme is an absolute disaster (as it is all over PHP, for historical reasons).
For example, let's say you've got a string like 4|1|45|343|22. You want to return a string with the last three numbers, but seperated by a comma and a space.
In PHP:
$arr = explode('|',$str);
$last_three = array_slice($arr, -3);
return implode(", ",$last_three);
In Python: return ', '.join(str.split('|')[-3:])
Small conciseness improvements snowball as the codebase gets larger. In fact, being unable to chain functions in PHP is actually my biggest beef with the language. If you could do return implode(', ',array_slice(explode('|',$str),-3));
that'd be a lot less annoying. Still not as good as the python, but a lot closer.That's just a lie or at least a horrible misconception, depending on your intentions. Furthermore, the example line you used to illustrate this entirely made-up inability of PHP does in fact work. You can do
return implode(', ',array_slice(explode('|',$str),-3));
it's valid code and it works just as expected!I mean I'm with you on the fact that it would be nice to have this in PHP. I just don't get how you can argue this point to show that it's supposedly a bad language. The difference between
array_slice($array, -3)
and $array[-3:]
isn't that important to a lot of people. Interestingly, this criticism never comes up when, say, C# or Java are discussed. Only PHP is treated this way. As I said: sure it would be nice to have this feature, but I wouldn't imply that any language that doesn't have it is unusable. Ruby and Python are fortunate in this regard, but this feature alone wouldn't sway my choice either way. In the end, the number of array slicing operations per line of code isn't usually that big."Or that you prefer a syntactical shortcut and everyone who disagrees is an idiot?"
No, not everyone who disagrees with me is an idiot. Just those people who read the sentence "Rather, it matters to me." and somehow think I mean "everyone who disagrees is an idiot", apparently missing the EMPHASIS ON "ME".
(capped for your benefit.)
* Arrays are created with array() as opposed to a more modern [].
* Arrays are not objects, so you have a ton of functions in the global namespace starting with array -- array_join() as opposed to $array->join().
* The functions are not consistent. Half of them don't have "array_" as a prefix. The order of arguments isn't consistent with other parts of the standard library.
I'm really curious about why you consider this a strong point of PHP.
When people want to pick nits about this or significant whitespace it makes me think that there must very little variance between the languages if THIS is the issue that deserves scrutiny. Am I missing something about array() vs [] ?
if you really hate typing array(), http://codepad.org/ASREdjTK
When I work with an unfamiliar class in Ruby, or come back to something familiar (say, Array) after a long time away, I'll often not "know" the exact method signatures for what I want, but I'll just guess something reasonable based on my knowledge of the language and idioms. And, lo and behold, most often it works!
Having to "remember" (does this method use array_?) or "translate" is a mental tax; there's cycles wasted that could keep your mind in the business logic.
> When people want to pick nits about this or significant whitespace
> it makes me think that there must very little variance between
> the languages if THIS is the issue that deserves scrutiny.
For the record: this is not the issue that deserves scrutiny. The other issues are more significant.However this "short array syntax" is representative of PHP's sluggish internal development process. [] is very nearly the de-facto solution for creating arrays, and yet the PHP core devs have, for two years, rejected[1] patches that implement it on ridiculous grounds.
Finding the argument order for a method takes ~3-5 seconds. Its irrelevant. array() vs [] is actually a bigger deal as its indicative of php's verbose syntax. But its not a killer.
People like JS because it got the fundamentals right. The bad parts are just details. PHP is bad because it got the fundamentals wrong. But people still harp on the details.
But the "details" grate daily. Poor reflection, no FP? Fine, you craft solutions that don't require them. But having to look up order of arguments for standard library functions is a pain in the ass.
PHP 5.3, which certainly does provide that, is more than two years old. (And it also introduced late static binding and a few other tweaks and benefits to make its OOP significantly better.)
What? Why is [] better? Because it saves you typing 5 extra characters?
A lot of little details make a big difference.
foo = mydict[key] # Throws exception if key does not exist
foo = mydict.get(key) # Returns None if key does not exist
PHP foreach compared to Python foreach: # PHP
foreach ($arr as $value) {
echo "Value: $value<br />\n";
}
# Python
for value in arr:
print "Value: %s<br>" % value
# PHP
foreach ($arr as $key => $value) {
echo "Key: $key; Value: $value<br />\n";
}
# Python
for key, value in arr.items():
print "Key: %s Value: %s<br>" % (key, value)I think this is a bad feature and causes bugs. In Python there's a fail fast feature, where it'll throw an error if you go past the end of an array. It's places like this were bugs creep in. In python, you find out that there's a problem with this array, in PHP you have to hunt around and only later look at the array X lines above where the bug manifests.
they are all hashtables so you can use them as both arrays and lists
Python dicts (i.e. hashtables) are better than PHP arrays. PHP arrays only have number or string keys, so you can't use arrays as a key in a PHP array. You can in python.
This should help you.
Awesome PHP is awesome.
Downvote? Really? Pfft.
Now, it's certainly more normal-friendly than Symfony2 or the like by way of allowing non-developers to implement (a subset of) features, but I wouldn't call it programmer-friendly and I wouldn't use its internals as an example of good code.
I still recommend that people new to Kohana start with 2.x because a framework is worth a lot less without quality documentation, when you have to go read the code all the time. Not that you shouldn't do that eventually, there's a lot of good code in there to learn from!
Really, Kohana needs more documentation....
I would personally pick another language if I were doing something from scratch, but the benefit is that it is a language others are already familiar with and so adding a framework like Yii isn't too hard.
CFScript is JavaScript (ECMAScript)
No it isn't, by any stretch of definition or imagination.In fact, I think Ruby has more in common with ECMAScript than CFScript does.
That and utterly unreliable servers, to the point of having a process running under Windows to restart the server when it accumulated, say, 50 pending requests.
I'll never touch it again.
I guess, nobody ever accessed that.
Even JBoss has an open source CFML distribution, http://www.getrailo.org/ so the whole cost argument is mute.
I wouldn't ever expect to convince anyone who had ever worked on an old CF site to move back to CF ever again (believe me, I'm still scarred from it) but it's actually pretty good these days (Railo, that is).
My experience isn't limited either; Rails, Django, Flask, .Net (Umbraco), CodeIgniter, Drupal to name a few. They all have their warts. I hate to say it but in my experience Railo (CF) is way more performant than any of them.
The key here, as it states, is that they "built their own framework/libraries", which essentially means nothing to indie-devs and other small non-well-established companies who want to build something...
So the trend is simply this:
1) We use PHP because it's what we know, easy to get started with etc.
2) It gets us by while we build our business
3) Profit! Re-factor our codebase, in PHP!
Thus, the blog post should read: "Hey Mailchimp is doing awesomely, so we refactored our PHP codebase with our very own custom framework!"
It's not that PHP is all bad; it just lost the "framework wars" IMO, and I think when companies come out and state things like this, it kinda proves it...
I don't think everyone is doing that (building frameworks), or can, or even should when they're other possibilities outside of the PHP world...
I never really understood this argument. I mean, the overlap between Ruby and PHP are so great that they are virtually interchangeable.
(Hint: copying files to a server is not how real applications are deployed.)
At that point, it's equally easy to install a stack like haproxy + varnish + nginx + a bunch of CPAN modules as it is to rsync over a bunch of .php files, and therefore "it's easier to deploy" is meaningless. You click a button.
Not to pick on you specifically, but one argument that comes up quite frequently, especially in PHP vs. X discussions, is "I don't see how xxx feature of other language is beneficial." Well, the reason you "don't see" that is because you simply don't have enough experience yet. Deployment is the same way; a lot of people get by for years without ever "doing it right". But that doesn't mean the wrong way is right, it just means you haven't been required to get deployment right yet.
Ahem. I get what you are trying to say, but I think you're gonna have a hard time saying that Ruby is as easy to deploy "right" as PHP. Rsyncing a bunch of PHP files is a single shell command. Writing puppet or bcfg2 specs to deploy your six-tier web stack for your RoR app is a bit harder, it is most certainly not a button click out of the box, and neither process is necessarily more "right". It certainly helped the PHP ecosystem that deploying a LAMP stack is as easy as running three package installs and copying over some PHP files. The fact that a simple-to-understand, well-established process will scale you up to decent load before you need to get fancy will continue to make it an attractive platform.
The GP talked about "the given problem domains". One problem domain is simple, one-shot processing for plain old websites. Custom sign-up forms for stuff. Forms that email their data to some address. Homecooked personal-use search boxes that have "magic" functionality. All kinds of simple shit. These are deployed by FTP just fine.
Another problem domain is deploying something to virtually any cheap shared hosting provider. These very seldomly have e.g. ruby support. Sometimes, for all kinds of practical purposes, you don't get to choose.
But seriously, I find programming language fights to be mostly useless. Its like trying to argue English is more expressive than say French or German or whatever language. They all can convey human ideas, but each makes certain concepts a bit easier to express and others more difficult. In the end though, the thought or concept can be conveyed.
Personally I'd be very wary of Lithium as the code looks pretty slipshod internally from a brief scan into it, but Solar and FLOW3 are solid projects.
Didn't dwell too much into Lithium's code but saw they have some interesting ideas also based on 5.3 features, e.g. they use a sort of aspect-oriented programming based on closures and lambdas. Sounds cool, even if only for experimenting with different programming approaches.
It's actually pretty much in the same league as CakePHP: old and slow. Not much to recommend it right now. (Symfony2 actually can pull in Zend-based libraries on its own without a problem, which is why among the more sarcastic of us I've heard Symfony2 described as "Zend 2 but actually here".)
check benchmark: http://www.yiiframework.com/performance/
Symfony2, on the other hand, puts a fairly strong emphasis on security, is fully based around PHP 5.3 idioms, and is written with sparkling code.
[1] - http://dev.kohanaframework.org/issues/2766 comes immediately to mind; forget the resolution of the bug (such as it wasn't), the behavior of the developers is not good. I get the feeling from those who've used Kohana that this isn't a unique situation.
Probably better than finding a good dev in other languages for web development considering all the good PHP developers are still using PHP, and all the ones that couldn't cut it went on to learn the next LotM.
Honest answer: The same chance of hitting a good dev regardless of the language.
> But if you considering building anything today on PHP (when you have sooooooooo fucking many better platforms) you are incompetent and plain stupid, because it will be a big technical debpt for the whole project.
I think we have a bunch of stupids like facebook and mailchimp... Php or any other programming language is a tool, a proven one. So if you can do some amazing things go for it.
"You use X then you are an idiot. Y is for masters !" approach is childish and proves that you can only use Y technology.