A matter of style in C#
Hello I am a c# developer. I am currently close to being hired by avid HNer but I have a couple of things with my coding style that I need to correct. I did not take any college courses on computer science and everything I know about c# and the .Net framework I have taught myself. I was wondering if anybody had any good articles or advice on writing clean and understandable code. I have been working professionally as a c# developer for almost 2 years and everything I have done has been solo. Learning how to write clear and concise code is a must and I would greatly appreciate any advice offered.
13 comments
[ 2.6 ms ] story [ 32.3 ms ] threadAfter that, make sure you're good about commenting code that isn't immediately obvious.
From that point, I'm afraid we'd probably need some samples to see where you might be going wrong or right.
http://idesign.net/idesign/DesktopDefault.aspx
(This is the direct download link: http://idesign.net/idesign/download/IDesign%20CSharp%20Codin...)
- For private class fields, I use an underscore with camelcase, starting with a lowercase letter, e.g.:
private static int _id = 12345;
- For public class fields, properties, methods, etc. I use camelcase, starting with an uppercase letter, e.g.:
public double Determinant() ...
- For method parameters, I use camelcase, starting with a lowercase letter, e.g.:
public void Foo(int bar, ref string helloThere)
I think this is also the style that Microsoft uses internally, and it makes it easy to see where your variables came from.
When naming variables I try to give them meaningful names but sometimes within the scope of a method I will assign single letter names to variables just used within the scope.
I am peticular about not posting code that I have done for my employer but perhaps I can solve a generic problem and post the code for that. My biggest problem is that I have not had to work with another coder before and I need to learn how to properly communicate my logic and ensure that the logic is the most efficient possible.
From scanning through the Chapter on design I got this quote: "This paradox implies, essentially, that you have to 'solve' the problem once in order to clearly define it and then solve it again to create a solution that works."
It reminds me of advice I have gotten from someone before, write code to solve a problem then scrape it and rewrite it.