Alex Rivera | Logout

Most common or vicious mistakes in C# development for experienced C++ programmers

Asked 2010-03-11T12:25:15.297
19

What are the most common or vicious mistakes when experienced C++ programmers develop in C#?

Edit
Report

7 Answers

13

I've seen many C++ coders code in a COM style in C#, trying to deal with the inadequacies of the language. C# provides lots of a type safe support for your enums and there are usually nicer APIs then P/Invoking back down to C++.

The other thing I've seen catch most people out is that C# generics are not templates.

answered 2010-03-11T12:35:45.407
5

Thinking that "garbage collection" = "I never have to worry about object lifetime at all". For instance, opening a FileStream and forgetting to close it.

Or:

  1. Allocating a lot of objects
  2. Putting them in a big global dictionary (usually after "I know, I'll make a cache")
  3. Wondering why the application's memory usage always goes up and never down ("but it's supposed to garbage collect!")
answered 2010-03-11T13:23:14.353
5

Confusing "pass by reference" and "reference type":

void GetAnArray(int input, ref string[] output);

(Compare with C++: void getAnArray(int input, std::vector<std::string>& output);)

answered 2010-03-11T13:24:39.063
4

Writing the full namespace each time.

This is fine in C++ when you're typing std::this or boost::that. Not so great in C# when you repeat System.Windows.Forms.Whatever all over the place.

answered 2010-03-11T13:28:00.740
3

Forgetting to specify access modifiers for every class member.

answered 2010-03-11T13:47:37.513
2

One that got me, and I believe a lot of non C++ people too, was leaking memory due to registered events keeping an object alive.

IDisposable grated to begin with (and still does if I'm honest) but was pretty obviously going to be a difference when going from native to managed code so it is not something I'd expect C++ developers to actually fall foul of, they just won't like it.

answered 2010-03-11T15:01:48.073
1

using Hungarian Notation and other C++ naming conventions

private int m_iMyIntField;
class CWidget { ... }
answered 2010-03-11T13:31:21.547

Your Answer