Question:
What is the difference between a Binary Executable(C, C++, etc) and a Script(Bash, Korn, Perl, etc)?
Rash Guy
2011-07-14 00:44:56 UTC
I wish to know the difference between Binary Executable programs, like those written in Programming Languages such as C, C++, BASIC, JAVA, etc. and Scripts, like those written in Shells using interpreters like sh, csh, perl, awk, sed, etc.

Both of them generate execuable file, but I am not sure how exactly do they differ. Kindly elaborate.
Four answers:
AnalProgrammer
2011-07-14 00:56:43 UTC
Programming languages like c, c++, c# and Basic are compiled languages. The compile process is usually unique to the operating system and creates an executable file that can then be run many times.



Languages like REXX, sh, csh, perl, awk, sed etc are interpreted. That is to say that when you execute a script it is first compiled to a machine language and then executed. So every time you execute a script it is compiled. Because a script is compiled before it is run it can usually be run on any computer, regardless of the operating system. The compile first for interpreted languages does in effect make scripts slower to process at first. It also means that script programs should generally be kept short to reduce the compile time.



Java is a special case language. A Java program is compiled into byte code which is then interpreted on the virtual machine.



Have fun.
green meklar
2011-07-14 16:28:06 UTC
With standard compiled languages like C or C++, or the computer does not read out the actual code you write when executing the program. Rather, there is another program called a 'compiler' that takes the code you write and translates it into machine code, which is understood directly by the processor. Because no translation is happening at runtime, the program is able to execute very fast.



With standard scripting languages (also known as interpreted languages) like Javascript or SH, there is no compiler. Rather, there is a program or procedure called an 'interpreter' that reads over the script code and performs the specified operations one line at a time. Rather than new machine code being generated, the interpreter just executes machine code it already has depending on what it reads from the script.



Java is a special case. It is a compiled language, but it doesn't actually compile into machine code. Rather, it compiles into something called 'Java bytecode', which is then interpreted something like a script. This allows Java programs to share some of the advantages and disadvantages of both compiled languages and scripting languages.
Ben
2011-07-14 07:53:00 UTC
Actually, most Java implementations do not make a binary executable. Not in the traditional sense.



Your computer doesn't know what this thing called "text" is. It doesn't understand C++ or BASIC or Fortran or any other programming language. All it understands is a sequence of numbers. Some numbers represent actions, like add or subtract or read. Others represent actual numbers. And other numbers are used to represent text. This is the ONLY language that your computer understands. With languages like C++, you run a program called a compiler that turns the source code into a series of instructions that the computer can understand.



With an interpreted language, like Bash or Perl, the program cannot be run directly by the computer. Instead, the user of the script needs another program, a real executable program on their machine. That program reads in the script and issues machine code instructions based on what it reads in the script.



With langauges like Java and the .NET languages (VB.NET, C#, F#, and so on), you have sort of a middle ground. There is a compiler that generates a binary code. But it isn't machine code- your computer doesn't understand it directly. There's still that interpreter like in the scripting languages, called a "Just In Time Compiler" here that turns the byte code into real machine code when it runs.





The other thing you need to keep in mind is that there are languages and there are language implementations. The Oracle version of Java for instance, generates that intermediate code. But there are other versions of Java (like a frontend to GCC) that do generate real machine code. And it's possible to have other Java implementations that interpret the Java program just like a scripting language. They're still all Java even though they work differently.
deonejuan
2011-07-14 08:57:04 UTC
C, C++ are not transportable. You have to compile the source, with the correct library included in the compile process, for the platform. And, let me clue you: it can be a real pain to tweak the source code for the various CPU. You end up with multiple versions of the source code. But, once it compiles, the code executes. C and C++ are just one level above machine code with the Op Codes that make the Registries work.



BASIC and JAVA are interpreted for each run. There are tools to convert such programs into a binary, but then you lose portability. The BASIC needs an engine for each OS. The java needs the plug-in written for OS/hardware. The same for C# which does not run on Linux and could never be compiled to run as binary on Linux. C# needs the 9-gigabyte plug-in to run.



The scripts all need an engine. You script specifically for the engine, whereas in Java, Sun optimized the plug-in engine for you for the various hardwares. The Linux version, the Mac version and the PC version of the Java plug-in are greatly different, but you don't have to be concerned with the inner workings of the plug-in. With Shell you must know which engine. With javascript you must know which engine. With python you must know which engine. The scripts will not be transportable.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...