As a beginner to C++, I would just like to ask what makes c# better than C++, and if I should wait to learn C++ before jumping right into C#.
As a beginner to C++, I would just like to ask what makes c# better than C++, and if I should wait to learn C++ before jumping right into C#.
If you actually mean "in what way is C# better than C++", then just search the Web for phrases like "C# versus C++". I easily found C++ vs. C# - a Checklist from a C++ Programmers Point of View.
If you want to learn C#, then learn C#. You can always come back to learn the other one some day.Originally Posted by ashinms
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
It would not surprise me if this is a common issue for people going C#->C++, instead of the other way around.
Even in spite of C++ being(Or at least having the possibility to be) somewhat higher level than C, there are still things such as pointers, arrays and so on, which deal with things on a much lower level than you can in C#. This means that were you you start C++ with no idea of programming beforehand, you would be forced to learn the low level ways, and therefore, going a level higher will be cake.
Going the other way around; e.g. programming without ever having to deal with these things, then going to another language that's a level lower, where you do have to deal with them, will be much harder.
"What's up, Doc?"
"'Up' is a relative concept. It has no intrinsic value."
And not unique for C#->C++, but also applies to moving from any other language that "does memory management for you", such as Java, Python, Perl or Basic and many others.
C++ (and C) have very basic handling of memory - it requires programmer effort to maintain pointers to valid memory, and to ensure there are no memory leaks or other problems. (This is in the standard language - obviously, with sufficient code added on top of the standard language, we can CREATE the environment for "automatic memory management", e.g. Python and C# are written in C or C++, so obviously the memory management done by those languages can be written in C or C++).
Almost all other basic principles of C++ are identical between C#, Java, Python - there are some subtle differneces, but for most programmers, those are a simple case of "learning how to do it in this language".
The principles of managing your own memory is a bigger task to learn.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
the feedback I've heard is that it's not just memory management. knowing where to use -> and :: when you've been using the dot for everything can be confusing for some, and the fact that C++ doesn't keep track of how big an array is when you dynamically create it was frustrating for one of my friends a while back.
It can be frustrating, yes, but it will in turn make you a better programmer to know how these things work. Deep down under C# and other similarly managed languages, unmanaged memory management is doing the work. Pointers are almost nonexistent in C#, but understanding them is pretty important in my opinion.
"What's up, Doc?"
"'Up' is a relative concept. It has no intrinsic value."
It does, if you use std::vector or std::tr1::array.
However, by default, it will not do bounds checking.
For dynamic arrays with vector, however, using the .at member function will guarantee that no out-of-bounds can be made.
boost::array also raises an assert if an out-of-bounds access is made.
How about the fact that in theory, your code you write in C# should be language independent to other .net languages. IE a class you write in C# can be inherited from and expanded by a VB.net developer, and you can then take that class and use it in your app.
Yes. You helped.
They're taking it a step further with C# 4.0, allowing you (with proper binding libraries of course) to call functions and instantiate objects dynamically across any language (javascript, python, ruby, etc).
That stuff is more advanced and may find little use but it's an interesting addition.
Personally I haven't done much stuff in C++ lately, would like to get back into it though. I prefer C# because of the frameworks it offers for web development (ASP.NET MVC) and desktop/web applications (WPF, silverlight).
C# might have a lot of connectivity features, but the truth is it's really just a big ole kludge. Besides that, any language lacking deterministic destructors just seems inherently flawed to me. I'd say stick with C++ unless you have no other choice.
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
You can still have the deterministic deallocation of resources via Dispose(). Plus, it helps improve performance -- if a large number of objects go out of scope at once, they don't need to all be destroyed immediately while your thread sits on its ass waiting. Rather, they can be garbage collected whenever there's time available to do so.
You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.
hmm... I was surprised to hear that C# has deterministic destruction, but a quick check shows that Dispose() is not automatically called when the object goes out of scope, so that does not adequately address Sebastiani's point.Originally Posted by Cat
A recent garbage collection discussion on the Boost mailing list gives me the impression that a well designed allocator would provide that benefit as well, though in this case it would be about delaying the freeing of memory since the objects would nonetheless be destroyed.Originally Posted by Cat
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Finalize() is called when an object is being deleted. It is in effect a destructor for C#, usually it's only used to free managed resources. Its syntax is also similar to C# as in ~ClassName();.