C++ Alternatives
I wanted to to a few projects that need a compiled object-oriented language, so I tried C++ and can't say I like it. C is great but it is not OO. So I was windering if there is some other compiled language that is OO, has a free/open source compiler for Linux, and is preferably backward-compatible with C?
|
Quote:
What didn't you like about C++? Lots of people dislike C++ because of features that are similar to C. But you said "C is great". Lots of people, who like C, dislike C++ because it was their first introduction to OO and they don't actually like OO. But you think you want OO. Lots of people dislike C++ because of all the confusing detailed rules inside the obscure advanced features (such as partial specialization of templates). If that is what bothered you, you had a bad introduction to C++. If you don't need the power of such features, you can program in C++ without being bothered by their existence. If you do need the power, some hypothetical language with a more self consistent design for such features would be great if it existed. But it doesn't. If you need such features and good performance, C++ is the only choice. |
Quote:
Look at, say, http://en.wikipedia.org/wiki/Eiffel_...mming_language . |
Quote:
Java's pass-by-reference makes much more sense and wastes less computing power. Usually when I want to copy an object I want a handle that can modify the original. This can be done in C++ with pointers, but you have to worry about the original going out of scope. C++ references seem very confusing, how do I know if it's a reference or variable if the syntax is the same? Even if you get past this, where do I use references and where do I use pointers? Mainly because the above things I said, it is very difficult to write a program that feels simple and solid, because there is either too much ways to do it or no way to do it. Programming in C++ feels more like some poor hack than making a solid program. |
Quote:
A derived class normally has different constructors than the base class. You cannot inherit constructors (I would like C++ better if you could). A derived class must invoke the constructor of the base class (either explicitly or implicitly). But that should be true in any OO language. Quote:
Quote:
You just described one of the major reasons many programmers dislike both C and C++. But how can you dislike that in C++ but like C? Quote:
In any non trivial programming language, the meaning of a chunk of code depends on things defined elsewhere. When I switched from C to C++, I was initially put off by the fact that meanings depend on distant definitions a lot more in typical C++ code than C and there are many more ways they can depend (such as whether some argument was declared by value or reference). But I soon got used to it, and appreciate the extra ways to localize design decisions. Quote:
In more advanced programming (such as overloading operators and defining templated methods) there are things that really need references Quote:
There certainly are too many ways to do almost anything in C++ (and I expect you don't even know about half the ways yet). I think you can learn a good subset of C++ to work with. |
One major consideration should always be the "social value" of the language. For example, you'll want a language used by lots of people if you want others to be involved eventually. Not only that, but the language should match the problems you're solving, as far as what other people might use. You don't have to "follow the crowd", but if you want help and you want people to gain from your source code, you should definitely take other programmers into consideration. If you're code is "yours forever" then you don't have to worry about this.
Along the same lines, you should look at the trends in language usage. I hate to say this, but Java's still on the rise, although C and C++ aren't going anywhere anytime soon. You might also want to look into the common languages used in Linux such as python, perl, lisp, etc. Kevin Barry |
Quote:
Quote:
Quote:
Quote:
Quote:
|
Quote:
Java is a tiny bit less strict in its rules for invoking the base class constructor. But it still has to be executed. Quote:
Even in simple programming, the two different syntaxes for one behavior are a useful choice. Do you think C, Java, etc. should not have for loops because the meaning is the same as a while with a couple extra lines? Should C not have X[n] syntax because the meaning is the same as *(X+n)? |
Quote:
I always thought that the superclass's constructor is not executed unless you call super() in the subclass's constructor. Quote:
|
Quote:
http://java.sun.com/docs/books/jls/t...ses.html#8.8.7 It appears something I used and appreciated long ago in Java was incorrect. So Java is not less strict than C++ about the base class constructor. It was very convenient in Java to call super() after doing some initial processing of the calling arguments of the current constructor, even selecting an overload of super() at run time inside the current constructor based on argument values (not types). I have wished for that feature in C++. But Java the language specification says you can't do that, so I guess the Java implementation I was using when I was able to do a little work before calling super() was wrong. The semantic rules for calling the base class constructor are much more similar between C++ and Java than I thought. The syntax is not similar. |
If it is called automatically, how does it know what parameters to use if there isn't a no-parameter constructor for the base class?
|
And off of the java slant this is taking: have you considered
"Objective C"? Not that I know much about it ... |
It's highly dependent on this nextstep/openstep/gnustep stuff, I don't understand that. Maybe it's OK.
|
Quote:
You can nest pointers as far as you want (*******) but you can't do so with references; a reference modifier can only be used once, and it must come last. References can never change (using defined behavior, anyway,) which is why they can be used as if they were an object. References require either a valid object or a dereference (good or bad) to create, whereas a pointer isn't initialized automatically, meaning it could point anywhere. This means a reference is in general more valid, although the object it points to can disappear, just like with a pointer. Other than that, you really need to perform a bad cast or dereference a bad pointer to get a bad reference. Lastly, a bad dynamic_cast of a pointer returns NULL, but it causes an exception with a bad reference cast. Kevin Barry |
Quote:
Only "default" constructors are called automatically. That is, constructors with no parameters. If don't provide an implementation of such a constructor the compiler creates one for you if there is no other constructor available for that class. If you do provide an implementation but don't invoke the paren't default constructor then one is invoked for you. And that is always the first call in child's constructor. If there is a constructor with parameters in parent but you haven't invoked it explicitly then compiler will complain that it can't find a default constructor and you haven't invoked one manually. This mind you is "exactly" how java behaves. As I said, I haven't tested it in C++ in a long time but I'll be very surprised if its different in principle (except some implementation details). |
All times are GMT -5. The time now is 01:24 AM. |