Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I regularly, (all over this thread), see people swear that PHP is great for beginners. Everything in this article seems to indicate the opposite. You have to trip over PHP's poor design while trying to learn to program.

Outside of the wide availability of PHP servers for cheap, what makes PHP so great for beginners? With Ruby, Python, Go, hell, even JSP for the "instant", in-HTML effect, I just don't see PHP as some gloriously "easy" language to use.

On top of it, there are hundreds of thousands of PHP tutorials all across the Internet that just have poor, poor, poor suggestions and design patterns that lead to people storing passwords unhashed, or unsalted. Sure, it's not unique to PHP, but it's really, really easy to get wrong in PHP and that's painful for a beginner and it's hard to progress and mature as a PHP developer without an existing code base to learn from.

tl;dr: I'm not convinced is as great as many here make it out to be. (To note, the first thing I sold was written in PHP in highschool. Since then I've used JSP/J2EE stack/python/ruby and now am infatuated with Go, so my opinion is not simply based on group-hate for PHP)



With PHP, creating a new "app" is a matter of sticking a .php file in a directory. There is no config file, directory structure, or server to babysit, and nothing to restart after modifications. Instead of using a complicated templating system, you just include HTML inline.

This is a horrible design for a large webapp, but even as an experienced programmer, sometimes I just want a quick hacky self-contained script, like the many, many .py files in a subdirectory of my home directory (but on the web, Python does not provide this convenience in commonly used setups). A beginner can similarly benefit from simplicity: even if Rails tutorial code is pretty, there is still a lot going on behind the scenes; sometimes, the smaller conceptual model required to really understand what's going on, the better.


"Sticking a php file in a directory" is just a matter of server config, not languages. There is no reason why you can't put a quick Python web app in a single file which exposes just one WSGI application object named 'application' - so if the server complied, you could indeed just stick the .py file in a certain magical directory.


Then why haven't anyone done it?

Cause as a designer who programs (mainly php) that is the number one reason why I haven't been learning a new language.

They all require way too much. Php just works for my needs. If I get bigger needs then I am sure I will make the switch to another language.


> Then why haven't anyone done it?

It's been done times and times again. Look at Sinatra for an example in the ruby world (http://www.sinatrarb.com/), I'm sure python has something similar. Maybe a static site generator such as octopress or push would be an option as well.

The problem is that the simple php approach does not scale. Sticking files in directories will only get you a small step, you'll need includes to share code soon. And then the mess starts if you're not using a framework. And good PHP frameworks go a long way beyond sticking a file in a directory - you'll have the same steep learning curve as with rails or something similar.


>They all require way too much. Php just works for my needs.

What? I understand for a beginner, but come on. If you're really a programmer programming for many hours aday... you really won't take the time to learn how to wire up wsgi to a python process? It's no harder than wiring Apache up to mod_php5 and telling it where to serve out of. It just takes a very modest effort on your part to learn it.

And then you get all the benefits of... not having to use PHP and getting to use... anything else.


I've been coding PHP for years and am just starting to learn Ruby on Rails. I'm not a programming expert at all, and so most of the objections mentioned would take me a while to parse.

From my perspective, Ruby on Rails is really, really difficult so far. You have to learn to use the terminal (which I've seen other people in my position use to totally mess up their computers); to make a simple application you're already looking at maybe a dozen files, many of which you don't understand; most importantly for me, because there is a lot of stuff going on that you can't see, it's very hard to extrapolate from examples.

I have learned what programming I know from breaking apart example programs and then using the pieces to build other things. I'm not good at learning from textbooks or tutorials. This has proved very difficult with RoR so far. I'll take components that look like they should make something happen, and then they'll throw an error that I don't understand and can't seem to locate.


Don't start with rails, start with ruby.

Doing otherwise is like trying to learn PHP by looking at the Drupal codebase.


I did, and Ruby was quick and easy. I wrote a bunch of programs and felt comfortable enough that I could understand stuff if I looked at it. But Rails seems like a whole other animal. And your right, this is the difference between languages and frameworks. But, without Rails I'm not sure how to get to a web app with Ruby. With PHP I was writing web apps before I really understood the language.

I don't mean to be saying that I'm doing it right, or that mine was a good way to learn programming. Just mean to be giving a data point about the relative approachability of PHP and RoR for actually making stuff as a beginner.


Start with Sinatra (http://www.sinatrarb.com/) instead. I had worked with PHP for a little while, and I decided to try out ROR. I could not understand it at all. I did some plain ruby for a while.

Eventually, I heard about Sinatra, and decided to try it out. It's a great way to learn about web apps. You'll learn the HTTP verbs if you haven't already, and you'll understand the routing process.

When you jump into Rails, you'll already understand Controllers and Routers, since Sinatra is basically the router and controller of Rails combined. You'll probably learn about views too.

Basically, learn sinatra, then go to Rails.


Agreed, rails is hard. Personally I prefer Sinatra and Ramaze since they are much simpler to understand.


I think this is an argument that we are not good at three things:

- Making better languages more accessible to utter newbies (PHP is unarguably the easiest to "get working", if nothing else of the prevalence of hosting).

- Showing newbie PHP developers how to do it better

- Introducing "better" languages to advanced newbies

The fact that PHP is used so widely as a gateway language, and the web is stuffed full of bad advice, is a systemic failure in those of us who know how to program well...


It's a hard problem, if not impossible based on its conditions: that which makes PHP easy for beginners make it hard for anyone to use well.

The ease of php (as mentioned repeatedly) is that you get global access to hundreds of functions. If you know how to call a function, you can probably hack together what you're trying to do. Others (python, ruby, go) are meant for more mature applications because real problems are not that simple. You "have to" do imports and write more boilerplate, but it's also more explicit as to what's happening in the context of HTTP and enables and encourages better design.

I feel like it's a compromise and I think creating something new that is as well thought out as Go but as simple as `<?php header("Location: http://google.com) ?>` would be difficult to do. See other things like PHP: JSP, etc.


> what makes PHP so great for beginners?

From what I can see and aside from the ease of install, it is the namespace. You type <?php and you have hundreds of functions at your disposal. Not the case with Python or Ruby where you need to understand imports and global objects.

Sometimes everything not being an object helps, but only in the short run.

It's not great, but it's the easiest to grasp.


from * import


That's an additional magic incantation people have to learn to add to the start of every file. In PHP, that magic incantation is invisible because they never have to type it or even know that it exists.


I was kidding (and lost the final asterisk); I would lose a lot of faith in Python if that ever worked. :)

Maybe new devs should learn Perl, instead... http://search.cpan.org/~adamk/Acme-Everything-1.01/lib/Acme/...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: