Hey everyone. My online game requires me to display a map, and that involves making a lot of divs on the page at specified places. If I do this with PHP, it assembles the divs which takes a long time and results in a big file, THEN it sends it to the client. Lots of CPU time. Lots of transfer. Very, very bad.

I'm thinking, hey! There's client-side languages, right? I can give all the work to the browser, and everyone will be happy. Huzzah! So I look into it. Apparently, javascript's the main client-side language everyone use. I look at tutorials, I get myself acquainted with javascript, I'm pretty confident in my javascripting skills.

Three weeks and 100 errors later, I'm cursing javascript to an untimely death involving lots of pain:
1. It can never give you the right line number of an error!
2. The error messages it does give you make no sense.
3. Classes don't involve real classes at all... they're... functions?! (yeah, I know, personal preferences and whatnot, but its frickin sloppy)
4. Execution stops at an error? It should keep going!
5. You need 3 sets of code, one for netscape, one for IE, and one for firefox.

So, screw javascript. I need a different language to program in, but I can't figure it out... the only other language I've heard of is VBscript, but is it supported? and does it have the same faults as javascript? And then theres Flash, but its a very steep learning curve...

What do I do? PHP is power-hungry in this situation and javascript is as unstable as a house of cards.

  • E
    Verdagon wrote:

    Three weeks and 100 errors later, I'm cursing javascript to an untimely death involving lots of pain:
    1. It can never give you the right line number of an error!

    Some web browsers (MSIE 6 and perhaps some other versions) give you junk line numbers for errors. This problem is solved on IE6 by installing relevant debug tools on the client side and using them. Microsoft's documentation will help here.

    Mozilla gives correct line numbers for Javascript errors, but if your client-side code is generated by server-side code, these won't tally with your line numbers in PHP.

    I STRONGLY recommend that:

    1. Don't mix client and server-side code - put all client code in an external, flat .js file which isn't dynamically generated by PHP.
    2. Install and familiarise yourself with all supported clients' debug tools.

    2. The error messages it does give you make no sense.

    Javascript is a dynamically typed language, like PHP. As such, sometimes error messages may appear to make no sense, particularly if something that you're expecting to have a particular property (remember, everything is an object and a method is really a property of type function) doesn't have that one.

    Use a debugger. Use watches, set breakpoints etc.

    3. Classes don't involve real classes at all... they're... functions?! (yeah, I know, personal preferences and whatnot, but its frickin sloppy)

    Javascript doesn't have classes, it has prototypes. Understand the language and you will know how this works and why it is good.

    4. Execution stops at an error? It should keep going!

    Javascript, unlike PHP, has structured exception handling. You can catch an exception which is thrown from almost any kind of error. Not all browsers give the exception object useful properties in all cases, but you can still catch it. Try some experiments.

    5. You need 3 sets of code, one for netscape, one for IE, and one for firefox.

    No, you don't. You should be able to have exactly one.

    Netscape is the same browser as Mozilla, so you should not need different code.

    Javascript behaves very much the same in MSIE, the only differences are in the DOM and they're not major.

    Event handling is a bit of a pain in the arse, but even that isn't THAT hard.

    So, screw javascript. I need a different language to program in, but I can't figure it out... the only other language I've heard of is VBscript, but is it supported? and does it have the same faults as javascript? And then theres Flash, but its a very steep learning curve...

    The main alternatives are:

    • Java (Big client-side memory footprint, long load times, but very powerful with lots of useful stuff)
    • Flash (Good for fancy stuff; You still have to use Javascript (Actionscript is almost identical semantically to Javascript))

    What do I do? PHP is power-hungry in this situation and javascript is as unstable as a house of cards.

    Nonsense. Javascript is an extremely nice language which was designed a lot better than PHP (in my opinion, obviously).

    Mark

      Write a Reply...