by pavs · 13y ago · 0 comments
My main purpose for learning PHP is for web-development. I have looked into java code and I felt like I am going to shit pants if I have to learn that.
2 questions.
- Am I wasting my time with PHP?
- What are some good alternative for web-development that preferably doesn't have a steep learning curve?
If you are learning PHP in 2013, yes, you are wasting your time. PHP's killer feature was (not any more) $5 web hosting, where you could upload your index.php with FTP and you're done with deployment. This is no longer the case. PHP stands for (at least used to) "Php is a Html Preprocessor", but at some point it turned into a general purpose programming language, largely as an afterthought.
Yes, you can learn web programming using PHP and that skill won't be wasted. But a lot of the PHP specific issues you'll be dealing with is just going to be a waste of time. There is a lot of WTF issues in PHP that you'll inevitably stumble into. This will be a major factor in the time wasted.
In addition, the world is full of bad PHP code. Yes, there is good PHP code too but the proportion of bad code is probably larger than in other languages. This will mislead you and make you learn bad practices more than you would perhaps do if you'd be learning another language. These are cultural, not technical issues.
For a beginner, I would recommend Python or JavaScript. Neither of them is my favorite language, but Python is rather beginner friendly and JavaScript has a special role since it's the language that web browsers use. Ruby is popular too, but in my opinion it has more traps a beginner could stumble into (not so much for an experienced programmer).
For learning purposes (not production code), I would perhaps even recommend staying out of big monolithic frameworks like Django and Rails and learn how things work internally. You'll get a better idea from HTTP and other web technologies if you build your own "framework" from building blocks like WSGI, SQL alchemy and a templating engine like Mako or Mustache (these are Python-specific, for another language, you'd pick other tools).
This is my recommendation for a beginner looking into web programming and my motivation is to keep a beginner away from bad technologies that may teach bad practices.
- GO: google's lang, seems to be trending lately. Lets you build potentially more elegant, higher performance web apps (if you believe the benchmarks) than node but will have a higher learning curve, less of a userbase.
- Python: Someone else will have to comment on python (and probably GO). Afaik it's a useful language to use overall.
What do you mean? What's the "global namespace" in PHP and why do you need to use it?
And it is easy to use it ... and you don't want to maintain code written like that.
Ruby, Python, and Node are all reasonable next things to try. Large communities, lots of resources, and plenty of example code to look at.
PHP has a problem, the "old stuff" / compatibility, like all older projects have. They change things, but slowly and sometimes inconseqent. I hope the will really renew everything with a new version, even if that mean that they lose many users.
In the last years so many new languages and styles were born, you feel really old with PHP ;-) ... that does not mean that the others were better.
Be a "programmer". Learn other languages. It makes you a better programmer in general.
> That, and if you are just starting to get into web development
These two things don't square well, and is a major reason why I discourage PHP. It's pedagogically suboptimal to be encouraging the sorts of behavior that culturally accepted PHP often does.
You can write good PHP. After many years I got to the point where I could say confidently that I can. But it took me most of a decade to get to that point of confidence.
The code I'd write in say, Clojure day one would be terrible when compared to the code I'd write a year or two later. Does that mean I shouldn't learn and use it?
Important point, whether you like php or not, you need to know why. If you like it because you are comfortable with it, make sure to know why. Being comfortable in a dev environment is great when you are learning, but very dangerous in the long run, since learning something new will be much (much) more painful.
Also, what is your final goal ?
If you just want to learn to build websites, regardless of top notch ways of doing things, just stick with what you are productive and comfortable with. The more reputable tech you use, the better, but it's not the point.
If you want to learn websites because it looks like a good way to learn programming in general, don't stay in the comfortable zone, don't fear the steep learning curve, embrace it. Well, it's not masochism either, if it's too painful, just stop. You have been intimidated by Java, but don't let it divert you from all other techs. Django/Python, Ruby on Rails, NodeJS and some others are much more easier to step into, will teach you much more about programming in general.
Employment wise it is a safe bet - there is a lot of legacy code for a person to maintain for a few lifetimes and then more.
The hatred towards PHP is explainable - if you use Haskell or Clojure today it is because you chose it. If you use php it is because you were forced to use it. So every little and not so little gotcha in the language (and there are a lot of them) is causing a lot of pain.
I have used python/(tornado/gevent)/flask/ stack with success.
Disclaimer - PHP programming 4 years, python 1
Having said that, learning a language's syntax is not the same as learning programming (or web development). If you are serious about what you are doing, learn OOP theory, design patterns, the internals of the web (TCP/IP, the HTTP protocol, etc.), security, and a bit of cryptography can't hurt.
So you can use PHP while learning all those things, and you will be golden. Ignore all the FUD and hate around it, eg: "php is insecure", "php websites are a mess", "php is for noobs", "php is slow". Using a different language won't fix any of that, learning how to program will.
And if you ever decide to switch to a different language within the same paradigm (procedural / OOP / semi functional, eg: ruby/python/javascript/java), it won't take longer than a few days, because you already know how to program, so you only have to learn the syntax.
If you like the "accessibility" of PHP, if you like programming in it, if you like the learning resources you have and you like the forums you've found, then go for it.
In due time you'll discover what the criticism about PHP was all about, form your own opinion and might check out other options (and Java won't be scary any more - just different syntax and a few concepts that you'll appreciate better when you have some experience).
Fact is PHP, for all its faults, still runs far more websites than all of those others combined and then some (http://w3techs.com/technologies/overview/programming_languag... - eg PHP 80%, Ruby 0.5%, Python 0.2%)
I learned PHP in 2003, and haven't regretted it since. There are quite a few PHP jobs here, and I like the culture that this language brings - unlike ASP.NET which is very corporate.
So yeah, use what makes you happy, PHP is a great start into a lot of other languages as it isn't as intense as others.
PHP is mostly ok as tool to get shit done with but it is one of the worst possible options for something to learn as a first programming language for many reasons, including:
- you will not learn how most real programming languages are, as PHP was not designed or engineered as a programming language, instead it is a collection of tools and commands that mutated and evolved into a programming language
- most code you will encounter written in PHP is very bad code (not all, but most), so you will find it very hard to learn from other people's code (this is the main reason to stay away from PHP imho!)
- it either lacks or has weird variants of the constructs that permit certain very useful styles of programming: no real closures until 5.3 and the need for the `use (...)` syntax to have them behave like in other languages, it has two namespaces for functions and variables (not other common language has this - yeah, there's Perl and Common Lisp, but...), weird stuff when it comes to namespaces, weird rules and stuff like autoloading, more weird stuff around the OOP features...
- so it leads to you learning all sorts of details that are basically untransferable skills - i.e. they won't make you a better programmer in general they will just make you a more effective PHP coder
I seriously recommend you to learn Javascript as a first language, as it has all the important constructs needed to learn programming in a sane way and it will also help you on the front-end side. It's just as simple as PHP to learn (I'd say simpler, because it doesn't have all the weird stuff in PHP) and later it will allow you to learn the basic concepts of both OOP and functional programming without much pain. Whereas coming from PHP, lots of concepts will be difficult to learn because "your mind will be twisted the wrong way". Javascript just feels natural for a beginner with no preconceptions: you can just assign a function to a variable and pass it around as a variable to other functions, then slowly learn what objects are by using them as "arrays" at first, then as arrays that have a special "prototype" (and with this, boom, you will have learned the simplest way to implement what in OOP is fancily called "inheritance" and you are in OOP land now).
Python is cool too, and it might be easier to find webhosts with python support than with Node (this is for Javascript running on the server, like PHP). Ruby too, but it too has "weird stuff" in it so I wouldn't recommend it as a first language, but it's still a better option than PHP. You can easily learn PHP in the future if your job will require, but don't start with it.
Oh, don't worry; JavaScript has plenty of weird stuff of its own.
With that said, I agree it's probably more worthwhile to learn than PHP.
Separate namespaces for variables and functions in Perl? Huh?
Different languages have different libraries, different communities, different philosophies, different purposes. Sure, a person who started in C can go and write C-ish code in many other languages. But that's bad code. Good code is idiomatic and takes advantage of the strengths of the language and platform it's written for.
Take php and ruby (two languages I happen to have used a fair bit both). If you're writing your typical web app, you'd probably use mysql for a database. That's the same. You talk http to the client - same. You want to parse xml? Probably going to use libxml underneath the covers. And so on. So yes, there's different libraries for the two, but there's also a lot that is shared.
As for different philosophies, they are both pretty much imperative languages. Php has a simpler object model than ruby and ruby has some fp features, such as co-routines, but by and large you write programs in the same style.
And different purposes? I'll dispute that. You pretty much use both languages for more or less the same things.
Mind you - I'm not saying they are exactly the same. Clearly they're not. But I'm saying the difference is in the nuances.
And while I do agree that ruby is a nicer language than php, I think the trend of treating it as if it was toxic is completely out of proportions.
I think you could pick better examples. PHP and Ruby are both interpreted, Perl-inspired languages started by hobbyist first-time language designers who released 1.0 versions about months apart. So yes, if you apply them to similar problems and use similar techniques in the same languages, you'll have similar experiences.
But even so, I think PHP's purpose, which is rooted in letting amateurs simply render web pages, is very different than Ruby's purpose, which is a flexible, general purpose, objects-first scripting language. I also think their design philosophies are pretty different. PHP has never worried much about elegance or consistency; Ruby inherited Perl's DWIM approach, but tried to do it in a way that was not just functional, but beautiful.