Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are so many web languages interpreted rather than compiled?

Why didn't languages such as C end up being using for web dev? Surely the speed increases from being compiled would be useful for heavy load sites?

like image 444
Rich Bradshaw Avatar asked Dec 04 '08 11:12

Rich Bradshaw


People also ask

Why are interpreted languages better than compiled?

Advantages of interpreted languagesInterpreted languages tend to be more flexible, and often offer features like dynamic typing and smaller program size. Also, because interpreters execute the source program code themselves, the code itself is platform independent.

Why is most of the scripting languages are interpreted and not compiled?

Scripting languages are typically not compiled. Instead, the code is fed directly into an interpreter at runtime. The interpreter reads and executes the program on-the-fly. Because the code is loaded and executed in tandem, scripting language environments sometimes do things that compiled languages cannot.

Why do we use interpreter instead of compiler?

Interpreter Vs Compiler Scans the entire program and translates it as a whole into machine code. Interpreters usually take less amount of time to analyze the source code. However, the overall execution time is comparatively slower than compilers. Compilers usually take a large amount of time to analyze the source code.

Why JavaScript is usually interpreted rather than being compiled?

The source code is passed through a program called a compiler, which translates it into bytecode that the machine understands and can execute. In contrast, JavaScript has no compilation step. Instead, an interpreter in the browser reads over the JavaScript code, interprets each line, and runs it.


3 Answers

Another good reason is that on a big server execution speed is not so much an issue as the connection speed anyway. Most of the time is spent sending and receiving data, not number crunching. And actually in certain web services which do a lot of computations, the hard crunching is probably run as a compiled program.

Plus interpreted languages don't need compiling (which on a large project can take time), thus it's more suited for the typically agile development of web solutions.

like image 169
Stein G. Strindhaug Avatar answered Nov 03 '22 06:11

Stein G. Strindhaug


Most web applications talk to a database. The overwhelming majority of these apps spend almost all of their time communicating with the database. So, for any given request to the application, there is a tiny amount of processing in the application server and then a long pause while waiting for the database. Since such a small percentage of any request's time is spent in actual application server code, optimizing that code by writing it in C/C++ will gain only a tiny, likely not noticeable, improvement in response time.

So, rather than focusing on C/C++ and saving every last CPU cycle, it makes more sense to worry about developer productivity. Developers are very expensive. And, they're typically much more productive in a scripting language or even in Java than they are in C/C++.

Of course, there are exceptions to this. And if some requests to your application are CPU or memory intensive, they should be written in C/C++. But, for the rest of your application, you're better off focusing on optimizing your algorithms, data structures, communication with the database, and developer productivity than in optimizing your language.

like image 29
Clint Miller Avatar answered Nov 03 '22 06:11

Clint Miller


Scripting languages have the following advantages over C:

  1. Much faster development
  2. Today, all of those relevant to this question are compiled at runtime. In some cases, this can make them faster than an equivalent C program, so performance just isn't an issue anymore.
  3. Maintenance costs much less
  4. You can develop using Agile methods (like unit tests) which results in much better code. Yeah, you can do that in C, too, but it's much more effort.
  5. When you're doing web development, you have huge frameworks which do most of the work for you.
  6. They are much more open to change. A new feature can take as much as a few minutes to implement.
  7. If something is broken, you can login to your server, start a text editor in the console and fix the problem, sometimes without having to restart.
like image 21
Aaron Digulla Avatar answered Nov 03 '22 06:11

Aaron Digulla