18

I really like the simple and transparent nature of C: when I write C code I feel unencumbered by "leaky abstractions" and can almost always make a shrewd guess as to the assembly I'm producing. I also like the simple, familiar syntax for C.

However, C doesn't have these simple, helpful doodads that C++ offers like classes, simplified non-cstring handling, etc. I know that it's all possible to implement in C using jump tables and the like, but that's a bit wordy at times, and not very type-safe for various reasons.

I'm not a fan of the over-emphasis on objects in C++, though, and I'm gun shy of the 'new' operator and the like. C++ seems to have just a few too many hiccups to, for instance, be used as a system programming language.

Does there exist a language that sits between C and C++ on the scale of widgets and doodads?

Disclaimer: I mean this as purely a factual question. I do not intend to anger you because I don't share your view that C{,++} is good enough to do whatever I'm planning.

7
  • 10
    You say that your question is "purely factual", but you are discounting c++ because it "seems" to have too many hiccups. What are these hiccups, and are they valid reasons to discount c++? Apr 1, 2012 at 5:49
  • 2
    What is the 'scale of widgets and doodads'? If you want real answers to a "purely factual" question you should avoid meaningless metrics.
    – Caleb
    Apr 1, 2012 at 7:05
  • 2
    And the few things you do state about C++ betray some misinformation. new is mostly a beefed-up malloc that can also take care of initializing the memory for you. With "placement new" and operator new, you can decide how and where it allocates memory. And as for object emphasis: A few lines above you state that you consider classes a "simple, helpful doodad". Make up your mind!
    – user7043
    Apr 1, 2012 at 7:10
  • 25
    Use C+ Diclaimer: Sorry, I couldnt resist. Its 1st of april ;)
    – knut
    Apr 1, 2012 at 10:10
  • 2
    This sounds an awful lot like the continuum hypothesis, and probably with the same answer. ( en.wikipedia.org/wiki/Continuum_hypothesis )
    – John Smith
    Apr 1, 2012 at 11:22

8 Answers 8

29

These might be the droids you're looking for...

Go - http://golang.org/

D - http://dlang.org/

Rust - http://rust-lang.org/

23
  • 5
    @dtech: D has that pointless GC/"Everything inherits from Object"/Values must suck crappery. I've already got C# for that and it actually has decent tools. Go, I admit that my memory of why I discarded it is somewhat hazy, but as I recall, it cut several very useful features.
    – DeadMG
    Apr 1, 2012 at 9:38
  • 4
    -1 for "what C++ should have been". C++ is what it is and if you can't handle it, that's largely your problem. You can deal with it by using a language that suits you better, but that doesn't mean C++ should have been like that language is.
    – back2dos
    Apr 1, 2012 at 12:49
  • 7
    @DeadMG On D, you made 2 meaningful statement : GC is mandatory and everything have to be an object. Both are wrong. It lead me to think that your conclusion is more based on ignorance than on actual knowledge. I have to agree with CodexArcanum.
    – deadalnix
    Apr 1, 2012 at 17:16
  • 5
    @deadalnix: Technically, you can choose to not use the GC. But since you have no way to know or control what library functions or language features use the GC, there's realistically no way to produce a program that doesn't use it. And you cannot create a class that does not inherit from Object. And their structs are seriously gimped compared to C++ values- no inheritance, no rvalue references, for example, so it is impossible to produce something as simple as a value string class in D that is as efficient as it's C++ equivalent. Those are facts about the D language.
    – DeadMG
    Apr 1, 2012 at 17:30
  • 5
    @DeadMG: Making structs with no inheritance is a feature, not a "gimping." It's something they got right, something that pretty much every OO language in history not named "C++" got right (including Simula, the original OO language,) and that C++ got incredibly wrong. Inheritance and value types do not mix. It breaks object identity, it breaks Liskov Substitution, it breaks the entire OO paradigm. Apr 1, 2012 at 18:14
19

There are quite a few languages (e.g., Java, Go, D, Objective-C) that are either roughly parallel to C++, or attempts at fixing problems that the authors saw with C++.

At least IMO, however, all of them work out substantially inferior to C++ for most practical purposes.

Unfortunately, based on your apparent taste for knowing what assembly code will be produced, we can probably rule out Objective C and Java immediately.

Theoretically, I'd consider Go the most interesting of these -- it has some truly original ideas and interesting approaches to solving problems that make some kinds of code much easier. Unfortunately, current compilers don't produce very good code, and there hasn't be a lot of improvement in that regard over the last few years.

That pretty much leaves D as the only one that stands a chance. It's probably the most similar to C++ (of these), but also the least likely (IMO) to fix what you seem to see as problems.

That leaves one obvious approach: use C++, but use only the parts you want, and avoid the parts you don't like.

19
  • 13
    +1 for "use C++ and avoid the parts you don't like". And I would suggest to the OP to learn more of C++, people often refuse things just because they don't know them well enough.
    – Doc Brown
    Apr 1, 2012 at 7:01
  • 1
    @DocBrown Maybe it's because it's not so easy to know C++ well enough.
    – Malcolm
    Apr 1, 2012 at 8:10
  • 3
    @Malcolm: it is of course hard to learn modern C++ in-depth. But on the other hand, there is absolutely no reason to be "gun shy of the new operator", that sounds just superstitious to me.
    – Doc Brown
    Apr 1, 2012 at 8:18
  • 3
    @Malcolm: Probably because the concept is very simple. Do I need a UTF-32 string literal, or a UTF-16 string literal? Well, that's a pretty easy question to answer, assuming that you know the basics of wtf string encodings are. And those multitude of hard features? They exist for a reason. For example, Java's generics. They are pathetic compared to templates. Sure, there's less to learn, but that's simply because they're just not very useful. It's like calling anything more complex than Brainfuck difficult.
    – DeadMG
    Apr 1, 2012 at 9:17
  • 3
    @Malcolm: That's not true at all. Popularity is influenced by 99999 things apart from whether or not the language is good/useful.
    – DeadMG
    Apr 1, 2012 at 9:57
16

However, C doesn't have these simple, helpful doodads that C++ offers like classes, simplified non-cstring handling, etc. I know that it's all possible to implement in C using jump tables and the like, but that's a bit wordy at times, and not very type-safe for various reasons.

I'm not a fan of the over-emphasis on objects in C++, though, and I'm gun shy of the 'new' operator and the like.

Sorry, buddy, contradiction alarm. Non-cstring handling requires new. It's a fundamental necessity. You cannot have std::string without new. And furthermore, new/delete is exactly equivalent to malloc/free but safer, because it guarantees correct construction and destruction of heap objects (totally necessary!) and uses exception handling instead of a NULL return, and is therefore superior in every fashion imaginable. In C++11 it is very possible to write your own new-style function, because perfect forwarding allows you to deal with any constructor of any type. If you are gun shy about new, then I suggest that you simply don't really know what you're dealing with.

Oh, yeah, and smart pointers make it so that you never, ever, have to actually deal with any of this yourself.

Furthermore, in C++ there is no over-emphasis. You don't have to use any object you don't want to. You can program functionally with lambdas and such any time you want to. Nobody is forcing you to use inheritance and virtual functions- in fact, many good C++ programs rarely exhibit inheritance. Templates are the more powerful and more useful abstraction technique. This is not Java.

8
  • 1
    I agree. It is much better to use C++ in the way you want to than to search for a (likely inferior) alternative
    – dtech
    Apr 1, 2012 at 9:37
  • 1
    I do not think that lambdas are enough to program functionally. I would also expect to have a function composition operator, currying, and so on. See also stackoverflow.com/questions/1981400/functional-programming-in-c. To me it feels like almost like doing OOP in C...
    – Giorgio
    Apr 1, 2012 at 11:10
  • @Giorgio: That question's answers just say "It's hard!". They don't show any evidence that it's actually difficult. Why would you want a separate operator for function composition? f(g(x)) seems to work just fine for me. And I also believe that currying can be done as a library generically in C++11.
    – DeadMG
    Apr 1, 2012 at 11:13
  • 1
    @DeadMG: A function composition operator is a quite well established, basic concept in functional programming. I would expect to find it in a language supporting FP. I find it very convenient (concise) to define a complex function as composition of other functions (e.g. like you do with pipes in Unix) without using variables: k = h . g . f
    – Giorgio
    Apr 1, 2012 at 11:20
  • 1
    @Giorgio: std::bind supports such things.
    – DeadMG
    Apr 1, 2012 at 12:32
5

C is almost a subset of C++, so you could just use those parts of C++ that you like and disregard the rest. It is even possible to write valid C that is also valid C++.

You won't be writing idiomatic C++, but that's about as "in-between" as it gets.

Alternatively, you could check out other languages that try to extend C towards something more powerful, most notably D and Objective-C.

And finally, depending on the nature of the project, you can go for a polyglot approach: divide your project into modules, and pick the most suitable language for each part. The downside of this is that you need to get the languages to work together, which may be too much work to be worth the effort.

1
  • Indeed, working in industries such as console game development, where we really wanted "a language in between C and C++", that's exactly what we did. We used a subset of C++ functionality, with certain things off-limits, or more likely off-limits within performance-critical loops. Apr 2, 2012 at 1:04
3

Just to offer a wild, out of the box answer: if the language you want doesn't exist, why not make one yourself? There are a variety of powerful language development tools out there, right down the old stand-bys of (F)Lex and Yacc/Bison. Since you already know C, you just need your "compiler" to output C code, which you then use your existing tool chain for.

This can be both simpler and more powerful than you think. Start with a parser/lexer for C, then add in the extra features that you think are important. If jump tables are annoying to write by hand, figure out a construct to express the abstract, and let your interpreter write them for you. Essentially this is just a higher-level of pre-processor metaprogramming, using outside tools to do the metaprogramming. You'll always know exactly what the final assembly is going to be like since you know the C, and you know what C your language extensions will expand into.

Obviously there are some limitations to how effective this can be without a lot of extra work. Adding a full static type system might be a tad more complex than you want to get into, but it's an option you could explore if you find you have a taste for it. Your DSL extensions are as powerful and complex as you have time and energy to make them, and who knows, maybe someday your extension language will become "the next C++".

2

You haven't said what C++ features are annoying for you. anyway you could try Objective-C. It emphasizes on Object Oriented instead of Standard Library on C++.

4
  • 2
    imho Objective-C is a meager attempt to introduce classes into C and inferior in many ways to C++. Furthermore it is very little used outside of Mac OS X / iOS.
    – dtech
    Apr 1, 2012 at 9:35
  • 1
    @dtech: Interesting, a former colleague of mine, who is not a Mac fan (rather a Debian / Linux guy) was convinced that Objective-C was a much cleaner OO extension of C than C++. I have never tried Objective-C though, so I do not have an opinion on this.
    – Giorgio
    Apr 1, 2012 at 11:02
  • 1
    @dtech: Then I humbly suggest you reconsider your opinion ;) Objective-C is about object orientation, and it does a far better job at that then C++, because it introduces message passing. While I agree that the language is inferior to C++ in many ways, it is just as much superior in other ways.
    – back2dos
    Apr 1, 2012 at 12:55
  • @Giorgio I agree with your collegue, though Obj-C has also some limits (maybe some of these are gone away with Obj-C 2.0), e.g. I would like to have overloading of "methods" (selectors) — btw I would like function overloading a la Fortran in C... Apr 1, 2012 at 12:56
2

The embedded world specified Embedded C++, which may be what youy are looking for. They removed things like multiple inheritance and such like. As far as I am aware, it's pretty much died out though.

0

You might find this in-depth side-by-side comparison of C++, Objective-C, Java and C# useful. Personally I think C# is a lot cleaner to work with than C++. I have ported several (numerical/calculations) C functions to C# before without too many changes being necessary due to the similarity of the syntax and numeric data types.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.