Tuesday, July 14, 2009

What are the PROS and CONS of using a scripting language vs C++ code?

I've searched but I can't seem to find a decent answer. What are ya'll opinions?





What are the pros and cons of using a scripting language vs c++ code?





Thanks....

What are the PROS and CONS of using a scripting language vs C++ code?
Good question and interesting answers. The cons of a scripting language are reasonably described by the others: slower execution, potentially limited in performing certain tasks, and so on.





Some of the pros are touched on: easier to write, less lines of code usually do more functions than in C++, easier to understand, smaller file size for web communications and so on.





No one stated the true goal (holy grail) of scripting languages. The ultimate goal of scripts was to make the scripts machine and operating system independent. That's one huge reason why scripts are so prevalent in web communications. We have no clue as to the processor or OS of the people viewing or using our sites. Thus, we roll out generic scripts. Linux, Sun, MS, others make special engines or interpreters that interpret these lines of code so that they operate identically on each platform--no matter what OS or hardware is under the hood.





If we made one application in C++ and compiled it, the application would only run on the targeted machine. There is no way that a gcc, VS, GNU, etc. compiler could generate one binary application that would run on Macs, Suns, PC's, etc. However, one well written program in a scripting language will run across these dissimilar machines/OS's.





Bottom line and the biggest reason for scripting languages: Machine and platform independence.





Hope that helps.
Reply:If you're talking about on a web site, scripting generally executes in the browser, C++ executes on the server.
Reply:Scripting is basically in my point of view a set of lines where each individual line will do something, its for tasks which are quicker to do by running a script... For example I've mad a bash script which asks the user for a port, reads the port, checks which processes are running on them and then ends them, typing the same thing each time would take ages and the codes kinda hard to remember. It's all command line based.





C++ is a bit more intense, and requires compiling and thus runs significantly faster. Take my bash script for example, one of the lines is lsof, a C++ code would of been made to create this rather than a script, it's faster and is ideal for more advance tasks rather than just convenience and preventing you from having to type the same few lines over and over, it's also much more open, it's not limited to the commands in bash (or batch if your a Windows man). The main thing though is speed, games are wrote in C++, this is completely impossible in most scripting languages.





Scripting is for convenience, programming is more for doing things which cant be done line by line. I'd write a script to shutdown my computer in 30 minutes, I'd use a C++ program to convert an avi video to a DVD. The up side to scripting though is because it does not requre compiling and in most cases a command can be executed line by line you can work with each line individually, in C++ you'd have to write the whole lot then compile it.
Reply:What others failed to mention





SInce scripts are essentially text files, unless properly secured against changes, the script can be changed by users and either rendered useless or open security issues within your secured computing environment.





A compiled program is a binary file which, with the proper tools, also be edited, but the users are less likely to change a compiled object. Therefore, your internal code is more secure from prying eyes, especially if you use usernames and passwords within the program.
Reply:Scripting languages are not compiled, so have to be interpreted each time they are executed. C++ is compiled into a binary (executable) which runs faster.





Compilers also have switches you can use at compile time. So, depending what you want to do, you might be able to unroll loops (with a compiler switch) making the code faster.





There are other compiler switches that will further optimize the compiled code.





Hope it helps!
Reply:C++ is a compiled language, therefore it runs faster. Scripting code is executed on the fly, therefore taking slightly longer.





However compiled code is more prone to bugs, as they may not become apparent until the program has executed under all possible scenarios. Script bugs generally show up straight away as the code is being read and the program is being executed.
Reply:Scripting languages are interpreted. Practically everything that follows results from the potential differences of interpreted versus compiled languages.





CON:


Interpreted languages, even those that are compiled into an intermediate form, are slower than running the compiled (machine language) equivalent commands.


BUT some languages (Java/bytecode, Pascal/P-code) can be run off an intermediate form very efficiently.





PRO:


Interpreters can normally give you better access to the runtime environment.


BUT IDEs (like Eclipse) have extensive debugging capability and this is not as big an advantage nowadays.





PRO:


Scripting languages are highly extensible and tend to be application/environment specific.


BUT languages like FORTH, Java, Ruby, C++, etc. allow the programmer to create "first class" extensions to the language which are treated as part of the original language.





PRO:


Quick-n-dirty implementations of a language are easier in an interpreter.


BUT ... well, that one's got no counter argument -- you are saving time on the initial implementation. Perhaps later you will create a compiled implementation.


No comments:

Post a Comment