Live data from Hacker News

I Like PHP

beust.com

81–90 of 269 posts

Re: I Like PHP

#81
post #23

"I don’t even bother writing tests for most of the PHP I write (obviously, I would be a bit more thorough if this code were destined to be used in a more mission critical web site). Not writing tests is not the only software taboo that I break when I write PHP: I happily mix up presentation and logic all the time. That’s just how PHP is supposed to work" And this is why everybody else hates PHP. It tempts you to writ…

Can you please provide me a resource to learn how to fully separate the code from the markup? I learned web development on ColdFusion then switched to PHP. I certainly understand separation of content from design (HTML to CSS) but I honestly have no idea how to do web development without mixing markup (HTML) with the actual programming. I've done a little C and Java web stuff where my code printed HTML output - ugly.…

Or another idea that doesn't require frameworks:

http://toys.lerdorf.com/archives/38-The-no-framework-PHP-MVC...

Re: I Like PHP

#82
post #78

Earlier quoted context omitted.

> Did you ever read Python's documentation? Yes. it's rather fucking good. > Show me one popular web programming language which has a full page, up to date, with examples and user comments and version incompatibility info, per function. Have you ever read Python's documentation? In the last ten years? Python's docs have a complete and readable description of the language[0] including its data model and the various co…

Don't forget being able to do this from within the interpreter: >>> print abs.__doc__ abs(number) -> number Return the absolute value of the argument. >>> print xrange.__doc__ xrange([start,] stop[, step]) -> xrange object Like range(), but instead of returning a list, returns an object that generates the numbers in the range on demand. For looping, this is slightly faster than range() and more memory efficient.

True, or from your OS's shell:

    > pydoc unittest
    Help on module unittest:

    NAME
        unittest

    FILE
        /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/unittest.py

    MODULE DOCS
        http://docs.python.org/library/unittest

    DESCRIPTION
        Python unit testing framework, based on Erich Gamma's JUnit and Kent Beck's
        Smalltalk testing framework.
    
        This module contains the core framework classes that form the basis of
        specific test cases and suites (TestCase, TestSuite etc.), and also a
        text-based utility class for running the tests and reporting the results
         (TextTestRunner).
 
    [snip]

Re: I Like PHP

#83
post #65

Earlier quoted context omitted.

The comparison between PHP and frameworks isn't valid. Writing PHP on a framework probably abstracts away SQL too, just like writing CGI in Python gives you lower-level control.

When frameworks are the popular alternative to PHP (RoR,Django,etc), it is valid. Are we also not allowed to talk about RoR when it comes to a discussion about PHP alternatives?

That is like saying Cocoa is a popular alternative to C++, but you prefer C++ because it allows you to write your own UI event loop.

I guess it is true if you really stretch your imagination, but does it mean anything?

Re: I Like PHP

#84
post #46

From TFA: > * I have yet to see this kind of universal support for any other language than PHP. Not even Ruby on Rails, let alone Java, is available on mainstream providers, thereby validating the claim I made five years ago that Ruby on Rails won’t become mainstream (I regularly receive emails about this article asking me this question, and I keep responding “Nope, still not mainstream”).* If your provider doesn't s…

Also, Dreamhost's $8.95 a month shared hosting supports Ruby (via passenger).

Re: I Like PHP

#85
My observations for the popularity of PHP are this:

1) It's old. You're alternatives to PHP 12 years ago are all bad. The most popular alternative was perl CGI scripts.

2) Since it's templated, it feels more like markup . Someone with absolutely no programming background can go: HTML -> HTML with a javascript "onclick" handler pasted from the web -> HTML with a bit of PHP pasted from the web -> writing my first original PHP code

Re: I Like PHP

#86
post #71

Earlier quoted context omitted.

Can you please provide me a resource to learn how to fully separate the code from the markup? I learned web development on ColdFusion then switched to PHP. I certainly understand separation of content from design (HTML to CSS) but I honestly have no idea how to do web development without mixing markup (HTML) with the actual programming. I've done a little C and Java web stuff where my code printed HTML output - ugly.…

Have a play around with a framework such as Symfony [1]. That's the most natural way of learning a better style of PHP web development. [1] http://www.symfony-project.org/

Any particular reason you're linking to Symfony instead of Symfony2? I find the latter so much easier to read and work with it's not even funny.

Re: I Like PHP

#87
post #39

Is PHP that much worse where it's worth it to jump onto the ruby ship? I'm just starting to code one of my current projects, but in PHP. Should I consider ruby instead?

Here is some PHP code: $x = "0"; if(!$x){ echo "0 is false"; } If you understand why it's crazy that PHP prints "0 is false" when you execute that, you're probably better off jumping ship now. If you don't, you'll probably appreciate the low barrier to entry for PHP more than any benefit you'd gain.

I understand why it prints zero is false, and personally I feel that it makes perfect sense. Indeed I approve of it. The fact that strings can be evaluated as numbers is great for accepting input from GET or POST because it means that there is no need to worry about explicitly casting strings to numbers.

Of course, input type validation is still important, and if a variable input by the user is supposed to be numeric, that is why there is the is_numeric() function to validate the type of a variable.

But once I've used is_numeric() and know that the string is numeric why should I bother with an explicit strtoint call? I feel that this feature of PHP if used correctly takes away complexity and repetition related to converting strings to integers.

In a realistic project the framework for your app should have a layer between user input and your code anyway. At this layer it will be validating that input from the user is of the correct type anyway, and once that variable passes the is_numeric() test the layer can easily cast that input string to an int so that it is the right type for JSON encoded objects or any other output from PHP for other languages that needs to have specific types.

Once again, if PHP is used properly, with a decent code architecture this feature of PHP is not a problem.

Re: I Like PHP

#88
post #65

Earlier quoted context omitted.

The comparison between PHP and frameworks isn't valid. Writing PHP on a framework probably abstracts away SQL too, just like writing CGI in Python gives you lower-level control.

When frameworks are the popular alternative to PHP (RoR,Django,etc), it is valid. Are we also not allowed to talk about RoR when it comes to a discussion about PHP alternatives?

It's a bit comparing apples to oranges. If you were comparing say Cake or Zend to RoR and Django then it would be a reasonable comparison.

Re: I Like PHP

#89
post #23

"I don’t even bother writing tests for most of the PHP I write (obviously, I would be a bit more thorough if this code were destined to be used in a more mission critical web site). Not writing tests is not the only software taboo that I break when I write PHP: I happily mix up presentation and logic all the time. That’s just how PHP is supposed to work" And this is why everybody else hates PHP. It tempts you to writ…

This is unfortunately true. I'm a PHP programmer (currently writing a book, A Highly Negative Book About PHP, that I've been billing as "like Essential Java but tells you what not to do") and, I like to think, a fairly good one; reading this article made me cringe because this guy is emblematic of most of the problems in the PHP community. He:

-accepts uncritically gobs of code dredged up via Google

-considers something "robust" if it doesn't break old code, when the rest of us hate it because we have to live with register_globals and other horrors

-considers "universal support" of craptastic versions of mod_php to be a good thing (some, but not all, major shared hosting messes use FastCGI)

-modifies files in production and thinks that's okay

It makes those of us who do know what we're doing and focus on disciplined code look bad, because the article author is what most people think of when talking about "PHP programmers".

Re: I Like PHP

#90
post #60
post #53

Earlier quoted context omitted.

You can do cheaper than that - WebFaction will give you an $8 a month shared hosting account and you can run anything you want! They have a really cool automated setup system for more involved projects like Django/Pyramid/Sinatra/Rails and lots of others.

...which leads me to think that the poster is confusing "mainstream" with "GoDaddy".

I'm not.

I'm using a fairly "non-noob" ISP (ssh access, crontab, etc...) and they still don't give me access to much more than PHP. I can install Java but I can't even run it as a CGI because of the HTTP request memory constraints they impose. This is pretty standard, I don't blame them for doing this, and I would go with a VPS if actually needed all this.

Same for Ruby on Rails, obviously.

Post reply on HN