Hacker Newsnew | comments | show | ask | jobs | submit login

How is this different or superior to languages like Objective-C and C++ ? Both provide C like syntax and have similar features as the system described here.



1) Objective C certainly does not provide generic functions and I doubt that Objective C++ does (C++'s static overloading is something completely different, although it might look similar).

2) And this is different exactly in that it is not a complete language, but a library of CPP macros and some supporting infrastructure.

-----


C macros, surely.

-----


CPP is "C PreProcessor", so your "C macros" are simply some subset of uses of "CPP macros". CPP can be (ab)used to preprocess other things than C source.

-----


slaps forehead

I blame my confusion on the .cpp extensions!

-----


and this confusion is exactly why I tend to use .cxx for C++ sources

-----


CPP is the C Preprocessor, not to be confused with C++.

-----


This compiles with a standard C compiler, so it's more appropriate to compare to something like GLib. Cos has faster single dispatch than Objective-C and has extensible multiple dispatch with significantly better performance than C++ (as implemented using Visitor, which is only extensible in one argument).

-----


So ok, I just peeked at the paper and it seems great, but the disadvantage of being in C is that you end up with a lot of macros (like e.g. `defclass`): what with debugging?

-----


This is a very good point and is the fatal flaw of most metaprogramming. It does seem easy to generate quite confusing error messages by making minor typos. Clang does a much better job with macro expansion errors than gcc, but it's still not great. As for actually using debuggers, it looks like you're on your own to understand the implementation enough to be useful. I don't know if it would be feasible to write a gdb plugin to improve the experience.

OTOH, Cos offers more compile-time type safety than GLib, so you might hope that you'd need to spend less time in the debugger.

-----


The C preprocessor would emit #line <number> to preserver the original line numbers, this way the debugger won't get problems understanding it. This off course if the macro does not expand multiple-lines (if it does, you'll just skip all over that).

-----


> Objective-C

As a friend of mine likes to put it - "Objective-C is C raped by Smalltalk without proper understanding of the language anatomy". Not exactly accurate, but fairly close still :)

-----




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact

Search: