Advertisement

advantages and disadvantages of javascript language (and canvas environment)

Started by June 12, 2014 09:48 AM
9 comments, last by DiegoSLTS 10 years, 7 months ago

is i said Im new in learning javascript (+ canvas) im trying to get enlighten (orientation) in this environment but it goes slow , I would like to share some interest with this environment to learn it quicker and more in depth (as alone learning goes slow and i lost motivation)

Maybe someone could discuss a bit what he considers advantages and disadvantages of this language and canvas environment (those are two questions better treat as a bit separate) Maybe elsoe someone could inform me what is in scope of fundamental things in javascript language and canvas environment..? for example what differs javascript programming from c programming.. Maybe some cool tricks examples that would be impossible or very hard in c ..

One of the advantages to developing Javascript and canvas is that you do not actually need to develop your game in Javascript. You can use Coffescript, GO, Hack, Dart or a dozen different languages that basically compile down to minified Javascript. You can even program in C++ using various tools like Emscription to compile your code to Javascript. Think of Javascript really as the Assembly Language for your web browser.

Advertisement

One of the advantages to developing Javascript and canvas is that you do not actually need to develop your game in Javascript. You can use Coffescript, GO, Hack, Dart or a dozen different languages that basically compile down to minified Javascript. You can even program in C++ using various tools like Emscription to compile your code to Javascript. Think of Javascript really as the Assembly Language for your web browser.

i seem to be liking javascript so do not want to change it to another, though i would like to konow it nice sides and bad sides

One of the advantages to developing Javascript and canvas is that you do not actually need to develop your game in Javascript. You can use Coffescript, GO, Hack, Dart or a dozen different languages that basically compile down to minified Javascript. You can even program in C++ using various tools like Emscription to compile your code to Javascript. Think of Javascript really as the Assembly Language for your web browser.

Javascript is a high level programming language, comparing it to assembly sounds bad. Assembly is architecture dependant, so using a portable language that compiles to it makes sense (you compile the program for different assembly languages). With JavaScript you need just one compile, JavaScript code runs on any browser on any PC. It even handles objects and "classes", so there's no real need for other languages that compile to it. I'm not saying that Coffescript or the others are useless, but there are real advantages and disadvantages of the language, there's no need to avoid it only because other tools compile to it.

I've used JavaScript for a long time and the main aspects I see are:

- It supports "Objects" but not the full OOP approach. You can't define classes in the common way, you define prototypes, but even then you can grab any object of any "class" and add or remove attributes and methods from it.

- It's event-based. Since it's intended to use in browsers it's built around asynchronous tasks, so you end up passing callback functions A LOT and instead of doing things. You can do the same in C with function pointers, but with much more work and considerations.

- It's loosely typed. You can use anything as parameters or return values for the same function.

- It works in browsers, so anything related to internet and server-client programming is simplified.

- The code is always visible. You can always see what a .js file contains, any of the common browsers have tools for it.

Note I'm not using pros and cons lists, each of those things could be considered good or bad for different programmers and different projects.

Pros: easy language to pick up

Cons:

* worthless I/O functionality ( unless you have heavy duty server side modifications )

* you are forced to use pseudo classes

* imposable to run more complex programs with out lagging the browser

* browser support is all over the place ( nightmare to adapt to all the different browsers )

* security nightmare if you decide to have interactive websites

I cannot remember the books I've read any more than the meals I have eaten; even so, they have made me.

~ Ralph Waldo Emerson

@up @upup

very interesting i began to interest myself with javascript+canvas

(after the doing over five years with c+winapi) and i see its quite cool+interesting

Im not a big fan of oop and this js way of makin object seem quite cool novelty to me (prefer it over classical oop)

as to this loosly typing (damn hell a lot of dynamic typic) i was quite shocked too (in positive sense) when i saw how it works

i also noticed a lot of callback passing - this is quite new to me so I cannot rate/value it - possibly it my bring to reading confusion maybe,

not sure, maybe depends on style of coding

as to browsers - it really can slowdown whole browser when you run

it on one card in the background whole browser will be heavy? not responsible or something?

what means worthless I/O ? does that mean that i cannot save my game save with it? couldnt i give such javascript some input file to processing (with some open file dialog or something, and use this as a load/savegame mechanisms?)

code always visible: I tried to spy some games, and some have its source avaliable but some had some links to something and i cannot find the source (though ias i say Im very green at it - always thinked that js is some weak lenguage nothing interesting to, bt it showed by very surprisingly cool one) - so does it meant that with some tools i could be get that hidden sources too? (to look on them?)

Advertisement


code always visible: I tried to spy some games, and some have its source avaliable but some had some links to something and i cannot find the source (though ias i say Im very green at it - always thinked that js is some weak lenguage nothing interesting to, bt it showed by very surprisingly cool one) - so does it meant that with some tools i could be get that hidden sources too? (to look on them?)

If you share a link I can take a look.

Anyway, most of the times the .js files are minified and obfuscated, so getting the source is just the begining. For example, if you look at the jQuery code you can find things like:


function(){var a,b,c,d,e,f,g=arguments[0]||{},h=1,i=arguments.length,j=!1;for("boolean"==typeof g&&(j=g,g=arguments[h]||{},h++),"object"==typeof g||n.isFunction(g)||(g={}),h===i&&(g=this,h--);i>h;h++)if(null!=(e=arguments[h]))for(d in e)a=g[d],c=e[d],g!==c&&(j&&c&&(n.isPlainObject(c)||(b=n.isArray(c)))?(b?(b=!1,f=a&&n.isArray(a)?a:[]):f=a&&n.isPlainObject(a)?a:{},g[d]=n.extend(j,f,c)):void 0!==c&&(g[d]=c));return g}

in the middle of a big string and you won't understand what it's doing unless you debug a lot and try to translate the file to something easy to read. Also, with the events and callbacks it can be really hard to find out what the code is supposed to do.


* worthless I/O functionality ( unless you have heavy duty server side modifications )
* you are forced to use pseudo classes
* imposable to run more complex programs with out lagging the browser
* browser support is all over the place ( nightmare to adapt to all the different browsers )
* security nightmare if you decide to have interactive websites

Just as counter-points:

  • Not quite sure what you mean "worthless I/O functionality"
  • That's a bit like saying C forces you to use structures -- not every language has to be based on classes. Javascript's notion of object-orientation is based on Prototypes.
  • Hard, perhaps. Impossible, no.
  • Its not perfect, not great, even. But 'all over the place' is a bit dramatic. Whatever the supposed promise of javascript is supposed to be, writing cross-browser code is effectively writing cross-platform code. You have to write browser-specific codepaths just like you have to write platform-specific codepaths in C++ or any other language. And if you don't want to do that, pick just one browser to support, just like you would pick just one platform. Chrome's install base is effectively as large as Windows' (or certainly far larger than you will ever saturate), even if you discount people using a version more than about 6 months old -- nearly everyone keeps their browsers very up-to-date.
  • Security is always a nightmare, but its probably better in a browser and on your own servers than just about anywhere else.

throw table_exception("(? ???)? ? ???");

Things I like about javascript

  • Its fairly simple and easy to learn
  • It is built on high level libraries so loading and drawing images, playing sounds, and downloading files is easy to do
  • Duck typing
  • Arrays and maps are built into the language
  • Reading and writing JSON is super easy
  • Your code targets browsers, not operating systems, making it easy to make cross platform programs

Things I don't like about javascript

  • There is no compile time type checking quickly making large projects difficult to manage
  • Prototypes, I think classes are a better option
  • It has a small built in library and, if you are targeting the browser, you cannot add your own native code libraries.

Overall, javascript is still one of my favorite languages. I will usually use it if I want to create quickly create a simple project that is meant to be cross platform.

My current game project Platform RPG

as to big projects, is javascript intendend and hold large projects? How large? what such large projects would do in browser? indeed it must be hard as large project would take a lot of text, a lot of interpretation etc

is there usable limit on a js script in lines?

This topic is closed to new replies.

Advertisement