views:

107

answers:

6

I have been programming in C then C++ then Java and now doing C#. Here's the embarrassing admission: My C# is being written like I am writing C++ !!!

I am having trouble completely shaking the thinking that has been embedded in my mind for 10 years and I need to know how others have solved the same problem.

A: 

I think if you program well with c++ you must have the OOP's understanding. So all you need is to find out what c# unique characteristics and features are, and see some examples. A good c# book will be useful.
Edit: I agree with Ignacio that consulting with c# programmers can be very efficient as well.

Oren A
+2  A: 

The best thing you can do would be to ask other programmers to review your code. They can show you what you are doing wrong or what could be done in a better manner. Seasoned programmers would be better than novice programmers for code review, but even novices can catch things.

Ignacio Vazquez-Abrams
+2  A: 

trouble completely shaking the thinking that has been embedded in my mind for 10 years

That is why they recommend you to change programming languages once in a while.

My C# is being written like I am writing C++ !!!

It may not be so bad actually. Maybe you're using the best practices which are applicable in any programming environment. Let us know what parts exactly raise your concern.

What to do:

  • Look at Java/C# examples and follow them
  • Ask other experienced people to review your code. You could even drop some pieces here on SO and ask people for their opinions and advice.
  • When you're about to apply some C/C++ pattern for a particular problem in your Java/C# code, stop for a moment and ask yourself - does this problem even exist in this framework? If not or not exactly in this form, then consider alternatives.
  • Java/C# are platforms for product development not system programming. Don't try to optimize everything up to bits. It's often preferred to have a clear and concise structure with low maintenance overhead.
Developer Art
+1 only bit I'd change to the answer is: look at Good java/c# examples.
eglasius
A: 

Reading related books and even better reading and understanding good code helps a lot. There are a lot of resources out there, i.e. open source projects and blogs to get started.

BrokenGlass
A: 

You might try learning some language which is completely different (a functional language, say, or Prolog, or Erlang) to shake you out of the rut. Writing C++ in Prolog (for example) is, I would suggest, sufficiently painful an experience that your brain will quite rapidly limber up and develop new ways of thinking

And if it doesn't help directly with the C#, at least it's made you smarter, which can only ever be a good thing.

telent
A: 

I don't think that this is necessarily a bad thing. Actually I think that it's good, because anything you do that creates difficulties will soon result in problems that need to be solved, and as always when you have problems, you need to learn how to fix them.

Making mistakes is essential to learning. My advice is simply to give yourself time. It takes time to absorb the nuances of a particular language... spoken, as well as programming! ;-)

If you feel there is something lacking, or that you feel something can be done better, try and do something new. Experiment, fail, learn, succeed. Also, if you're even the least bit curious, you'll be naturally inclined to look at examples of code in books, or on websites, and this will influence how you write your code later on.

Profilers will help you if you are worried about introducing inefficiencies in your code, and tools such as Resharper or Style-Cop will help you to learn how to write your code in a manner that is considered to be the current best practice... and so will your colleagues for that matter.

I think you'll find though that coding in a new language is like wearing a new pair of shoes. It takes a while to get used to them. New means change, and change is always an uncomfortable experience. In my experience, it realistically takes about 6 months to become truly comfortable with a new language, and about a year to reach a point of proficiency, and even then, you'll find yourself doing things that others will shake their heads at. At the end of the day though, decide for yourself which is the more important. Delivering a working solution that satisfies the customer, or delivering something to impress your fellow programmers...

S.Robins