Slashdot Mirror


Carrot, an Open Source C++ scripting module for Apache

Fons Rademakers writes: "ROOT-Apache (aka Carrot) is an open source scripting module for the Apache webserver. Based on the ROOT framework which is using C++ as scripting language, via the CINT interpreter, it has a number of powerful features, including the ability to embed C++ code into HTML pages, run interpreted and compiled C++ macros, dynamically extend the framework with external libraries, access and manipulate databases, and generate graphics on-the-fly, among many others."

20 of 50 comments (clear)

  1. Yes... by Anonymous Coward · · Score: 3, Funny

    Because C++ is designed to be a quick and dirty web scripting language...

  2. Great idea by __past__ · · Score: 5, Funny

    Finally, a web-server scripting environment giving you all the features you always missed, like coredumps, buffer overflows and format string errors...

    1. Re:Great idea by Fweeky · · Score: 2, Funny

      > Finally, a web-server scripting environment giving you all the features you always missed, like
      > coredumps, buffer overflows and format string errors

      Yup, open source web software finally catches up with Microsoft. Should go nicely with the FreeBSD .NET port :)

    2. Re:Great idea by cperciva · · Score: 2

      I'll agree that buffer overflows and format string errors are a problem... but core dumps?

      If you don't want core dumps, disable them. Personally, I find core dumps to be rather useful things... if something goes wrong, you can track down what happened, unlike with interpreted languages where you'll be lucky to get an uninformative "Abnormal program termination" message back.

    3. Re:Great idea by Snowfox · · Score: 2
      What the reason to create *scripting* language which is as hard as C/C++ to program in? As scripting language it cannot be as fast as C/C++ language. And as C/C++ like language it cannot be as high level as other lanugages like Perl, Python, Ruby, etc.

      C/C++ are only hard to program in if you do everything from scratch. You wouldn't use any of the above languages without anyone else's toolkits and libraries. Why would you do differently with C/C++?

      There are string, memory, file, html, etc libraries which make C/C++ every bit as easy (some would say easier) to work with as any language you care to name. And there are more libraries available for free use than there are for all of the languages you can name combined.

      On top of that, you get a huge suite of debugging tools and superior performance. Do a little research. A C/C++ environment is about the most flexible thing out there. You can turn it into anything you like.

    4. Re:Great idea by m_ilya · · Score: 2, Interesting
      First of all don't take my words as offence. I don't want to say that C/C++ is bad. Still I think that most good scripting languages are much more easier to program in (with libraries or without them programs in scripting language are shorter anyway). After all good scripting languages are *designed* to be easier. You can have even garbage collection in C/C++ but still it fills very alien in it. However I know that some tasks are better to do in C/C++ (but definetly web development is wrong application for it).

      Anyway my point was that *scripting* languages which resemble C/C++ are crap. There is no huge suite of debugging tools and superior performance for them and there is no string, memory, file, html, etc libraries which make C/C++ every bit as easy for them. I've been there. I've been forced to write in one such language. It is very annoying when you have to deal with memory managment in *scripting* language.

      --

      --
      Ilya Martynov (http://martynov.org/)

    5. Re:Great idea by Wojtek · · Score: 3, Funny

      Format string errors? That's C. No, C++ in the webserver will bring you the joys of doing template code instantiation on every single page lookup! Fun for the whole family!

    6. Re:Great idea by Webmonger · · Score: 2

      Perhaps you should read a little more carefully. *this* C/C++ scripting language supports libraries that aren't specifically written for it.

  3. Not in C++ by ttfkam · · Score: 3, Funny

    As long as you write standard C++ (std::string instead of char*, cin/cout instead of scanf/printf, etc.) buffer overflows and format string errors go away. Core dumps are still a danger though...

    I agree though... All of the power of a scripting language with the ease of use and simplicity of C++. Makes me pine for the days where assembly was the dominant language.

    --

    - I don't need to go outside, my CRT tan'll do me just fine.
    1. Re:Not in C++ by __past__ · · Score: 3, Funny
      All of the power of a scripting language with the ease of use and simplicity of C++.
      Perhaps they want to learn from Java's success, which elegantly combined the disadvantages of interpreted and compiled languages...
    2. Re:Not in C++ by ttfkam · · Score: 2

      With the exception of Python (I think...I'm not sure) I know of no commonly used scripting languages that allow for simple and consistent object serialization/deserialization. I know of no scripting languages that have the equivalent functionality to EJBs. Combine those with the fact that strong typing (it's a int, it's a String) can be an invaluable asset in interface-based programs -- especially when talking to other languages or over a distributed model such as CORBA.

      While there is definite overlap, Java has a different problem space from most scripting languages (and from C or C++). Use the right tool for the job.

      --

      - I don't need to go outside, my CRT tan'll do me just fine.
    3. Re:Not in C++ by einhverfr · · Score: 2

      With the exception of Python (I think...I'm not sure) I know of no commonly used scripting languages that allow for simple and consistent object serialization/deserialization.

      iirc, REBOL has these features. Unfortunately, the licensing model for that language for commercial purposes sort of prices it out of the market even though it is a killer language.

      --

      LedgerSMB: Open source Accounting/ERP
  4. A better idea .... by geirt · · Score: 2

    I like C, but I think they got this the wrong way around...

    Instead of creating a scripting language out of C, they should have created a good way to embed html codes in the C source (eg. a pre-processor and a custom library), and compile the pages to a cgi program.

    This way you will get the best out of both worlds. You can code in C, and get real compile time checking instead of an interpreter failure because of a misspelled variable name or keyword. You get the speed of a compiled program and the C code can contain real html with no escape characters.

    With a good library (no libc by default, that is too risky ...) you can get access to apache internals, code in C (that is the whole idea, isn't it ?) and get super fast performance. The library needs a large collection of string handling functions.

    --

    RFC1925
    1. Re:A better idea .... by Anonymous Coward · · Score: 2, Informative

      With the cgicc library you can create CGI applications written in C++.

      Supported features: client-side cookies, file-uploading, fast-cgi and environment debugging.

      http://www.gnu.org/software/cgicc/

      http://www.fastcgi.com (A language independent, open extension to CGI, that provides better performance due to process persistance.)

      http://debianlinux.net/c++.html (C++ resources)

    2. Re:A better idea .... by geirt · · Score: 2

      Yes but you are still stuck with code like:

      printf("<tr>\n");
      printf("<td colspan = \"2\">\n");
      printf("<img src=\"/img/myimage.png\" alt=\"comment\" border=\"0\" height=\"100\" width=\"150\">");

      Not very readable. We need a preprocessor which embeds the HTML code in C for readability.

      --

      RFC1925
    3. Re:A better idea .... by ahde · · Score: 2

      Doesn't this also do it your way (a la JSP)

      example:

      <H1> Say it ten times </H1>
      <OL>
      <CARROT>
      for (int i = 0; i < 10;i++)
      cout << "<LI> this whole thing will be compiled" << endl;
      </CARROT>
      </OL>

      is converted to:

      cout << "<H1> Say it ten times </H1> "" << endl;
      cout << "<OL>" << endl;
      cout << "<!-- begin embedded carrot section -->" << endl;
      for (int i = 0; i < 10;i++)
      cout << "<LI> this whole thing will be compiled" << endl;
      cout << "<!-- end embedded carrot section -->" << endl;
      cout << "</OL>" << endl;

  5. Re:Java by ttfkam · · Score: 2

    Algorithms are fast or slow -- not so much the languages in which they are written. A for-loop in Java is just as fast as a for-loop in C. An O(log n) operation in BASIC will probably run faster than a O(n^2) operation in assembly. In most cases, if your standard library is complete and reasonably efficient, most programmer errors are avoided simply by helping them avoid reinvention of the wheel.

    That being said, as compared to C or C++, Java is a faster language in which to code -- standard library that includes networking, i/o, threading, enterprise components, directory services, database access, etc.

    That being said, Java is a more complete language for handling networking, i/o, threading, enterprise components, directory services, database access, etc. than any scripting language I know.

    That being said, for numerics, low-memory usage GUIs, kernels, and those applications that need the absolute last squeeze of performance (0.01% of all programs), use some language other than Java. Hell, use whatever works best for you. But a properly written program (badly written programs and inefficient algorithms can occur in any language) are speed-wise quite similar to one another despite the choice of language. There is a far greater variance in programmer ability than the inherent speed traits of a particular language.

    For the record, I don't own any Sun hardware, don't have $2 million to spare, and my servlets and EJBs run just fine thank you.

    My only point of skepticism with a scriptable C and C++ is that the languages weren't designed to be scriptable -- they were designed with compile-time inefficiency so that runtime efficiency could be maximized. This is in direct contrast to scripting languages that are meant to be loaded and run in a single pass with no linking steps, best guess, general optimizations, and ease of coding. If it works for Carrot, good for them. If it helps primarily C and C++ coders get their jobs done, good for them. Will it give the same type of benefits that languages such as Python can give, probably not.

    Use the right tool for the job and use that tool correctly. Everything else (including language-bashing) is waste of energy.

    --

    - I don't need to go outside, my CRT tan'll do me just fine.
  6. No no no... by ttfkam · · Score: 3, Informative

    Once again, there is far more variance in programmer ability (judicious use of algorithms and patterns) than is inherently demonstrated by language choice.

    Now with regard to Java, its standard library is much cleaner than that of Perl (for example). Perl objects were an afterthought and it shows. Its socket APIs are not intuitive. Couple this with the fact that you can't enforce by interface that a particular variable is an int vs. a string vs. anything else without extra runtime checks like regular expressions. This can add unecessarily to the runtime of a program. Large-scale Perl is a nightmare compared to language that doesn't just pay lip service to a component-based architecture. So right off the bat, this is what I get from servlets that I can't do with mod_perl.

    Comparing VMs, Java's is noticeably faster than both Perl's and Python's for computationally intensive programs and is not quite so bad against C or C++ as you assert. Combine this with the fact that Java can be compiled natively with a variety of tools today (although modern JVMs do a more than adequate job). Speed approaches that of C and C++ code without core dumps, buffer-overflow exploits, etc. Add to this excellent i18n and l10n support, standard networking, threading, database, directory services, distributed programming, ABI, etc., I consider it a good trade.

    A lot of development is going into Jython. Why? Because a lot of Python developers recognize the value of the Java platform. ...and the JVM is faster than the Python VM.

    Now let's examine the proprietary manuevers. Sun has not released Java to a standards body. ECMAScript *has* been released to a standards body and yet the programming models are not uniform on all platforms. Perl is the shining star apparently...but how many have tried to access CPAN modules directly from Perl on Windows? As it turns out, quite a few modules are programmed with C and a UNIX model in mind (or just Linux/BSD). Don't believe me, check out the graphics modules (dynamic creation of web images for example), RPC, mail handling, etc. So much for write once run anywhere with a "standard" language.

    Are there issues like a logger that was put in even though there was an arguably better one out there? ...and a regular expression engine? Sure. Do I like everything Sun has done? No. But then, I don't like everything the Perl, and C++ communities have done either.

    Now let's examine the J2EE issue. If Sun tested JBoss for free, what does that say to IBM, BEA et all who paid a lot of money to get tested? You'll lose partners that way. But also notice that Sun has not tried to bully JBoss out of the market. When you look closely at the Lutris (Enhydra) J2EE stink, you'll note that they were worried because they used Sun J2EE libraries to produce a product. Couple this with the fact that Sun never issued a cease and desist; Lutris pulled back on their own.

    As long as JBoss (and libre software in general) stays competitive, it is in Sun's best interest to leave it alone. Can you imagine what would happen if Sun suddenly decided to deny access to the Sun platform to anyone but licensed vendors? It would destroy the Solaris server market. The same holds true for Java. After all, it's just another platform, and there is far too much code out there to simply cut them off.

    This is like saying that maybe tomorrow Microsoft may announce that all compilers except for Visual Studio are not allowed to be used on Windows OSes. Aside from the anti-trust issues, there is simply too much code out there that has been written with a Borland, GNU, Intel, Metrowerks, etc. compiler.

    Someone's already pissed in the pool. You can't get it out now without draining all the water out first. Developers are in far more danger from DCMA, SSSCA, and other similar items than Java suddenly becoming unavailable.

    --

    - I don't need to go outside, my CRT tan'll do me just fine.
  7. Re:Java by lkaos · · Score: 2

    That being said, Java is a more complete language for handling networking, i/o, threading, enterprise components, directory services, database access, etc. than any scripting language I know.

    My biggest problem with Java is how horribly ugly it is. Interfaces are a joke and the lack of MI is incredibly painful. It's collections are utterly uselessly and adapter classes are almost as painful as functors in C++ although the lack of any binder functions make them much less useful.

    Java is, at best, an academic language. Very little useful things can be done with it other then a 20 line hello world program. It has some good ideas (Inner Classes) but they are poorly implemented and the memory model absolutely sucks.

    Passing by reference encourages sloppy programming as the use of final is not encouraged as it should. A well written C++ framework is a thousand times more robust then Java. Well written C++ classes can literally be safe even with monkeys smacking the keyboard in Emacs.

    Java would be better if 1) it was an open language and allowed input from people other than Sun engineers 2) it was organized by a company looking to create a good platform and not by a company looking to exploit every buzz phrase in the world 3) the JVM bytecode was robust enough to be useful for other languages (and not bastardized versions of languages such as Mangled C++).

    --
    int func(int a);
    func((b += 3, b));
  8. Re:Java by lkaos · · Score: 2

    Please. Interfaces couldnt be any simpler or easier to use. Lack of MI might be incredible painful to the .01% of people who need it. The other 100% dont care because interfaces provide what you need. Is it perfect? No but its hardly what you make it out to be.

    Interfaces are a poor excuse for MI and are misused in Java. The fact that interfaces can't have a default implementation (or that certain aspects of an interface can't be option) is why interfaces stink. GCC has an extension to C++ called signatures which are much more useful than Java interfaces especially since they can be applied to a class post-compilation.

    Java doesn't pass by reference. It passes reference by value. Your mistake is a common one.

    If Java does indeed pass value by reference, then surely I can pass reference by reference then perhaps? Or maybe dereference the reference and pass by value directly?

    No, you can't. Java doesn't give you the option. It does not have a 'robust' passing mechanism. Encouraging objects to be passed around by reference (making them writable) is very bad programming practice. Strict use of const (or final in Java) makes programming much safer. There is no reason why drawString should be able to modify the String object that is passed in.

    Java does have input from people other than the engineers at Sun.

    Is there a non-partial committee that oversees the development of the Java language? or do a bunch of suits at Sun determine what is in the language?

    They may be open to suggestions, but I would equate that more to stealing ideas.

    JVM bytecode *is* robust enough to be useful for other languages.

    So then it supports MI? Or referencing objects? Or passing objects by value? It supports operating overloading? Come on now. JVM bytecode is only useful to languages which only contain identical functionality to Java.

    The thing I wonder about though is why does that even make a difference?

    Because then Java could be used (practically) with other languages. The C-to-Java wrappers are a joke. If a language cannot be mixed with other languages, then it is useless in the real world and useless for most production programs where legacy libraries are a reality.

    --
    int func(int a);
    func((b += 3, b));