Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
How I stopped worrying and switched to C++ for my Bob Scheme VM (thegreenplace.net)
79 points by wglb on Dec 2, 2011 | hide | past | favorite | 18 comments


Nice to read an article about someone successfully using C++ in an ordinary way, even with a little OO to it. We know it happens all the time given the volume of C++ in development.

But so many articles are like "C++ isn't OO", "C++ has awful syntax", "C/C++ is insecure", "ZOMG templates", etc.


The problem with C++ isn't that it has any one of these problems; the problem is that different people have different opinions on what the problems are.


I don't mind that kind of a problem.

Any language that lacks a diversity of opinions about its strengths and weaknesses doesn't sound very interesting to me. I suspect it lacks expressive power.

I once started a job which involved a little bit of Perl. The other Perl programmers on the team were a little freaked out by my unfamiliar Perl syntax. I didn't tell them that everything they objected to was from the O'Reilly book "Perl Best Practices". :-)


I'm currenty on a project, where C++ is used as "C", and I'm quite fine with this. In couple of the thread loops, there is setjmp handler waiting for longjmp... It's also waiting for the unaware new programmer on the team to use RAII, and not suspect it's failing. (We use longjmp/setjmp not only for error situations, but to handle other exceptional situations and recover from them). One of the platform we are targeting simply does not support C++ exceptions.


How do you guys deal with the long compilation times? For me, I wouldn't mind C++...if it only compiled faster. Even just two or three C++ files take ~5 seconds to compile on my machine. Is this not an unacceptable amount of time for you, or do you have tools to make this go below the 3 second threshold? In my mind, this is a serious problem that is keeping me from using C++ more. I try to do as much as possible in C for now.


- For simple 'syntax checking' compiles, compile only the module ('.cpp file') you're working in. This requires a proper IDE or at least some editor support - for VS it's ctrl-f7.

- For 'whole-project' compiles, limit the amount of them to the absolute minimum. Use unit tests to test fundamental functionality rather than running the whole program.

- Use a compiler that supports precompiled headers, understand how it works and use it as it's designed.

- Pay attention to your #include graph. Only include headers where they're used (i.e., in the .cpp file and not in the header where it's possible), use Cheshire cat where possible, and put as much into the precompiled header as possible.

Doing all of these things make C++ compilation bearable, but still it's a nice change when I write code in C# or 'scripting' languages and compilation times disappears. It's one of the more annoying aspects of C++, but despite it and a bunch of other nitpicks, it's still my favorite language.


I took a measurement of the number of non-comment non-blank lines of code for each std c++ header file. I'm now experimenting with writing replacements and wrappers for the classes that require the larger ones. My theory is that I can get by just fine with the 80% of the features that I really need, and end up with 20% of the code.

https://github.com/marshray/qak/tree/

For example, my simple implementation of min and max<T>(a, b) amount to just a few lines of code. But using them instead of std::min/max means you don't have to #include <algorithm> ... a savings of 39274 LoC!


It really depends on what compiler you use, in my experience g++ coupled with make is as fast as gcc for compilation.

clang++ is even faster.

Visual Studio 2010 has a decent compilation speed if you use a Dos prompt.


About the only thing I'd add to roel_v's excellent sugegstions (to which I cannot reply) is the use of ccache, distcc, and if you can use it, the gold linker. For larger projects, they make compile times bearable. In fact, I usually complain about time spent in linking, rather than compiling.


We use IncrediBuild.


And, for teams that use C++, there are different subsets of what they choose to apply.


For one of my current projects, I found myself in a similar position. I actually ended up picking Go instead of C++, since it's a language I've been wanting to learn for a while, and the feature set intrigues me. I have yet to see how this decision pans out though.


Well, I already had the VM implemented in Python, so I really wanted to do that in C or C++. Go was not an option because (1) one of the goals was to understand how other VMs are implemented, and most VMs today are C/C++, and (2) I wanted a language without garbage collection (which Go has, AFAIK)


Perhaps Vala would also be a viable language for this sort of thing.

I've been pondering writing a GC in Vala to learn more about them, and see how suitable Vala is to low-level work.


Bob language and VM already exists... :)

http://drdobbs.com/open-source/184409401


Is your code posted somewhere?


The 3rd and 4th words in the linked post point to Bob's Google Code page (http://code.google.com/p/bobscheme/) where its code is stored.

The code is wholly in the public domain, by the way - http://code.google.com/p/bobscheme/source/browse/COPYING





Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: