I’ve been writing JavaScript programs for a few years. Now it seems PHP is gaining favor. Which language is better to learn?
I realize my question is very subjective but I’d like to know some specifics such as:
*** Is the output of PHP easier to format than JavaScript ?
*** Are there more commands and functions in PHP ? (For example, JavaScript doesn’t even have a ‘GOTO’ command).
*** Is PHP programming a more marketable skill than JavaScript programming?
Before you answer, please do NOT speak in “computer-ese” (e.g. “when considering cross-platform, client-side, object-oriented applications…”).
This is comparing apples and oranges. PHP runs on the server side. The computer hosting the file executes the code. This code can be used to spit html back to the browser, and can have javascript embedded just like regular html.
Javascript runs on the client side. Your browser executes the code.
Personally I find PHP to be much more necessary and I use it for pretty complex database applicatins with mySQL.
You’ve been programming “for a few years” but you’re afraid of “computerese” ? I recommend you learn the computerese - it will help you understand these concepts.
You don’t need a goto if you’re programming correctly. Or you need it so rarely you’ll never miss it in 99.999% of all cases, and even more rarely in the kinds of things you’d be programming in JavaScript and PHP. A lot of `real’ languages support it, but that’s more to give the gurus a warm fuzzy feeling that they can, if they need to, throw structure to the wind and get some Real Work Done. Teaching new programmers goto-oriented programming should be punishable by law.
Which languages you learn will depend on what you want to do. Systems programmers will need to know C as a baseline, and one or more assembly languages in addition to that. Webpage designers who write CGI programs will probably learn Perl, that being the preeminent CGI language right now, and Java, JavaScript, and PHP for other tasks.
Those calculators on your site definitely should be in Javascript, as they appear to be. However, you may want to look into techniques that are applicable in almost any language. You could really clean this up.
Achernar
By your posting, I guess you mean that instead of my specifically naming each variable, I should have used a “while loop” with 25 recursions. Yes that is much “neater”, but since the execution speed as well as the loading speed was very fast, I never bothered to change it. (I just might change it if for no other reason to show I can do it).
Thanks for visiting the website and for the suggestions.
Anyway, it is good to know that for my website, learning JavaScript was the right choice for me.
I was going to say a for…in loop, but yeah. It wouldn’t help execution speed, of course. Such a thing wouldn’t, in general. But it would save you about 2kb of bandwidth, and make it easier to change or debug.
Flymaster
I read the Edsger Dijkstra rant against the infamous “GOTO” statement. Maybe I’m just getting cantankerous in my old age but could he have worded that any more obtusely? Sheesh, that was written in 1968, long before “computer-ese” enjoyed the popularity it does now. And for such a relatively short article, could he possibly have used the word “process” (or “processes”) any more? I counted a “mere” 21 instances of that word.
As for my distaste for “computer-ese”, I can easily understand the necessity for precise, specific, technical terms (brain surgery for example). Heck, even I used some “computer-ese” in my reply to Achernar when I mentioned a “while loop” with 25 recursions. However, the things I despise are people using terms that are pretentious and wordy just to make themselves and their work seem more important and esoteric than it really is.
An example ? Sure !! I read some time ago that a web designer was working on a site whereby, based on a person’s previous buying habits, the person would then be shown similar products on their next visit. Okay, basically, he decided to show people what they liked. Is that what he said the website did? NO. He said it gave consumers a “contextually-guided mercahndise experience”. LOL - true story.
Why can’t people speak a bit more clearly?
What’s that popular expression? eschew obfuscation
Well, Eleusis (the only one posting here relating to the question) pretty much covered it, but I wanted to add that in general, PHP is much more marketable than JavaScript.
PHP is more akin to CGI programming, with the advantage that it’s embedded into your web pages. For a simple example of what PHP is decent for, you can check out my art site, which I would never shamelessly plug. There seem to be 6 gallery pages, and over a hundred individual artpiece pages, but actually, there is only one of each, with PHP in the source files that pulls info from a back-end MySQL database.
IMO PHP is an incredible language. I’ve just written my first real application in it, and I keep becoming more and more pleasantly surprised by its balance of ease of use and power. But PHP is a server side thing, unlike Javascript. The two cannot be compared equally at all.
PHP output formatting is very flexible and powerful. And it has a lot of the C String functions too, which is cool.
There are an enormous number of commands and functions built into the standard PHP distribution. And the external functions that can be added (like on-the-fly Adobe PDF generation) are almost overwhelming.
Right now you see more “Javascript” on job requirements than “PHP”, but that is slowly and steadily changing. I think PHP will replace or be the equal of Perl within 1-2 years due to its very powerful functions library and ease of use - especially if you’re a C programmer already. Of course, that’s always a heated debate in some circles.
I’ve learnt C programming and know the operational structures well, but don’t have any real programming experience (school projects don’t count).
I want to learn PHP since I want to minimize the work required in putting up my website (I’ll putting up a gallery soon as well as leave open the possibility of adding other sections).
I went through W3School’s PHP tutorial and it was pretty easy in the sense that the syntax and basic algorithmic operations in PHP are analogous to C with a few technical differences here and there. But, how the hell do I learn how to actually write an useful app? What are the common library functions? What are the tricks to use them to do non-obvious things…etc? Most tutorials leave you at the constructs stage and provide the function table as a reference. That doesn’t seem to further my efforts.
No. No. No. Javascript is a language and there is nothing inherent in it which makes it client-side. Saying this is akin to saying that because you can write an applet in Java, Java must be client side, which would leave all those poor J2EE server-side Java guys slapping you with a cluestick.
You can write server-side Javascript ASP pages. In many cases, ASP pages are written in Javascript rather than VBScript if it facilitates porting the code (e.g. if code is being ported from C or Java to run as an ASP page, it is much more straightforward to port to Javascript than to VBScript). This is a major strength of ASP (compared to single-language server-side frameworks like J2EE and PHP) because you can blend VBScript, Javascript, Perlscript and many other languages (even Cobol) on the same site, even within the same page.
That said, I’m not going to say either one of Javascript or PHP is better. I use them both. I use PHP more, but that’s because I like it, it suits my needs, and I have servers conveniently available, not because it’s objectively better.
micco
So it seems that PHP might be worth learning. The trouble is, I do not know C or C++ at all.
Then again, remember about 20 years ago, it was Pascal that was THE language to use.
If you know JavaScript and PHP well enough to want to compare them, picking up C should be a breeze. Learning C from a Pascal background would be more of a shift, since they took a different evolutionary track from the same progenitor (Algol-60, I think), but the essential ideas are much the same.
Just keep in mind that C is a mid-level language. You are exposed to things like managing your own memory (learn about malloc() and free()) and pointer arithmetic (where a pointer is the address of a location in memory). It was designed, in some respects, to be a portable assembly language: The first big project it was used for was to rewrite Unix in a portable form, so it could move from the systems of its birth to the Rest of the World. So if you compare C to JavaScript, you’ll be sorely disappointed. However, if you want to write some time-critical piece of code that should still be portable from system to system, C will be the language of choice.
In my opinion, there is one really good book that teaches the C language: The C Programming Language, Second Edition by Brian W. Kernighan and Dennis M. Ritchie. You’ll get other books later, but this is the one to begin with.
As a final note, don’t use C as a stepping-stone to C++. It won’t work. If you don’t already know how OO works, learn Ruby or something to learn OO and then attempt C++. There is a huge gulf between C and C++ that is belied by a few syntactic similarities.
There’s no reason not to use PHP and Javascript together, according to the needs, but for my money PHP is far more versatile and useful than Javascript is. If you must learn only one, go with PHP.
If you’re running MacOS X (a kick-ass OS for web development), you’ve got everything you need – just start up the web server (Apache), write some PHP code, and bang away. Conversely, throw some Javascript into a few HTML pages, then load 'em up in Safari or IE.
Not to stick up for Windoze or anything, but the most convenient way of messing with it (if you can’t be bothered with installing Unix) is to download a windows installer for it on the PHP downloads page
And while you’re at it you can grab yourself Apache and mySQL for windows as well: