views:

460

answers:

9

The main reason to use C++ over a managed language these days is to gain the benefits C++ brings to the table. One of the pillars of C++ is "you don't pay for what you don't need". It can be argued though that sometimes you don't want to pay for backward compatibility with C. Many of the odd quirks of C++ can be attributed to this backward compatibility. What other languages are there where "you don't pay for what you don't need" including backward compatibility with C?

Edit/clarification: The real killer for me is in that second sentence. Is there a language truly designed from the ground up that doesn't impose things you don't want on your code? C++ has that as its design philosophy: don't want RTTI? It doesn't exist. Don't want garbage collection? It's not there. The problem with C++ is it (IMO) violates this requirement when it refuses to break from the past. I don't want the cruft of backward compatibility with 20 year old code hampering my going forward. C++ isn't willing to do that. What is/has?

Edit2: I suppose I should have been more clear about what a cost is. There are multiple potential costs. The one I was initially focusing on was runtime cost.

In C++ polymorphism through virtual methods has a cost. But not all methods pay that cost. A non-virtual C++ method is called with the same runtime cost as a plain old C function (having at least one parameter). C++ does not require you to use polymorphism. In other OOP languages all methods are virtual and so the cost of polymorphism cannot be avoided.

Runtime costs are most important but other costs mitigate against that. Assembly language would have the least runtime overhead obviously but the writing and maintenance costs of assembly language are a huge strike against it.

With that in mind the idea is to find languages that provide useful abstractions which, when not in use, do not affect runtime costs.

+21  A: 

D language

D is a general purpose systems and applications programming language. It is a higher level language than C++, but retains the ability to write high performance code and interface directly with the operating system API's and with hardware. D is well suited to writing medium to large scale million line programs with teams of developers. D is easy to learn, provides many capabilities to aid the programmer, and is well suited to aggressive compiler optimization technology.

The general look of D is like C and C++. This makes it easier to learn and port code to D. Transitioning from C/C++ to D should feel natural. The programmer will not have to learn an entirely new way of doing things.

D drops C source code compatibility. Extensions to C that maintain source compatibility have already been done (C++ and ObjectiveC). Further work in this area is hampered by so much legacy code it is unlikely that significant improvements can be made.

Igor Krivokon
I know about D. I was wondering if there were anything else. I'm not sure it meets my "don't pay for what you don't use" requirement. But the most "don't pay for what you don't use" language would be assembly and that's not really better than C++.
jmucchiello
Are you saying assembly and C++ are of equal level of complexity?
GMan
@jmucchiello - well, you're looking not just for a language, that "Doesn't Impose Things", but for a better-than-C++ "D.I.T." language. The question is difficult to answer, because it pretty much depends on your definition of "better". Another definitely "D.I.T." language is Forth. But I will leave the question of "better" to you :)
Igor Krivokon
@Igor: There doesn't have to be a right answer. I've been meaning to delve deeper into D. @GMan: And now, assembly and C++ are not equal in complexity. I was saying assembly imposes the least (actually no) on what you can and cannot do.
jmucchiello
+1  A: 

You can also try Ch from : http://www.softintegration.com/

auvi
Ch is basically a subset of C++ meant for scripting. I don't see this answering the OP's question.
Matthew Flaschen
From the site: Ch is C plus (Ch = C+). Ch is a C interpreter. Ch is C with classes and high-level extensions. Ch is a superset of C. Note that C++ is no longer a superset of C. For example, VLA and IEEE floating-point arithmetic in C are not supported in C++. C is for low-level system programming and embedded systems; C++ for large-scale projects. Ch is optimal for platform-independent scripting in numerical computing and visualization, rapid application development, Web programming and plotting, embedded scripting, shell programming, integration with legacy systems, and learning C/C++.
auvi
A: 

Try Aikido. Syntactically similar to C++, and I don't think it inherits C style backward compatibility.

Aikido @ Wikipedia

Suvesh Pratapa
But it's interpreted, and I think it has garbage collection built-in. Which doesn't really fit what he wants in his question.
Nosredna
OK, just suggested it as another option!
Suvesh Pratapa
+4  A: 

I'm tempted to downvote this question (but as of yet I have not). Your requirement that "you don't pay for what you don't use" depends very heavily on what exactly you use. You already mentioned in one of your comments that assembly is perhaps the most fluff-free language there is, but you complain about C, which sits somewhere between assembly and C++.

If you find garbage collection and explicit object-oriented features "fluff" then frankly, I think C is probably the best candidate. The language is actually small and elegantly designed. It meets most people's "fits in one's head" requirement. For a language that gives such close control over the hardware, it's very expressive.

If you are not tied to the hardware, then Scheme or some other minimalist dialect of Lisp probably fits the bill for "doesn't impose what you don't want on your code" but again, it all depends so heavily on what exactly it is that you don't want.

If there are some higher-level features you "can't live without" (which it seems you are implying by naming "C++ without C compatibility" as your language of choice) then you should say explicitly what those are. What exactly is C++ bringing to the table that you don't want to sacrifice?

John Y
Actually C is certainly a language that imposes little on the programmer. The question is can you add more language features and still maintain that minimalism. For example, adding duck-typing imposes an overhead. If a language (somehow) allows you to use duck-type or lets you turn off duck-typing then it meets my criteria for paying for only what you use. The point isn't what "can't I live without". It's what can I gain when I need it and throw out when I don't.
jmucchiello
+1  A: 

SPECS is alternative syntactic binding for C++. This binding includes a simple syntax for declaring and defining types, functions, objects and templates, and changes several problematic operators and control structures. The resulting syntax is LALR(1) parsable.

Jim Huang
+1 That is awesome! It doesn't really answer the question, but that is so cool...
Zifre
+1  A: 

Eiffel. Looks like Pascal, has C++ type semantics. Also, adds special "programming by contract" assertions that are built into the language definigion, years before people were talking about "X"Unit libraries.

Roboprog
I haven't looked at Eiffel in a while. Are there language features that add overhead that I can turn off when I don't need the features? That is the essence of my question. Can I write my own memory management? If I create a hierarchy with no exceptions will there still be exception handling code in my runtime?
jmucchiello
I wish I could answer your questions. It's been years since I looked at this as well, in the context of learning more about using C++ and Borland ObjectPascal. I don't think you can disable the exception handling. You *can* disable the precondition and postcondition checks.
Roboprog
+4  A: 

Ada is another alternative - gc is optional in the implementation of the language:

http://en.wikipedia.org/wiki/Ada_(programming_language)

David Cournapeau
Too much Verbose.
Hai
A: 

I'm not exactly sure what costs backward compatibility with C has...

Brian Postow
Roboprog
A: 

I'm not exactly sure there are any runtime hits associated with C backwards compatibility, could you elaborate? Certainly the backwards compatibility does give you more rope to hang yourself with but strict enforcement of rules can mitigate that. So I suppose my answer to you is C++ is the language that does what you ask for and you just need a tool to enforce valid constructs.

Edit: odd that i didn't notice the post directly below me with the same first line comment

Hippiehunter
Backwards compatibility with C is on the maintenance side of costs. I never said C++ didn't fulfill the purpose. I'm just wondering if there are alternatives. Why aren't there more languages with the "don't pay for what you don't use" mantra?
jmucchiello