0% found this document useful (0 votes)
149 views22 pages

JavaScript vs PHP: A Humorous Debate

PHP and Javascript both have strengths and weaknesses for web development. Javascript excels at client-side development in the browser due to features like AJAX and a simple syntax. However, its dynamic typing and scoping can lead to bugs. PHP is better suited for server-side development and has a more robust standard library, but requires additional tools to enable client-side functionality. Overall, both languages are useful for web development, with Javascript being particularly well-suited for modern single-page applications.

Uploaded by

kingtutfashions
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
149 views22 pages

JavaScript vs PHP: A Humorous Debate

PHP and Javascript both have strengths and weaknesses for web development. Javascript excels at client-side development in the browser due to features like AJAX and a simple syntax. However, its dynamic typing and scoping can lead to bugs. PHP is better suited for server-side development and has a more robust standard library, but requires additional tools to enable client-side functionality. Overall, both languages are useful for web development, with Javascript being particularly well-suited for modern single-page applications.

Uploaded by

kingtutfashions
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PHP vs Javascript

Which sucks harder?


Rules

Referee: The SuckometerTM (written in Perl)

60 seconds per topic

Topics
− Syntax, Data Types, Scope, Name spaces and
Packaging, Standard Library, Extensions Libraries
− Procedural, Object Oriented, Functional and Meta
Programming, AOP
− Networking, Error Handling, Multi Tasking,
Reflection, Garbage Collection, Security, Tools
− Server Side, Client Side, Community,
Documentation
Syntax

Easy – the best of your favourite languages!
− “JavaScript borrows most of its syntax from Java,
but also inherits from Awk and Perl, with some
indirect influence from Self in its object prototype
system.” - Brendan Eich

Sexy one-liners
− $("p.surprise").addClass("ohmy").show("slow");

Narcissus – Javascript Self Interpreter
− it could almost be Lisp!
Core Data Types

Strings with Unicode support(!)

Objects are everywhere
− (102).toColorPart(); // prototype

Easy type conversion
− + operator overloaded, parseInt(), parseFloat()

Simple Collections
− Arrays for stacks, queues etc.
− Who needs hashes? In Javascript: Objects

Literal arrays / objects easy to generate
− e.g. JSON – it’s the new XML!
Scope / Name spacing / Packaging

Lexical scoping rules simple and easy to
remember:
− If it ain’t local… it’s global

Functions as name spaces – highly flexible!

Dynamic package loading on Internet scale!
− The library is everywhere:

Adsense

Maps

Tracking users
Standard Library

All the basics you need
− RegExp, Math, Date

Browser APIs
− The joy of DOM (OK: jquery)
− XMLHttpRequest - the worlds most exciting API!

And lots more...
− J2SE (via Rhino)
− .NET (via JScript.NET)
− XPCOM (e.g. Firefox extensions)
− wxJS (Javascript on wxWidgets)
Extension Libraries

prototype – the hottest library ever…

…apart from jquery, which is hotter

JSAN http://www.openjsan.org/
− CPAN for Javascript

Mozilla dying to blow our minds
− E.g. E4X - http://en.wikipedia.org/wiki/E4X
− Canvas
− Etc.

Lots more cool stuff at http://www.mozdev.org
Procedural Programming

All the control statements you know and love
− if, else, for, while, do...while, switch

Scales down
− Remember “DHTML for Dummies”?
Object Oriented Programming

(Almost) everything is an object

Implicit this variable makes Java programmers
feel right at home!

Prototype based inheritance radically reduces
lines of code
− No need for inherits!

Easy mix-ins at runtime
− add behaviour to prototypes
− add behaviour to objects
Functional Programming

Functions are objects too!

Functional programming blows your mind!
− …and shrinks your codebase!

Closures, monads, currying

Continuations
− via jwacs: http://chumsley.org/jwacs/
Meta Programming

Object.prototype !

# Dynamic cow…
var cow = new Object();

Object.prototype.moo = function() {
alert(‘Moooooo!’);
}

cow.moo(); # Oh Yes!
Aspect-Oriented Programming

No need for ugly byte code hacks!

Easy to roll your own
http://www.jadetower.org/muses/archives/000391.html

Or find library e.g. dojo.event.connect()

And CSS selectors == dependency injection!!!
− http://softwareas.com/css-the-tech-ajax-forgot
Networking

XMLHttpRequest (AJAX)
− When was the last time a network client API
caused this much excitement?

Via flash proxy to anywhere

Otherwise take your pick of networking from;
− Java (via Rhino)
− .NET (via JScript.NET)
− XPCOM
− wxWidgets
Error Handling

Exceptions, just like Java

Including finally!
Multi Tasking

Asynchronous XMLHttpRequest

setTimeout() is so easy!

Co-routines
− Via jwacs: http://chumsley.org/jwacs/

Iframes
Reflection

typeof – it doesn't get any easier!

...except instanceof which is even easier!

...and is (Javascript 2.0)
Garbage Collection

Different implementations: easy to understand
− Most: reference counting
− Spidermonkey: mark and sweep

Great tools
− Leak Monitor
− IE Leak Detector
Security

No files, no problem!
− Browsers keep all Javascript tightly locked down
Tools

They get better every day!
− Selenium : the web app tester
− Firebug
− Visual Studio Debugger
− JSEclipse
Server Side

http://haxe.org/

http://users.skynet.be/saw/wxJS/mod_wxjs/

Javascript Servlets

IIS: JScript + ASP.NET / ASP 3.0

More: http://en.wikipedia.org/wiki/Server-side_JavaScript
Client Side

Your browser! AJAX! Revolution.

Mozilla
− Firefox extensions
− Xulrunner

wxJS!
Final Rave

Steve Yegge (ex-Amazon, now Google)
http://steve-yegge.blogspot.com/2006/09/bloggers-block-3-dreaming-in-browser.html

“JavaScript is probably the most important


language in the world today.“

Are you still stuck on the server-side?

You might also like