News for hackers. Stuff that matters.
Re:Lambda-style anonymous functions for C++ in less than 500... by confuzatron on Tuesday April 13, 2010 @10:38AM (#1262103)
Less than 500 lines of code. More than 500 lines of compiler errors if you get a character wrong somewhere. ;)
Re:Lambda-style anonymous functions for C++ in less than 500... by dirtyaura on Tuesday April 13, 2010 @11:41AM (#1262313)
Yes. However, in my experience, on a small team, benefits of readable code by using templates to implement DSLs in C++ still outweighs burden of prosaic error messages. You quite quickly learn to pattern match error messages to find the real problem.

We might be bitten this later when new guys and gals join the team. Code is very readable for being C++, but newbies might have hard first few weeks with these error messages.

Re:Lambda-style anonymous functions for C++ in less than 500... by sreque on Tuesday April 13, 2010 @02:53PM (#1262982)
If you've ever tried starting a debugger in a program that uses the Boost Lambda library you might disagree. My program was only a few hundred lines long, a toy, but I for the first time had to turn pagination on in gdb to view my program's stacktrace because the it filled two entire screens! Even worse, compile times on my program were ridiculously high and I was wasting a ton of my time in long compile-run feedback cycles. Eventually I threw my hands up in disgust and started hand-rolling my own structs. Compile times dropped to under a second and I was able to easily spot my mistakes in the debugger.

What was I doing? I was just writing a simple program to try to understand Boost's spirit parser, somewhat of a monstrosity in its own right, and thought I'd use the lambda library along with it. While we're on the subject of crazy DSL's in C++ templates, I ended up concluding that Flex together with Bison or Lemon are much more pleasant to use than Spirit if you don't need a full recursive descent parser.

Using C++ templates to implement crazy meta-languages might seem like a cool idea, and it is, but in practice I've found it to mostly be a waste of time and very unproductive.

Re:Lambda-style anonymous functions for C++ in less than 500... by dirtyaura on Tuesday April 13, 2010 @03:57PM (#1263168)
We have noticed that debugger is not a very good debugging tool for our apps: interactive games with lots of events, animation, multiple threads etc. Stepping through in debugger has turned out to be waste of time.

What has worked? It's much better to produce detailed logs of some of the subsystems and analyze them. This way you get much better understanding of the big picture of what is happening. Why? In UI code (or event-driven code in general) state changes that cause bugs happen over time, not inside one step of an event loop. You just can't get the big picture of event-driven code with a debugger, which is optimized for going up and down callstack.

We have build a custom tracing library (and yes, it uses a lot of MACROs) that allows us to do select what is traced in a very granular level. I can proudly say that it's wonderful tool, every UI platform should ship with something like that.

By the way, tracing is also better for debugging parsers, their behavior often have similarities to event-driven systems

But you are right about compile times. Those get worse with templates.

Re:Lambda-style anonymous functions for C++ in less than 500... by loup-vaillant on Tuesday April 13, 2010 @04:55PM (#1263330)
All this can be traces back to a root problem: using, maybe even needing, C++. Solution: don't use C++, or run away. (And spread the word[1]) I am dead serious: I don't follow my own advice, and that makes me miserable at work.

[1]: http://yosefk.com/c++fqa/ (I actually learned quite a few things there)

Re:Lambda-style anonymous functions for C++ in less than 500... by _delirium on Tuesday April 13, 2010 @05:12PM (#1263378)
I second the recommendation of Yosef K's FQA. It's not just an anti-C++ rant, but a pretty detailed explanation of a lot of C++'s features, interactions between features, and corner cases (and how those will bite you in the ass).
Re:Lambda-style anonymous functions for C++ in less than 500... by bad_user on Tuesday April 13, 2010 @04:28PM (#1263267)
Btw, I've had great experiences with Antlr (instead of Yacc) and can use Java/C/C# as targets, although you might have problems redesigning your grammars to be LL(*).
Re:Lambda-style anonymous functions for C++ in less than 500... by confuzatron on Tuesday April 13, 2010 @12:16PM (#1262440)
Yeah, really it's a more general problem with the extreme expressiveness of C++ meaning that the compiler is less able to give a helpful error message than in other languages I've used. It seems that you can do anything in C++, but step out of line and you'll have trouble deciphering where you went wrong.
Re:Lambda-style anonymous functions for C++ in less than 500... by eru on Tuesday April 13, 2010 @07:29PM (#1263681)
> extreme expressiveness of C++

You probably mean that the boundary between meaningful C++ programs and typos is not very well defined?

Re:Lambda-style anonymous functions for C++ in less than 500... by confuzatron on Tuesday April 13, 2010 @07:36PM (#1263694)
Exactly. Very well put.
Re:Lambda-style anonymous functions for C++ in less than 500... by wheels on Tuesday April 13, 2010 @12:26PM (#1262476)
Nah, it's actually more of a GCC problem than a C++ problem. Intel's compiler produces surprisingly sane error messages.
Re:Lambda-style anonymous functions for C++ in less than 500... by zokier on Tuesday April 13, 2010 @01:45PM (#1262759)
llvm/clang is supposed to have nice error messages
Re:Lambda-style anonymous functions for C++ in less than 500... by confuzatron on Tuesday April 13, 2010 @12:48PM (#1262551)
I can confirm it is also an MSVC problem.
Re:Lambda-style anonymous functions for C++ in less than 500... by growingconcern on Tuesday April 13, 2010 @12:29PM (#1262490)
It's not that hard parsing template compiler errors (though I am looking forward to better errors in C++0x). Are you saying this is a good reason not to use templates at all? With a little practice they start to make sense. I'm sure for novice programmers the first time they see 500+ error messages stemming from a missed semi colon or curly brace (in regular code) it can be pretty bewildering too, but just like with template error messages you just ignore virtually all of it.