views:

1025

answers:

14

Greetings All,

I'm looking for an OO language that support pointers and (if possible) GC. Though it would be nice NOT to enforce GC and allow for override/customize it.

I'm open to both VM and binary executable languages.

I'm looking for a consistent and proactively developed/supported OO language to do development with. Maybe I am not comfortable with the historical back-compatibility of the C++ standards as well as the different standard libraries. In simple words I need a cleaner language.

Any thoughts ?

+9  A: 

Only if you are not developing for Embedded devices (thanks for the good comments hereunder)

Here is a quite old but best comparative overview of C# / Java / C++ that I could find. Nowadays with Generics, LINQ and Parallel computing support there are even more points that should be treated inside such a paper. Maybe someone has a more up-to-date reference?

The C# language and .NET environment provide all control that you will need. It is highly customizable for special cases and bindings to other languages exist as well. C#/.NET provides you all the things you expect from a modern language and environment.

  • You are platform independent (x86 or 64 bit systems) or even Linux with Mono (WITHOUT recompiling) if you take care not to call native code (use .NET).
  • C# is easy to learn if you come from the C++ world
  • GC: with using and IDisposable and finalizers, you will have control over it.
  • Use of pointers possible in so-called unsafe contexts to get the rest of flexibility and performance you might want to have
  • if you really want or need it you can create a native binary from a .NET assembly with ngen.exe
  • Clean semantics for inheritance (abstract/virtual, override, sealed)
  • Supports lambda expressions and LINQ
  • Reflexion (you can "see" and "analyze" the objects you get even without knowing their types in advance)
  • Easy XML parsing handling with XML attributes
  • Easy binding of COM components (just reference them, Interoperability DLLs are created on the fly)
  • Integration of native code or migration from C++ eased thanks to DllImport attributes.

And many more. Definitively worth to learn, you won't regret it.

jdehaan
C# has matured a lot since version 1 so it's definitely a great programming language. Especially the Linq addition was a big step forward.
XIII
`C++ is rather weak` funny :D ... C# is weak, you can do much more and much better with C++, however `C++ is rather difficult`.
Matthieu M.
If you tell me how you can do reflexion or LINQ-like queries easily with C++ (even `boost`'ed), then I maybe agree. I do not see anything you could do with C++ and not with C#/.NET
jdehaan
Writing a cross platform solution for embedded devices and different architectures.
Chaoz
@Chaoz, good point (+1). For WinCE platforms there is upcoming Motegi (where C#/.NET is rather poorly integrated at the moment), for Linux at the moment no real .NET movement.
jdehaan
-1 for `C++ is rather weak`. That's just flat wrong. The reasons you mention just show you don't understand C++.
Gianni
jdehaan
@jdehaan: I worked with C# for two years and then jumped back to C++. For all its faults C++ is just way more powerful language than C#. To each his own, I guess.
Nemanja Trifunovic
but.... Have C# pointers?!The OP asked for them, and AFAIK C# has not pointer as C/C++/Objective-C (..and D as read in another answer)
ShinTakezou
*"In comparison to C++, C++ is rather weak."* - Euh, what? C++ is weaker than itself? ;)
Georg Fritzsche
@Georg: Is there no end to the things that C++ can do?
Donal Fellows
Ouch ouch, ok, I removed the too controversal and subjective sentence :-). @ShinTakezou, you can use pointers in C# in `unsafe` contexts: http://msdn.microsoft.com/en-us/library/chfa2zb8.aspx
jdehaan
@jdehaan thx, didn't know it
ShinTakezou
c++ is weak... slow compilation kills me, no reflexion, no introspection, horrible serialization, horrible unit testing frameworks
Kugel
Maybe to find a consens, C++ is not such a bad weapon but in inexperienced hands it has not enough security mechanisms to make it a safe weapon. D adds a bunch of safeties. Too many things are there that shots in oneself's foot are frequent things. C# has many features that must be explicitly unlocked to be used, what increases its safety. OK all developers on a project should be sufficiently experienced, but hand on heart in real-life situations are you sure that it is always the case?
jdehaan
Aside from a Turing-equivalent template language and deterministic finalization, is there really anything else that makes C++ better?
Gabe
+1  A: 

How about Scala?

Andrew McGregor
You can't really avoid the GC, you don't have any pointers and the java ecosystem is entirely different from the C++ world.
tstenner
+5  A: 

Maybe Objective-C?

Polybos
+12  A: 

Google released the Go language with the goal of combining the speed of C++ and the convenience of Python.

http://golang.org

Mtgred
However `Go` is still experimental and slowish (they readily admit they need to work on their garbage collection scheme).
Matthieu M.
But it is actively developed by a renown group of developers (Google). That is a pretty big plus!
Blindy
@Blindy: Google has abandoned quite a few promising products halfway through. Just because Google is working on something doesn't mean they're going to keep working on it, or that they'll actually turn it into something useful or successful.
jalf
I'm personally having a hard time getting past the syntax - aesthetically, it's hard to like. On paper, the language looks very good, though.
greyfade
@Matthieu M: So basically the reality today is that Go combines the convenience of C++ with the speed of Python ?
MSalters
@MSalters: it's faster than Python from the benchmarks I've seen, because it's compiled and not interpreted. But the original goal of being as fast as C++ has not been reached yet.
Matthieu M.
+34  A: 

The D Programming language:

You didn't ask, but D also has compile-time templates, built-in functionality for unit tests, and excellent support for conditional compilation.

A couple caveats with D are that you have to decide between v1 and v2 and between Phobos and Tango. Version 1 is stable (meaning no new features are being added), while Version 2 is still in development. Phobos is a bare-minimum standard library, whereas Tango is (in my opinion) rather like Python's "batteries included" do-it-all library, but Tango is currently only available for v1, at least until v2 stabilizes.

Mark Rushakoff
And you have to wait for a stable and complete implementation of v2... (but+1 it answers right the question)
Klaim
But how should one decide between these versions without knowing the language? And how should one know the language when he doesn't know with which version he should begin? Catch-D. ;-)
stesch
@stesch: It's the internet. You aren't on your own, read what people have already said about the decisions.
Mark Rushakoff
@Mark Rushakoff: That's OK if you are new to the Internet. I've wasted much time because I listened what people on the net said.
stesch
@stesch: "But how should one decide" Try both, pick the one you like more.
SigTerm
@stesch: And still you are participating here... :)
Georg Fritzsche
Didn't D enforce GC? It seems that he asked for something that didn't enforce the use of GC. IIRC, there where couple of features that simply weren't devised to work without the GC.
Juliano
How does D interface with C or c++ libraries?
Kugel
+10  A: 

You might consider looking at the Boehm Garbage Collector for C++, if you're not quite ready to part with C++ entirely.

Drew Hall
+3  A: 

Although it's still in development and might change a little bit, OOC is a great new language. It definitely is usable right now:

  • OO language - check (although classes are pretty much open by default)
  • support pointers - check (you can create "covers" that map to native C structures and link to all standard libraries)
  • and (if possible) GC - check
  • NOT to enforce GC and allow for override/customize it - check - the class allocator can be overloaded (per-class)

  • I'm open to both VM and binary executable languages. - it compiles to binary

  • consistent - in itself it is, although it is still developed, so new constructions might appear

  • proactively developed/supported OO language - definitely; the team is very active
  • In simple words I need a cleaner language. - for me, OOC is what C++ should've been ;)

Downsides:

  • small community (although not non-existant)
  • some bugs still exist - it's a fairly new language after all

Other nice things:

  • supports closures and generics :)
viraptor
+2  A: 

Your requirement appears artificial. Languages that do not have pointers doesn't need them because the semantics of the language doesn't need them; typically these languages have a much more expressive semantics that pointer becomes unnecessary.

Most languages that have automatic GC have a way to turn them off, I'm not aware of any languages that actually forces you to use GC and doesn't allow you to turn it off.

So, perhaps it's better if you describe your requirement a little bit more concretely. If you need a fast language, then you would definitely want a compiled language with a good optimizing compiler. If you need a language with close-to-the-metal semantic, then C/C++ would be the perfect language before deciding to use assembly.

If you want platform independence, then currently you have to use a either Virtual Machine based language (i.e. bytecode interpreted language) or fully interpreted language.

Here's a the three classifications I often used to differentiate languages:

  • Assembly: bare-metal semantics, highly platform dependent; it is practically impossible to write platform independent assembly.
  • C/C++: near-metal semantics, can be platform independent with some care. Typically compiled languages.
  • JVM/.NET/Python/Perl: expressive languages, is easily platform independent; it is impossible to write hardware drivers in these languages. Typically VM-based or interpreted langauges.

EDIT: since I was challenged, ok:

disabling GC in :

  1. Python:

    import gc
    gc.disable()
    
  2. Ruby:

    GC.disable
    
  3. Java, Scala, Clojure all runs on JVM, and therefore share the same trick: use Immortal Memory (which is basically a Malloc)

  4. Like Python, Perl does not have a Garbage Collector; both Python and Perl uses Reference Counting and do not strictly need a Garbage Collector.

  5. I'm not bothered to look at the rest. They're not languages that I'm concerned about.

Reference Counting is a garbage management mechanism; Garbage Collector is a garbage management mechanism; Malloc is a garbage management mechanism [or rather, a manual garbage management]. However, neither Reference Counting nor Malloc is a Garbage Collector; unlike a Garbage Collector, Reference Counting and Malloc comes practically for free (no stop-the-world, no heap size to manage, etc) and there is no reason to disable them (why would you want to disable malloc? probably only for bondage programming).

Lie Ryan
Can you tell me how to turn off the garbage collection in Java? In Haskell? In Erlang? Scala? Ruby? Python? Lua? Clojure? Common Lisp? Scheme? Perl? You're going to have to beef up your knowledge of programming languages and implementation before you start making bald statements like "I'm not aware of any languages that actually forces you to use GC and doesn't allow you to turn it off". I mean you *named* some!
JUST MY correct OPINION
@JUST YOUR OPINION , I am too lazy to do a deep search for every lang you cited... but e.g. http://docs.python.org/library/gc.html does not mean in Python I can disable GC, or is my english understanding that bad?!
ShinTakezou
Huh. I stand corrected on Python. And now that I look at it more closely, on Ruby too.Still can't turn it off on Java, Haskell, Erlang, etc. though.
JUST MY correct OPINION
But, well, you know that if you disable GC in python, it is not possible to free memory at all? Disabling GC is dynamic languages is not equivalent to have GC optionally for some objects.
liori
@liori: No, python primarily uses reference counting, gc is only strictly necessary to releases memory for objects with circular reference. If you know your program has no circular reference, it is generally quite safe to disable gc in python without getting memory leaks.
Lie Ryan
Reference counting is certainly not free! Every time you copy a reference or delete one, extra work has to be done. Malloc isn't free because the heap has to be walked on every malloc and/or free. And don't even get me started on heap fragmentation...
Gabe
Reference Counting is much cheaper than GC; for every referencing or dereferencing, you only pay an integer increment/decrement and conditional jump if the refcount reaches zero (two very cheap instructions). In total, it's amortized O(1) and you don't experience a stop-the-world symptom. I'd consider that practically free.
Lie Ryan
Lie: Storing the ref count requires an additional 4 bytes (or 8 depending on your alignment requirements) for *each* allocation, which even if your memory is free, still increases your working set (and page faults are *not* free). Furthermore, multiple threads make the increment instructions much less cheap, possibly causing false sharing that can seriously hurt the scalability of an app. And even you realize that the possibility of circular references means you still have to stop the world for GC.
Gabe
@Gabe: If you design your program carefully such that you don't create circular refs or break any circular refs manually, you won't need gc at all (though for most purposes, leaving GC on doesn't harm as much, there is much less garbage to be collected by the gc in a refcount-gc hybrid mechanism). Yes, refcount has problems with circular references, but IMO when no circular refereces is concerned, refcounting is much superior compared to GC. Furthermore, in Python, the GIL makes refcount lock unnecessary so there is no problem with multiple threads.
Lie Ryan
Lie: You haven't exactly created a glowing endorsement of Python. My biggest problems with Python are lack of multiprocess scalability and memory fragmentation. Having a proper copy collector GC would eliminate fragmentation and avoid part of the need for the GIL, making Python usable for my server.
Gabe
A: 

Java:

  • similar syntax
  • garbage collector
  • really cross-platform
  • efficient (with the Just in time compiler)
  • you can forget pointers

    • eclipse with many interesting plugin. if you are student, you can write your own one.
LonliLokli
Does not match requirements stated: no pointers.
JUST MY correct OPINION
Java references are pointers- they can even be null. In what exact way is a Java reference NOT a pointer?
DeadMG
I know, that all variables of user defined classes (and Integer, ...), but if you coding in java, you don't need to have all background knowledge about the platform (for example what happens, if you make cast by multiple inheritance, in this case the value of the pointer can change). It doen't matter for the user(if you foget side effects), that variables are c++-pointers.If you don't want to have side effects, than chose haskell (of course it is only my opinion).
LonliLokli
@DeadMG: you can't increment a reference. You can't create references to arbitrary memory addresses (it's implementation-defined in C++, but it's not impossible). Java references are not pointers, but they do overlap quite a bit.
jalf
@Jalf: Maybe you can't increment a reference, but it was a bad idea in C++ to do that instead of using an iterator. And, what possible benefit could pointing to arbitrary memory addresses bring? Perhaps I should rephrase. Java references are pointers for the vast, vast majority of sane uses of them, and aren't disqualified just because you can't shit all over your application with them.
DeadMG
@DeadMG: What benefit? Interfacing with memory-mapped hardware, for example. And as for incrementing, that is what allows pointers to be *used* as iterators. Can you use a Java reference as an iterator?You are right, for *most* everyday purposes, a Java reference can replace a pointer just fine. But the OP specifically asked for a language with pointers, and I'm just giving you examples of why that might be: there **are** legitimate use cases for pointers that can't be achieved with Java references.
jalf
+12  A: 

Objective-C seems to be the only widely used language that supports your requirements: low-level (pointers, etc.), OO, optional GC.

On the flip side, it is hardly "clean" being source level compatible with C and is pretty much used only on Apple platforms. Also, it is way dynamic for my taste, but some people actually like it.

Nemanja Trifunovic
Note: Objective-C has GC from v2.0, otherwise only through framework (GNUstep, Cocoa...); but I wonder, since Obj-C is a "strict superset" of C (copy-pasted from other questions/answers) and no-one prohibits me to use malloc... can I say in this case Objective-C has a "wide" GC mechanisms? (i.e. that embraces all the way one can allocate memory)? Same for e.g. C++, I know, if you use malloc;so you won't use it... but in C++ you have e.g. __new__;in Obj-C 2.0? (This is a real Q, I have not explored Obj-C 2.0 since my current compiler is not Obj-C 2.0 compliant)
ShinTakezou
@Shin: GC doesn't automatically apply to C-style allocations.
Georg Fritzsche
@Geog Fritzsche thanks, but my Q was about the "alternative" in Obj-C 2.0 that allows to be GCollected; in C++ I can imagine the GC "sits" on __new__ but in Obj-C 2.0? Which is the GCed way of allocating memory?
ShinTakezou
@Shin: That would fit better as a new question than discussing that on this answer.
Georg Fritzsche
likely:) but it seemed a fast "inlined" question in a comment about noting that however Obj-C < 2.0 has no GC ... on the other hand an answer to such a question could point directly to Obj-C 2.0 specs, so that outside the context of a feed-fastly-my-couriosity question in a comment, it currently seems to me exagerated to create a question on the topic.
ShinTakezou
+3  A: 

Modula-3 is still around and supports what you ask for. It doesn't support multiple inheritance, mind, but it supports objects, generics, garbage collection (which you can turn off), pointers (both in safe and unsafe modes) and all sorts of other goodies.

That being said, the language isn't quite dead, but it's definitely coughing up blood.

JUST MY correct OPINION
+2  A: 

This is a really tricky question, and as its a personal thing I propose the following list of possibilities (grouped by how they are pecieved):

Go or Scala

Ruby or Python

C# or Obj-C

All these languages are very different, and are applicible to different areas, you wouldn't catch me dead writing a web-app in Obj-C or an enterprise accounting ap in Go etc...

thomasfedb
Of those Scala, Ruby, Python and C# do not match the requirement of supporting pointers.
JUST MY correct OPINION
In ruby everything is a reference, so it supports it...
thomasfedb
@thomasfdb pointers are not just "references", at least in C, and thinking of how the term "reference" is used often for many languages. I am almost sure Ruby, Python and C# has _no_ pointers the way a C programmer "wants"
ShinTakezou
I'v only dipped my toes into C based languages and I only even used pointers to prevent the copying of a lot of data or to pass an array. Sorry if I am overlooking the point! (pun)
thomasfedb
You can use pointers likes references, but they can also point to arbitrary memory locations, e.g. into the middle of some object. References instead always alias one object.
Georg Fritzsche
@Georg: Pointers also always point to one object (if they point to any valid object at all), but their main advantage is as slices/views of an array (which *only* applies to "real" contiguous arrays). However, every language in this list has (often superior) equivalents to that iteration behavior, even C++ itself with generalized iterator semantics.
Roger Pate
@Shin: I suspect it's merely because of lack of experience that the OP is asking for pointers specifically instead of using, for example, Python's variables/attributes, which act like pointers in most respects.
Roger Pate
Gabe
@Roger: Pointers don't have to point to the beginning of one physical object, see e.g. `char`-based serialization of arbitrary POD-types.
Georg Fritzsche
@Georg: All char pointers point to specific char objects (if they point to anything valid at all). It's a property of POD types that you can use those objects as arrays of chars, rather than being a special ability of pointers.
Roger Pate
+3  A: 

No language offers the power of C++'s templates, as far as I know. If you want bog-standard object-orientation, Java/C# can work for you. But.. I could never leave C++ for a language that didn't offer templates.

DeadMG
what do templates give you, beside extreme compilation times and duck typing?
Kugel
In my opinion, templates and their bastard stepchild in .NET, generics, are a failure of the language and compiler itself to do what programmers need.Yes, they're very powerful, but they're certainly not necessary in most projects.What are you doing that requires templates so much?
Jordan
Are you blind? Every C++ project ever made uses templates in the STL. It's true that if you develop a raw application, you might not make heavy use of them. But if you're developing or using a library (for example, that provided with the language) they're invaluable. The massive array of data structures and other things available for C++ all depends on templates to make them usable in your code. The alternative to fast, inlined, safe templates is int size; void* data; or the catch-all System.Object.
DeadMG
When you find someone that feels like a superhero simply because found a way to make a "loop" or an "if", then you know for sure that something is dead wrong.C++ metaprogramming is really not much different that walking on your hands... it may be funny and it may even look as an achievement. But for going around is not such a clever walking method.
6502
@6502: Depends on if your legs are permanently disabled, which is what it's like going to languages without templates.
DeadMG
@DeadMG: C++ templates are very useful in C++. However, that doesn't mean they're good. C++'s approach is overweight and produces inefficient code at compile time with blind copy/paste strategy. It looks like you're using it for type abstraction, which is fine and that's really the only way to handle it in a language like C++, but other languages like ML and Lisp dialects have it almost built-in, and of course newer dynamic languages like Python and Ruby can handle it near-natively with interfaces and type overloading.
Jordan
...So yes, templates are very powerful in C++, but that's because the language itself is broken, IMO. There are obvious tradeoffs related to performance, but I'm betting on someone fixing performance in the future, whereas template implementations are ingrained.
Jordan
@Jordan: Dynamic languages like Python and Ruby don't even come close to vaguely fulfilling the same purpose as a static language like C++. And, I'm not wholly sure where you get the copy and paste thing, because the whole point of templates is that you don't copy and paste things. Even if you did need copy and paste, I'd just pull out the Boost preprocessor library. Templates are incredibly flexible and produce very fast code, with little input on the part of the end user. What more could you possibly want out of a system?
DeadMG
Right, the programmer doesn't have to copy and paste. Under the hood, the compiler is guessing at what you're trying to do, and often produces essentially compiled copy and paste. Templates are great if you're basically using them as type abstraction/duck typing, and don't have a lot going. But again, they're solving a problem that doesn't exist in other languages and systems. My question is: why do we have to think about templates in the first place? I think the language and compiler should be able to handle that internally. P.S. yes I know the technical reason "why", it's a thought exercise.
Jordan
@Jordan: Right. So now, your argument about templates has changed to the compiler. I trust the compiler to do a billion other things intelligently, and optimizing template code is something that they have proved very good at when you actually look at the performance- std::sort vs qsort, for example. They solve a problem that exists in all other similar (static type, compiled) languages. We use templates because the results are goddamn fast and they're easy to use, if not develop, shortening development times and producing good code.
DeadMG
If you trust the compiler building your C++ app to do a billion other things more intelligently, you have much more faith than I do. What I apparently don't seem to be expressing clearly enough is that a) yes, the problem exists in all other similar (static type, compiled) languages, and b) maybe these languages should die a horrible death so we can move on to better programming practices. To your final points, they are not easy to use if you're doing more than basic type abstraction. Development times are faster in languages that don't require templates at all.
Jordan
@Jordan: Sure, they are faster development. They also produce buggier and hideously slow code. If you get the native Lua implementation, it will add a pair of numbers a whopping 25 times slower than C++ or C. Can you imagine waiting 25 times longer for applications to start or run? What the hell kind of games could you play with 25 times less FPS? Dynamic languages have uses- replacing static languages ain't one of them, because they're still unusably slow for the vast majority of applications.
DeadMG
+1  A: 
Norman Ramsey
Don't forget [`UNTRACED`](http://www.opencm3.net/doc/reference/complete/html/2_2_7References.html) for shutting off the garbage collection at incredibly fine-grained levels.
JUST MY correct OPINION