When searching for online code editors (out of interest how all the course sites such as Codecademy has been made) I noticed they are all been written in JavaScript.Why are all those code editors such as CodeMirror or Ace written in JavaScript and not in PHP or Java for web applications?
Online code editors programming language
javascript;ide;text editor
PHP and Java are processed Server-Side. JavaScript is processed by the web browser.If you were processing in real-time with PHP, you would need a piece of JavaScript (such as an AJAX POST) to send the entire chunk of code to the server for re-processing, wait for a return and then replace the entire display with newly formatted text every time a user changes a single character.JavaScript can do this all itself directly in the web browser and leverage the power of the Users PC to accomplish the task.Using JavaScript speeds up the process as nothing ends to be passed backwards and forwards all the time, it lowers bandwidth usage as nothing is passed to and fro and it also reduces the server workload for the same reason.There is also an argument that it is more reliable and secure. If you are not passing anything back to a server, there is no need to worry as much about properly escaping special characters, less of a concern about an insecure piece of server-side code being exploited etc.It is also good practise to not send anything back and put a load on your server unless there is a good reason to do so.While you could have a button on your code editor which would send an entire chunk of script back to a server for processing and send back a formatted return, it's generally not the done thing for the reason stated above. Also, a reformat all button wouldn't add much value as you can simply reformat everything in JavaScript.