Forum Moderators: coopster & phranque

Message Too Old, No Replies

Why do you need scripting at all if you have C++?

A naive question from a novice

         

serega

3:35 am on Feb 19, 2002 (gmt 0)

10+ Year Member



OK, here is a very basic question. I have acquainted myself with Perl, PHP4 and JavaScript. What I do not really understand is why would you bother with any of those if you have your old good C/C++. Just upload to the server, compile, and do what you have to do. I know I am missing something here. So please tell me where I am wrong.

brotherhood of LAN

3:43 am on Feb 19, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Definetely somethng Id like to know too!!!

txbakers

3:43 am on Feb 19, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi and welcome.

Since C++ is compiled, the code and functionality has to be perfect before you put it on the server. If you have to make a change to the script, you need to recompile as well.

With the other scripting languages, to make a change is very simple as the scripts are interpreted on the fly. It's easier also to compose the script line by line and test as you go without having to compile.

Another thing to think about, many servers do not like to run strange exe files.

Air

3:49 am on Feb 19, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to the board serega.

Well IMO you are right, mostly. In the end it really depends on what you need to accomplish and the situation at hand. Consider this however, javascript runs client side so you really can't compare it to Perl, PHP, and C/C++. There are times when it is desireable to offload server cpu to the client and therefore javascript becomes a good choice, for example when parsing and validating form input.

Perl and PHP are a tradeoff compared to C/C++, a lot can be accomplished with much less code and complexity at the expense of speed (sometimes) and direct control of some low level machine functions.

The clincher though is that unless you are in control of the server you can't run C/C++ on most web hosting accounts, but Perl and PHP are offered as a standard. That makes code written in Perl and PHP usable on a great many more sites than the same code written in C/C++.

ggrot

4:07 am on Feb 19, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Air has alot of good points. c/c++ is definitely preferable in terms of efficiency, speed, etc assumming you know how to do it.

However, there is another type of efficiency/speed and that is development time. While C/C++ will do everything the other languages do, it's difficult at best. An example: If you want to make a page with a dynamically generated date somewhere that has the current day. C/C++ can generate the date and even format it easily enough if you know your stuff, but then you need to output the rest of the page to stdout. The most obvious thing is to output a couple of constant strings, but then you have to handle escaping various slashes, quotes, endlines, etc. Then you still have to compile on the server. In php, you just load up your favorite html editor, design the page, throw in a 1 line php tag for generating the date that shows up as a comment to the editor and thus wont break anything. Upload and you are done. When you want to change the design, you can do it in your favorite WYSIWYG.

Then there is the other extreme: If you are doing hardcore calculations on the other end before generating minimalist html(such as database analysis of logs or something), C/C++ is the better choice.

As I've always said, pick the best tool for the job. The more tools you have available to you, the better off you will be (although the law of diminishing returns always applies).

Everyman

4:09 am on Feb 19, 2002 (gmt 0)



A compiled C program that avoids calling a shell with system() or popen() will run anywhere from 2 to 10 times faster, and use one-half to one-tenth of the memory while it runs, as compared to JSP or Perl. Don't know enough about PHP to say one way or the other. Also, a properly-written C program is more secure. And you can SUID a compiled C program on Linux to get the permissions you need while it runs, but you can't do this with an interpreted script without using some sort of wrapper kluge.

The need to compile is trivial. It takes a few seconds on your own Linux box. You compile it for static libraries so that the sysadmin can't screw up the Linux system by upgrading or moving libraries or whatever. Just upload the compiled program into the cgi-bin directory. The compiled program may look bulky when static linking is used (between 100 and 200K using gcc, even after you strip out the symbols), but it's faster than hell.

I can handle and log in my own custom log, about 20 executions per second, sequentially from the same source, with a compiled C program on a plain 500 MHz Linux box with a T1, and keep the load under 1.0. I don't think an interpreted script would do this well.

serega

4:12 am on Feb 19, 2002 (gmt 0)

10+ Year Member



Thank you everyone for your great replies. Very very helpful. I appreciate it very much.

Brett_Tabke

5:38 am on Feb 20, 2002 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Well, if you are going to go to all that trouble, why would you use C in the first place? If you have a compiler, you probably have an assembler too! Why not use "the real thing"? ;)

cyril kearney

5:49 am on Feb 20, 2002 (gmt 0)

10+ Year Member



The decision on which language to use usually hinges on the cost of development. It is usually far cheaper to use a higher level language.

One has to be wary about saying that C++ will do things 2 to 5 times faster than a scripting language. Not that the statement is untrue but elapsed time for an application is more than code.

Say your application is data entry, The speed of the typist has more to do with the time of completing the job than the C++ code.

If your Internet connection is 9.6 the improvement gained by the C++ code is lost. If you read a data file, retrieval time generally more important that the speed of the processing code.

Low level languages just don't give the same bang for the buck as higher level ones. C++ is a higher level language than assembly but the scripting languages are higher level still (and probably implemented using C++.)

bird

6:49 am on Feb 20, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Why not use "the real thing"?

I've been complaining to my hosting service provider for years, but they stubbornly refuse to accept my CGI programs on punched cards... ;)