-
Notifications
You must be signed in to change notification settings - Fork 10
Javascript__Overview
Javascript was chosen as the main programming language for mkturk. As the language of the web, javascript has several advantages. There is a large developer and user community behind the language leading to noticeable improvements every year and an ever expanding list of APIs. The drive toward mobile devices and wireless solutions for computing has contributed to innovation in javascript. These advances have helped offset the historical critique that javascript wasn't as advanced as other languages. We strongly recommend you look into different options for yourself before taking the plunge with javascript. Many power users may find it limiting or be much more fluent in another preferred language. In that case, you may want to consider building an app and using something like Python or Java. We chose javascript because it is quick to get off the ground and works in the browser reducing the headaches of installation, app updates, and cross-device compatibility. Some have even gone as far as to say Javascript is the new C when you're not CPU bound. Also, wrapped up into the choice of javascript vs other languages is the choice of a web app versus an app. That choice has its own set of pros and cons with web apps being quicker to set up and maintain across devices while apps have more power and hardware access.
In fact, we are finding that the choice between programming languages and apps and web apps is becoming more and more blurred. We are encouraged by the recent availability of new cross-platform solutions. Electron allows a javascript web app to act more like a regular app and access the system hardware. PhoneGap can do the same and is more geared toward compatibility with mobile devices. In the other direction, Xamarin (or Ionic) can take your app and make it compatible across a wide range of settings. Given these options, any choice of programming language can be a good choice. In the future, one can hybridize and get the best of both the web app and native app worlds.
We recommend developing html/javascript web apps in Chrome. Chrome and Firefox typically keep up with the latest javascript features. If in doubt, you can always check whether your browser & version have a particular function by going to caniuse.com or looking at browser compatibility tables on the mozilla developer network MDN.
Under chrome://flags, enable experimental javascript ("Enable web pages to use experimental JavaScript features"). This just ensures you have access to the latest javascript functions such as async/await. Also, enable Web Bluetooth ("Enables Web Bluetooth which could allow websites to connect to and control Bluetooth devices around you") if you will use any bluetooth devices. Chrome now has a good bluetooth API that is starting to reach maturity. Finally, make sure the "Passive Event Listener Override" is set to Default so that passive is not set to true for eventlisteners. This avoids scrolling from taking over on passive elements (unless you would like no jank scrolling for some reason).
That's it, no real software installs, library dependencies, or purchase required. just load up your web app and then open the Chrome DevTools to debug and track the internals of your web app (alt-cmd-i on apple, ctrl-shft-i on pc). I would recommend reading about how to use the DevTools for debugging and memory/network/rendering performance.
You'll find the DevTools to be so great that when you go to test your web app on a phone or tablet, you'll be disappointed that they are not available there. You have two choices here. You can either simulate a mobile device within DevTools on chrome desktop or you can use remote debugging via usb connection from your desktop to the mobile device. If you choose to do remote debugging, then you will need to activate developer mode on your phone/tablet and then navigate to chrome://inspect on your computer's chrome browser.
Precise timing:
this has improved with the introduction of performance.now
Bluetooth:
web bluetooth is now possible through the chrome api and is available for origin trials. Some limits: BLE smart only, and accepting multiple devices and scanning are still in development.
Synchronous code for external events:
async/await is in the most recent developer javascript ECMAScript 7. Also, generators & promises in ECMAScript 6 allowed you to write synchronous code that looks cleaner than previous approaches.
3D rendering:
WebGL libraries are fast improving. See three.js and babylon.js for examples.
Good audio:
see the webaudio api
Access to the local system disk:
One can read local files from within the browser. You just can not write to the local disk for security.
Real time communication to other devices:
See the webusb api. If you want a direct line, another option is using the audio lines of the device. And for fast wireless, WebRTC may be the way forward.
Powerful computing:
This may be true. We have not fully tested the limits of javascript with respect to display updates and computational power. However, we would say that for basic behavioral tasks, you don't need that much power, and browser-based solutions are enough to get you 95% of what you need if not more. For that other 5%, if you really want to be cutting edge, then of course, you should go for a tailored solution probably outside the browser and probably even outside mobile devices to more dedicated hardware.
...Javascript is constantly evolving. If you wait long enough, the features you desire have a good chance of being implemented. As a recent example, something like seamless cloud based 3D CAD modeling, which you might have previously thought would be impossible in a browser, is now implemented in web apps such as Onshape. This case is illuminating in that it was enabled by key developments in javascript, developments that benefit many web apps including mkturk:
1 - anything related to 3D graphics or display in a modern computer or smartphone is done by the graphics processor (GPU), not the CPU
2 - companies such as Google have put tremendous resources into making Javascript execute fast within browsers
3 - there is a 2011 standard that lets a Javascript program running inside a browser tell the GPU what to do: WebGL
The client side of Onshape is essentially the mother-of-all-Javascript systems telling the graphics card what to do. It turns out to be more than sufficiently responsive. Other than a thin shell of an iOS or Android app, the company offers no software to download and install.
(Source: Phillip Greenspun's blog)