Live data from Hacker News

Cling: Running C++ in an interpreter

blog.coldflake.com

11–20 of 49 posts

Re: Cling: Running C++ in an interpreter

#11
I just keep a fixed .cpp file with a bunch of common includes and directives, and alias the g++ command to link to common libraries, so my workflow goes:

> vim temp.cpp

> g++ temp.cpp

> ./a.out

Very similar to my process with Python, actually. Every time I use the REPL for some experimenting, the code ends up outgrowing it and I have to stuff it in a file anyway, so I may as well cut out the middleman to begin with. YMMV.

Re: Cling: Running C++ in an interpreter

#12

Why would I do that :S

I can see it being helpful if you are working in C++ all day and need to try small things out. I use LinqPad for doing the same w/ C#, helps when you need to test out some smaller ideas w/o all the cruft of projects and references / includes / etc.

Re: Cling: Running C++ in an interpreter

#13
It's a cool idea, but his reason for creating it is kinda dumb.

Creating an entire "project" just to check a code snippet is just silly.

Just create a "testing" directory and throw your one off test files into it and compile/run them there.

I start mine with a comment explaining what I'm testing, why I'm testing it, and what special compilation flags are required, if any. I even have an Emacs macro that fills in the boilerplate includes and main function. The overhead involved is probably less than 15 seconds.

It has the advantages that I can test multiple compilers and I keep a history of the things I've tried.

Re: Cling: Running C++ in an interpreter

#14
post #10
post #7

Earlier quoted context omitted.

Why not? It's great to quickly test C++, I have yet to find a developer who doesn't love a REPL for one. C++ could also be used as an embedded extension language using something like this.

I share your enthusiasm but there are limits. C++ compilation speed (and thus interpretation speed) will make it quite impossible to use it as an extension language. And while I like and use C++ a lot I don't think it is the right language for this purpose. It can do quite a lot of things, but working in a homogeneous language in your extensions as well as your core product doesn't have enough benefits compared to us…

Well if it's possible for C++, it's definitely possible for D which is benchmarked to compile 100 times faster and has close-to-ruby's productivity in a close-to-metal language like C. An added benefit is that D already has most of the C++11 features and more.

I would very much like to use D as an extension language.

Re: Cling: Running C++ in an interpreter

#15
I've used libtcc from tcc to do something similar on a prototype listening on a socket to do queries over a 2 gig memory mapped file. I'd pass over the query as a string of C that would be dynamically compiled and executed by libtcc. It worked really well but ultimately didn't go anywhere other than research. Here's an example from the distribution (first google result for the file): http://www.koders.com/c/fidC76C8B834DFF05F1D0BD61220AC19E246.... TCC can be found here: http://bellard.org/tcc/

Re: Cling: Running C++ in an interpreter

#16

It's a cool idea, but his reason for creating it is kinda dumb. Creating an entire "project" just to check a code snippet is just silly. Just create a "testing" directory and throw your one off test files into it and compile/run them there. I start mine with a comment explaining what I'm testing, why I'm testing it, and what special compilation flags are required, if any. I even have an Emacs macro that fills in the…

The ROOT project has been using CINT for ages. Talk to your favorite physicist friend -- they'll be confused why the CS crowd _doesn't_ have this technology.

This is just an updating of what must be an awful hack to be built on LLVM infrastructure.

Re: Cling: Running C++ in an interpreter

#17
I think it is very useful if you want to know more about c++,especially some feature you 're not very sure about. interactive interpret make it very intuitive, and it will save you time,because you don't need to compile the code. but one limit is that now it doesn't support template , you still have to write a source file if you want to use template.

Re: Cling: Running C++ in an interpreter

#18
post #11

I just keep a fixed .cpp file with a bunch of common includes and directives, and alias the g++ command to link to common libraries, so my workflow goes: > vim temp.cpp > g++ temp.cpp > ./a.out Very similar to my process with Python, actually. Every time I use the REPL for some experimenting, the code ends up outgrowing it and I have to stuff it in a file anyway, so I may as well cut out the middleman to begin with.…

I too put the code in a file even in Python, but REPL is still valuable. I use "python -i" which runs your code (defines functions, classes, etc.) and then stop, and put you in that environment. This is very useful. It seems Cling could be used the same way: .x command.

Re: Cling: Running C++ in an interpreter

#19
post #10
post #7

Earlier quoted context omitted.

Why not? It's great to quickly test C++, I have yet to find a developer who doesn't love a REPL for one. C++ could also be used as an embedded extension language using something like this.

I share your enthusiasm but there are limits. C++ compilation speed (and thus interpretation speed) will make it quite impossible to use it as an extension language. And while I like and use C++ a lot I don't think it is the right language for this purpose. It can do quite a lot of things, but working in a homogeneous language in your extensions as well as your core product doesn't have enough benefits compared to us…

> C++ compilation speed (and thus interpretation speed) will make it quite impossible to use it as an extension language.

I think you vastly underestimate the speed of the clang C++ compiler (or any modern C++ compiler at that). I can't imagine that the compilation time for anything that could be classified as an "extension" would be significant in any meaningful way.

Post reply on HN