4 ms·
PHP will always have an edge. If you want to do something stupidly simple, no other language can match. <?php $hackernews=file_get_contents("http://new
by lukeschlather 14y ago
PHP will always have an edge. If you want to do something stupidly simple, no other language can match.
<?php
$hackernews=file_get_contents("http://news.ycombinator.com);
$hackernews =str_replace('Hacker','Interwebz',$hackernews);
echo $hackernews;
?>
Now that's horrible code, it has a dozen bugs aside from the security issues, but I would go so far as to say when I need to do something stupid like that quickly, nothing matches the simplicity of PHP. It's downright elegant.
Not to say you should write a webapp in it, but I think you're wrong; there's intrinsic overhead in using a Real Language. It has nothing to do with "knowing how to do it," doing things properly takes time, a half-assed but mostly functional solution can be whipped up in minutes.
- deleted 14y ago[deleted]
- bradleyland 14y ago> Now that's horrible code, it has a dozen bugs aside from the security issues, but I would go so far as to say when I need to do something stupid like that quickly, nothing matches the simplicity of PHP. It's downright elegant. So: * It's horrible code * It has bugs * It's not secure ... * It's downright elegant See the discord there? It's not elegant at all. It's easy, but easy != elegant. It's just easy.
- lukeschlather 14y agoIt depends on the problem domain. I've seen PHP pretty similar to what I just wrote that worked without complaint. In some circumstances, great, bug-free, secure code is over-engineered and inelegant.
- saraid216 14y agorequire 'net/http' puts Net::HTTP.get(URI.parse('http://news.ycombinator.com')).gsub('Hacker', 'Interwebz') I'm confused. Where's the edge? Or, even simpler, require 'open-uri' puts open('http://news.ycombinator.com').read.gsub('Hacker', 'Interwebz')
- lukeschlather 14y agoI knew I was going to get some code golf responses. Simple and short are two different things. I value PHP over Ruby here because it's much clearer to the layman what's going on. To explain the PHP, all I have to explain is functions, variables, and the echo statement. To explain the Ruby, I have to explain functions, variables, Objects (everything is an object), Libraries, I/O, and method invocations. Also, in classic code golf form, your code eliminates a couple things that will make it do exactly the same thing as the PHP - you're missing your #! line, and you're not actually writing a CGI script, which is a second library you need to include and explain to your hapless newbie. And honestly, it's not just a newbie thing. I've written Ruby similar to that (with good error handling, etc.) Ruby only makes sense if you're going to do the job properly and put in error handling, etc.
- gbhn 14y agoAnd to Jeff Atwood's original point, you cannot copy-paste the file onto basically any http webhost on earth and have it run out of the box. I don't think that's appreciated in the threads thus far, is that web hosting companies have really done a lot of work for you for PHP and Perl that you have to do yourself with other web programming platforms. They might be better, but they aren't as universally available and supported. (For some value of "supported" which is usually "enough")