Live data from Hacker News

I Like PHP

beust.com

241–250 of 269 posts

Re: I Like PHP

#241
"there is no claim you can make about PHP that can’t be made about C as well, and vice versa."

What about hundreds or thousands of inconsistently named built-in functions?

C doesn't really have built-in functions, just a standard library that you don't have to load if you don't like it.

Re: I Like PHP

#242
post #97

Earlier quoted context omitted.

It's an XSS-prone templating language, as the default correct syntax for outputting variables is: which is far from encouraging safe best practices. PHP namespaces aren't any better: http://pornel.net/phpns

Actually, you should also always indicate the character encoding, for reasons I explain here: http://shiflett.org/blog/2005/dec/google-xss-example

Yes, declaration is necessary, but not in the htmlspecialchars() call if you're using ASCII-superset encoding (and you really should declare UTF-8, never UTF-7).

Re: I Like PHP

#243

Earlier quoted context omitted.

Python's got excellent documentation, both official and third party.

Python itself does, but the third party modules (which do most of the heavy lifting) generally don't. See: Twisted.

There's high variation in quality amongst third-party modules, but the "modern" python community takes documentation quite seriously, there's even a complete site dedicated to nothing but hosting compiled documentation[0]. Projects like Django, Flask, SQLAlchemy or Flask have rather good documentation sets.

[0] http://rtfd.org

Re: I Like PHP

#244
post #237
post #182

Earlier quoted context omitted.

Almost impossible? Pop quiz: The case-insensitive version of "strpos" is "stripos", what is the case-insensitive version of "strcmp"?

I'm guessing it's stricmp... However off the top of my head I have absolutely no idea what the argument order and return values for any of those four functions will be without looking them up.

buzzer sound I'm sorry, the answer we were looking for was "strcasecmp"

(Sorry if the level of levity is considered inappropriate, but humour is a level 4 defence mechanism and the only way I can remain sane in the face of such things)

Re: I Like PHP

#245
My first web language was PHP, I started working with it 12 years ago. Back then you didn't have Rails, Django, ORM, unit testing (in web dev that is), and javascript was looked as a language to just show popups and have confirm()'s before submitting forms.

If you wanted to connect to a MySQL, you have to do it all by yourself, you need to create a database, tables, PKs, connect to database, execute RAW mysql queries, and so on. Form validation ? Yeah right. Back then the include_once() or require() were amazing for separating code. But all in all that mades us learn how things work internally, how HTTP requests work, how SQL works, even why CSRF or XSS and SQL injections are executed.

Yes, the code was shitty, it was all over the place, but we learned how a web app works internally.

And yet, most developers I know who coded PHP back then are amazing developers today in any web language or framework. Why ?

Because most of them learned doing things the hard way. We had to understand how HTTP requests works, how SQL works, etc..etc.. because we didn't have the magic of rails, or any helper for any framework.

In these 12 years, web development as grown, a lot, and for the better, I'm currently learning Rails, and I've already done a project with Django and Node.JS . I liked them a lot and they are amazingly well done, I just wished PHP was more OO like ruby or python.

However, I laugh at these new Rail/Django developers that joke about PHP code. Most of them start coding jumping immediately into a framework. I bet that most of then couldn't create a simple MVC framework, ORM from scratch, hell, even a simple security CSRF would be a pain without "gem install ".

You see kids, PHP was like our first GF or our first car, where we tried stuff, made us cry (in a sense), and helped us grow and mature as developers, for those who wanted to grow that is. Now you have lots of languages for web dev, but back then PHP was the thing.

I still believe that PHP is a very cool language if done correctly, I wished tho, that it should be rewritten to be more OO.

But if one thing I learned from all of these years is that, it's the developer who makes quality code, not the language. Unless that is, you are using a framework who basically demands you to do things the way it wants, and puts a lot for magic so you don't bother with "boring" stuff. But in the end of the day it's not your code, it's theirs.

So my advice for new dev is, forget frameworks, and learn the hardcore way, then pickup a framework you love and go with it, either PHP, Ruby, Python or whatever.

Re: I Like PHP

#246
post #176

Earlier quoted context omitted.

Frameworks have been suggested, and are a good option. A good understanding of MVC will carry you through though, and if you are only building small things then an ad-hoc MVC set up will probably get you most of the way to readable, flexible, maintainable code. One good tool for separating code and HTML is using a templating engine of some sort, I adore Smarty and normally recommend it without hesitation, but have to…

I've used twig quite a bit. Its leagues better than Smarty in every way. I heartily recommend you give it a spin. Having autoescaping built-in is a powerful and fantastic feature.

Smarty can actually do auto-escaping. Twig was specced in the Smarty 2 era and Smarty 3 and Twig ended up solving the problem in very similar ways. My biggest gripe with Smarty is how damn unprofessional it is - backwards compatibility breaking changes on point upgrades for example, and the code and "API" (I use the term loosely) is a mess.

Re: I Like PHP

#247

PHP's greatest strength is that it doesn't require OO. Seriously, for most simple web application tasks (and even some complicated ones) OO adds more confusion than it removes, and I say this as someone who certainly sees the value in OO for complex apps. Most web apps are ultimately more like shell scripts or console applications than desktop/mobile applications. It's no coincidence that most of the former are writt…

Google isn't the best place to look for object/method references. I've worked with a lot of large PHP codebases and the answer is always in the local source files or, if they're too obtuse, then on the project's documentation (if it exists and is current), in the PHP manual, or in a Google search result.

Any editor worth its salt can manipulate a cross-reference of the project's symbols. Learning how to do this has saved me days of time figuring out OO-heavy projects. I prefer ctags(1) and Vim.

Re: I Like PHP

#248

Earlier quoted context omitted.

Perl is a good example where most third-party modules have good documentation. Or at least a SYNOPSIS you can poke, some DESCRIPTION of what the module does, and a few hundred lines of code in the t/ directory that test all the features of the modules. The one thing I miss in Python is the inability to click "view source" in my web browser to see how a core Python library is implemented. PHP also has this problem. (C…

If you're talking about the search.cpan.org links to source, I'm right there with you. The only thing I wish they had was a way to pipe it through a highlighter like perltidy with html out. That'd probably just lead to holy wars on formatting/colours though.

MetaCPAN (http://metacpan.org) has a pretty source view.

For eg. https://metacpan.org/source/DRAEGTUN/Builder-0.05/lib/Builde...

Re: I Like PHP

#249

"there is no claim you can make about PHP that can’t be made about C as well, and vice versa." What about hundreds or thousands of inconsistently named built-in functions? C doesn't really have built-in functions, just a standard library that you don't have to load if you don't like it.

That's at best semantic nit-picking. You cannot write a useful C program without using the standard library or re-implementing (parts of) its functionality yourself. If for some reason having functions available that you don't use bothers you, you can still easily disable most of them by not loading any extensions; and if it's really a big issue to have the 'standard' functions in php available, you can compile php to not include them. If this is the best example of why php isn't like C, they are actually very similar...

Re: I Like PHP

#250

My first web language was PHP, I started working with it 12 years ago. Back then you didn't have Rails, Django, ORM, unit testing (in web dev that is), and javascript was looked as a language to just show popups and have confirm()'s before submitting forms. If you wanted to connect to a MySQL, you have to do it all by yourself, you need to create a database, tables, PKs, connect to database, execute RAW mysql queries…

I don't think it's a good idea to advice newbies to learn the hardcore way. I'm exactly like you, started with PHP, had to do everything manually, etc... except I have a different opinion.

The reason you and I and all the others like us put in so much effort in solving problems in PHP like CSRF, XSS and SQLI was because we were passionate enough to learn about that and then implement solutions for it.

Developers who don't care about security measures like that - they're the ones who store plaintext passwords, still - won't care either way, no matter if they're using Rails or PHP. Frameworks like Rails solves it for them, but if it weren't for Rails, their apps would have all these security problems, and they would only be addressed once disaster strikes.

Those that do care will be passionate about their work. They are the ones that read up on XSS and CSRF out of interest, not necessity. I'm sure they look at the generated HTML source once in a while, and then wonder why they add that token there. Using Rails, newbies are exposed to the solutions from the start, encouraging them to learn about it. As a PHP newbie, you're never exposed to the problem or the solution, until you start reading about security on your own or you get into trouble.

Post reply on HN