Slashdot Mirror


Coding Standards for C#?

infinite9 asks: "I've been given the task of writing the coding standards for my corporation. I've been in IT for 12 years, so many things are obvious. Recently though, my employer has standardized on C# and .NET, and since I'm new to the technology (isn't everyone?) I'm not sure what to include. I've included a paragraph about signing assemblies with a standard key pair as well as a few other odds and ends. Apart from the obvious statements that apply to any language like good comments, good variable names, and maintainable code, can anyone suggest other C#/.NET related things that I should include?"

82 comments

  1. My personal standard: by DreamerFi · · Score: 1, Funny

    Just one rule about coding in c#:

    Don't.

    1. Re:My personal standard: by Anonymous Coward · · Score: 0

      How the heck could this get modded up as Informative?

  2. Google sez... by Hard_Code · · Score: 2, Informative
    Following the Microsoft recommendations in the Framework SDK might be a
    good idea - they seem pretty well thought out, and the code is going to
    look and feel familiar to other .NET programmers.

    > -----Original Message-----
    > Sent: Monday, July 09, 2001 7:01 PM
    > Subject: [Mono-list] C# coding standards for Mono
    >
    > Hey kids,
    >
    > Has anybody taken a stab at a C# coding standard for Mono classes?
    I'm
    > thinking something along the lines of Sun's Java Coding Conventions
    > (http://java.sun.com/docs/codeconv/html/CodeConvTO C.doc.html)
    >
    --

    It's 10 PM. Do you know if you're un-American?
  3. Use the IDE's beautify by buro9 · · Score: 3, Insightful

    Don't attempt to come up with any of your own formatting rules (as much as it's tempting to make your code look like the rest of your code)... having a standard formatting implemented by the IDE results in much cleaner formatting and will ensure that the people you hire will understand the code that much sooner.

    1. Re:Use the IDE's beautify by farnsworth · · Score: 1
      having a standard formatting implemented by the IDE

      this might be the least worst thing to do, but VS has terrible default formatting. I forget the name of the style, but this is what you get by default:

      namespace Foo
      {
      public class Bar
      {
      void Bar()
      {
      if (foo)
      {
      bar(0);
      }
      else
      {
      bar(1);
      }
      }
      }
      }
      combine this with the all the toolbars and help viewers that are on by default, and you can effectively read about 4 lines of code at once.
      --

      There aint no pancake so thin it doesn't have two sides.

    2. Re:Use the IDE's beautify by chrisseaton · · Score: 2, Informative

      Bullshit! That is nothing like how VS formats code. I just copied and pasted and this is how it formatted:

      namespace Foo
      {
      public class Bar
      {
      void Bar()
      {
      if (foo)
      {
      bar(0);
      }
      else
      {
      bar(1);
      }
      }
      }
      }

    3. Re:Use the IDE's beautify by farnsworth · · Score: 2, Funny

      er, the indentation got lost in my post, but that wasn't the point. the point was that using sun's style this code is 10 lines while VS formats it to be 17 lines, presenting you with much less code per screen.

      --

      There aint no pancake so thin it doesn't have two sides.

    4. Re:Use the IDE's beautify by chrisseaton · · Score: 1

      Well, I think that it's much more clear like this, more breathing room.

      You should have previewed anyway.

    5. Re:Use the IDE's beautify by metalpet · · Score: 1

      Ha! That's just a trick to inflate your stats as far as how much line of code per day you can write.

      Kinda like comments, but worse.

      Real men write:

      namespace Foo {
      public class Bar {
      void Bar() {
      if (foo) {
      bar(0);
      } else {
      bar(1);
      } } } }

      If you need more white space between your lines, adjust your font settings, but don't take it out on the brackets.

    6. Re:Use the IDE's beautify by Anonymous Coward · · Score: 0

      Ha! That's just a trick to inflate your stats as far as how much line of code per day you can write.

      Kinda like comments, but worse.

      Real men write:

      namespace Foo {
      public class Bar {
      void Bar() {
      if (foo) {
      bar(0);
      } else {
      bar(1);
      } } } }


      Actually, that's how poor men write.

      Real men have money and just buy bigger, higher-resolution screens and use the correct and visually pleasing Allman brace style.

    7. Re:Use the IDE's beautify by offpath3 · · Score: 1

      Real men write a utility to count the number of lines while ignoring comments, braces, and whitespace!

    8. Re:Use the IDE's beautify by Anonymous Coward · · Score: 0

      I hope to never be employed as a programmer who works with people that think as you do.

      Out of genuine curiosity, how many IDE's have you learned? And to think that time could have been spent learning how to improve your own code rather than, "Oh look! A new point and click a toy."

  4. C# Coding Standards by cymantic · · Score: 4, Informative

    To work out some standards use what you know from Java, Python or any other language with a C based syntax.

    The guys at ICSharpCode (http://www.icsharpcode.net/TechNotes/) have some nice documents on coding styles/standards for coding for #Develop (you don't have to follow them when coding using #Develop)

    Also have a look at something like FX Cop from MS (http://www.gotdotnet.com/team/libraries) to help enforce coding standards.

    t

  5. Reasonable, my twopennyworth by Burb · · Score: 3, Informative
    This is pretty sensible advice. Most C# shops I've worked in stick to the standard MS coding conventions.

    I would also stress: use the inline documentation stuff a log (/// comments). Use NDOC to generate documents from the XML output. Make use of the using() {} statement to encourage early resource disposal.

    --

  6. Wait until you see what's on the horizon! by wonkamaster · · Score: 3, Funny

    It doesn't really matter what coding standards you implement, as long as something consistent is used. And that doesn't really matter much either.

    Microsoft will probably innovate a new language syntax soon, my guess would be C##. It will undoubtedly be more scalable, secure, robust and less prone to errors. And it'll automatically be included in the latest version of Windows, but not be compatible with previous versions due to architecture limitations.

    Personally, I'm holding out for that version. I'm going to push my company to standardize on that version. Because it just makes good business sense.

    We need a moderation for Sarcastic!

  7. MS design guidelines by Jussi+K.+Kojootti · · Score: 4, Informative
    Yep, They're not bad: Design Guidelines for Class Library Developers.

    Maybe you'll find this useful: White paper on resource management in components written for the Common Language Runtime (CLR).

    -jk

    1. Re:MS design guidelines by ClosedSource · · Score: 2, Interesting

      In looking at MS's design guidelines, I'm struck by how big the learning curve appears to be.

      One of the main ideas behind guidelines is supposed to be that consistency will result in more programmer productivity because the programmer will recognize new aspects more quickly.

      The question is: Does the time it takes to learn the guidelines so they are second nature exceed the time saved by avoiding a lookup of a function or having to come up with your own name?

      Guidelines are an engineering product just as much as code, and as such, they should be subject to the same cost/benefit tradeoff as anything else. I wonder how often in practice this analysis is actually done.

    2. Re:MS design guidelines by aled · · Score: 1

      Aren't these guidelines oriented to building libraries, more than code style?

      --

      "I think this line is mostly filler"
  8. VS.NET by diesel_jackass · · Score: 1

    Learn to use Visual Studio.NET. It will do everything you want it to. Don't worry about tabstops, etc. because it does stuff like that for you. Some helpful shortcuts:

    CTRL+[SPACE] = Type ahead
    /// = When used a line above functions, events, etc. it will autogenerate the XML based comments

    I used to program C# with UltraEdit before my company could afford VS.NET. VS.NET paid for itself the first day that I used it because it saved me so much time.

    If you have the time, I'd highly recommend reading the C# language specification.

    1. Re:VS.NET by Schnapple · · Score: 2, Interesting
      Two things I would suggest in regards to the reliance upon VS.net:

      1. VS.net obviously gives you the "VB" approach to design and coding, so you have things like Intellisense pop down your available functions and methods, and instead of worrying with coding your GUI design you design it in design mode.

        Of course the problems with this approach is that it's way too easy to use the IDE as a crutch - especially Intellisense. One day you'll be in a situation (like a technical quiz for an interview) where you won't have these tools available, so unless you're paying attention you won't know what to do.

        Now this is not to say that IDE's are bad - we all use them. But be aware of what you're doing - commit to memory the notion of what event handlers you're really writing code for.

        Also, VS.net writes part of your code for you as part of the interface design - this is hidden (collapsed) by VS.net into a region - something like "Forms Designer Generated Code". They're correct in telling you in the comments not to touch it, but do open it up and look at it every once in a while, both because then you'll see the behind the scenes stuff (something VB6 wouldn't let you do) and because that stuff is written with Microsoft Best Coding Practices in mind, so it's clean to look at and study.

      2. The second thing I would say is use the command line compilers now and again. Obviously you don't want to commandeer a huge project with command line compilers if you don't have to, but it's still a good way to make sure you know the code better than you know the IDE. A happy medium can be found with the open source (!) IDE SharpDevelop, but be forewarned that the forms designer leaves a bit to be desired and I've had SD wipe out code of mine before.
    2. Re:VS.NET by borgboy · · Score: 1

      Well... VS.Net, for all that I love about it, sucks at managing large projects. I would STRONGLY recomend making sure you know how to build EVERY project, from the command line, without using the IDE (yes, you can invoke the IDE as a build tool from the command line.) To that end, I'd suggest using NAnt, Ant, or the not free but very fine FinalBuilder.

      As far as wizard generated code goes, the (extraordinarily expensive and worth it) Compuware DevPartner Studio often flags wizard code as non-compliant with MS' own standards.

      All above referenced tools/products are easily googled. No apologies if you're too lazy to do so.

      --
      meh.
    3. Re:VS.NET by MisterFancypants · · Score: 1
      Of course the problems with this approach is that it's way too easy to use the IDE as a crutch - especially Intellisense. One day you'll be in a situation (like a technical quiz for an interview) where you won't have these tools available, so unless you're paying attention you won't know what to do.

      If I were on an interview and they were asking me such an API-specific question that Intellisense would have helped me answer it, I wouldn't work at that company anyway.

    4. Re:VS.NET by 0x0d0a · · Score: 1

      Well... VS.Net, for all that I love about it,

      I'm curious. Why *do* people like VS.Net, as opposed to say, emacs?

    5. Re:VS.NET by borgboy · · Score: 1
      well, Mister CRLF, it is well suited to developing applications on the Windows platform. It provides such boons to us evil stormtroopers like:

      context sensitive help with examples coded in multiple languages.

      Intellisense that integrates user code documentation.

      Template creation to limit junior programmer usage of pretty/useless widgets

      Good macro support

      Integrated web load testing tools

      Integrated Active Directory support

      Integrated database support

      Integrated debugger

      Forms designer for the gui guys (I ain't one)

      Class/object browser
      For our shop, it is worth the investment. But then, we just get the MSDN Universal Subscription...we don't actually pay for just the IDE. But soon, there will be Sidewinder.

      --
      meh.
    6. Re:VS.NET by Anonymous Coward · · Score: 0

      Your company couldn't afford Visual Studio .NET? What do they pay you with, used tissues?

    7. Re:VS.NET by 0x0d0a · · Score: 1

      It just seems that most of these have parallels.

      context sensitive help with examples coded in multiple languages.

      But so does man, which comes with cygwin.

      Intellisense that integrates user code documentation.

      Doxygen.

      Template creation to limit junior programmer usage of pretty/useless widgets

      Dunno exactly what this is.

      Good macro support

      Hehe. Yup, I think emacs could manage this.

      Integrated web load testing tools

      Why would you bundle web load testing tools into an IDE, and what's the benefit over using an external program?

      Integrated Active Directory support

      What does it let you do...you aren't managing a network from VS.NET...

      Integrated database support

      What's the benefit over having a db client built into the IDE over just running an external, like psql?

      Integrated debugger

      ddd

      Forms designer for the gui guys (I ain't one)

      Okay, fair enough. I can see how tying a RAD UI tool to the IDE might be convenient.

      Class/object browser

      There are a *ton* of these for UNIX, for C++ and Java at least. Dunno about .NET.

      See, that's what I don't get. The integrated forms designer might be nice, but most of the things that people like VS for don't seem to be anything special. And it costs enough money to get much nicer hardware instead...

    8. Re:VS.NET by diesel_jackass · · Score: 2, Informative

      I was in your shoes when I was using UltraEdit and the free .NET SDK for development. I had all kinds of macros set up to autogenerate a separate xml file where my comments would be extracted from the code and placed into, while placing the rest of the 40 or so cs files into a dll and running it, etc. I thought that the color coding was help enough with programming. I'd just assumed that VS.Net was just bloat-ware like every other MS dev. env. that I've used in the past.

      However, unless you have the entire .Net built-in class libraries in your brain and can compile code with warnings in your head on the fly, VS.Net will greatly speed up the development process. (It's much easier to hit ".", "(", or CTRL+SPACE, than to google MSDN for what I'm looking for.) Aside from all the other features already listed, its integration with VSS is pretty seamless.

      You really have to use it for a day to realize it's potential. All the MS marketing fluff sites don't do it any justice. Ours at work was included with individual MSDN Universal subscriptions for all of our developers. We all got to upgrade from NT and whatever development tools we were using before (VS6.0, HomeSite, UltraEdit, notepad, vim).

    9. Re:VS.NET by sheldon · · Score: 1

      "One day you'll be in a situation (like a technical quiz for an interview) where you won't have these tools available, so unless you're paying attention you won't know what to do. "

      Interesting our lead developer who does our interviews generally asks a question like this, and one of the acceptable answers is "I don't know, but that's easy to find in MSDN."

      We're much more pragmatic here in the heartland.

    10. Re:VS.NET by Jord · · Score: 1
      Your correct you wouldn't because they would not hire you.

      If a programmer does not know the language well enough to write out a class/method, etc. on a whiteboard without reference then who is really doing the programming?

      Part of being a progammer is understanding the language so well that you can see what the language is doing "under the covers". If the IDE does all of that for you, then I guess the company should hire monkeys because the IDE is doing all of the work.

  9. A few perls of wisdom by Michael.Forman · · Score: 0, Offtopic

    Coding standards:
    • No & in function call unless necessary.

    • Split long lines using hard return; try to respect the 72th column margin (this is kind of a soft limit).

    • Scripts should use strict, and run -w. Documentation should come in .pod format, documentation about script internals should be in comments.

    • Refer to the Lire::Program manpage for more details.

    Another word of advice, "C#" is a bad name for your perl script. I hear there's already something named that.

    Michael.
    --
    Linux : Mac :: VW : Mercedes
    1. Re:A few perls of wisdom by Anonymous Coward · · Score: 0

      how the hell did this get informative?

    2. Re:A few perls of wisdom by Michael.Forman · · Score: 1


      I have no idea. I was aiming for funny!

      --
      Linux : Mac :: VW : Mercedes
  10. don't write to winForms by Miguel+de+Icaza · · Score: 1, Interesting

    use an abstraction layer and your code will be portable (maybe) to gtk#

    --
    Before adopting WHATWG, read the moonlight.NET EULA [http://www.microsoft.com/interop/msnovellcollab/moonlight.mspx]
  11. New technology? by n1k0 · · Score: 4, Funny

    > and since I'm new to the technology (isn't everyone?)

    Used Java? ;-)

  12. Maybe it's just me, but ... by Anonymous Coward · · Score: 1, Informative

    Having an IT guy come up with coding standards is like asking the janitor to design an operating system.

    (The fact that he's consulting with Slashdot regarding aspects of his job is kind of a hint.)

    1. Re:Maybe it's just me, but ... by krinsh · · Score: 2, Interesting

      Well, that is a pretty good point. The person creating the standards should be a Configuration Manager/CM Level III type; or a similar position, whose job no longer includes coding - a strong technical writing background is likely a job requirement here. I once worked for a very senior programmer and my duties consisted only of testing software; putting together installers and distribution media; and documentation - which included coding practices for the junior developers. Nice thing was the senior developer not only gave guidance but followed a lot of my suggestions.

      --
      I think with the interesting people, their lives can't possibly be wrapped up into a nice little package.
  13. Try Microsoft's published standards first by shodson · · Score: 1

    You might want to look at what Microsoft has published about standards first, use that as a foundation

    http://msdn.microsoft.com/library/default.asp?url= /library/en-us/cpgenref/html/cpconnetframeworkdesi gnguidelines.asp

  14. RVBA-like conventions in the works by Xoc-S · · Score: 1

    There are a set of notes towards a set of C# conventions at http://www.xoc.net/standards. RVBA has long been the most widely used set of conventions for Visual Basic. The new conventions take into account the features of C# and .NET.

  15. Don't abuse Using, try doxygen by softoff · · Score: 2, Interesting

    It's easy to abbreviate code with lots of Using statements. However, this obfuscates code, since there are several thousand classes scattered across numerous namespaces. Plus there's no different in byte code between explicit naming and abbreviated naming combined with Using statements. In our group, even the folks originally opposed to all that extra typing have now adopted this style, just for readability. One more thing: After using doxygen for the past year, I view Microsoft's xml tags a distant second. The latest doxygen 1.3 candidate does a fairly decent job with C#, and the resulting documentation is much more informative than Microsoft's. Just my two scents...

    1. Re:Don't abuse Using, try doxygen by spongman · · Score: 1

      that's not what using does. in C# 'using' is used to explicitly call an object's Dispose() method.

    2. Re:Don't abuse Using, try doxygen by softoff · · Score: 1
      There are two forms of using.
      • The using Directive is a namespace alias (of which I was referring to)
      • The using Statement defines a scope at the end of which an object will be disposed (of which you were referring to)

      The point I'm making is to stay away from aliases as much as possible (just check out the header to almost all C# code. You'll see using System; at the front of nearly every file. That's just an alias that does not affect bytecode, but makes the code less clear. Regards...
    3. Re:Don't abuse Using, try doxygen by jerdenn · · Score: 1

      It's easy to abbreviate code with lots of Using statements. However, this obfuscates code, since there are several thousand classes scattered across numerous namespaces.

      Actually, VS.NET comes to the rescue here, as well. If you do a Mouse Hover over the object in question, it will give you full namespace information. If you aren't certain of the class hierarchy, simply mouse over the object and VS.NET tells you what you need to know. More questions? Put the cursor over the object, press F1, and you get instant help on the topic.

      -jerdenn

  16. Two non-obvious things I'd suggest by Sevn · · Score: 4, Insightful

    Make sure you recommend CVS, or some other type
    of versioning system to save hell down the road.

    Enforce under penalty of death or termination of
    employment that DOCUMENTATION IS PART OF DEVELOPMENT.
    I've had many a contract where I've basically just
    had to say "screw it" and redo a rats nest of
    undocumentated code because of zero documentation.

    --
    For every annoying gentoo user, are three even more annoying anti-gentoo crybabies. Take Yosh from #Gimp for example.
    1. Re:Two non-obvious things I'd suggest by presearch · · Score: 1

      CVS? They're a Microsoft shop.
      Nothing but M$ products for them.
      VSS I suppose. Make sure you do those backups.

      In addition to the standards document, you should make
      sure that you'll have the appropriate budget for buying
      new dev tools and training every year. I'd also beef up
      your end-user support budget, you'll probably need it.
      Also make sure that your current products will be well
      supported and viable for the next year or so because
      you'll be late on delivery of your C# and .net based rollout.

    2. Re:Two non-obvious things I'd suggest by Merkins · · Score: 1
      CVS? They're a Microsoft shop.
      Nothing but M$ products for them.


      That looks like a nice, standard mis-informed Slashdot post to me.

      For Windows, there is CVS NT which works great. Then you can use Igloo for IDE integration. Or the even cooler Tortoise CVS for explorer integration (an easier to use source control tool I have yet to find).

      OR, there is always Subversion if you don't want CVS. Subversion also has a Tortoise port.

      Or, back in the closed source world, Perforce and I'm sure a handful of others.

    3. Re:Two non-obvious things I'd suggest by The+Mayor · · Score: 1

      I think you're the one with the mis-informed Slashdot post. I'm not sure you've ever worked in a M$ shop, but in my experience very few of these will accept CVS, or any other open-source software solution for that matter. Sure, CVS and Subversion work, but VSS will be the solution most M$ shops use.

      Perforce, Subversion, and CVS are all decent solutions, and all tend to have better reliability than VSS. But I've found that most M$ shops stick with M$ solutions for most tasks. If you're stuck with VSS, follow the suggestions outlined by the grandfather post.

      --
      --Be human.
    4. Re:Two non-obvious things I'd suggest by Merkins · · Score: 1

      Sure you might have some resistance to anything that isn't VSS, I was just pointing out some alternatives. I was replying to a misinformed post that said VSS was the only option.

      Also, there is Vault which looks very promising. It uses SQL Server as it's repository, and SOAP as the transport and is written in .NET.

    5. Re:Two non-obvious things I'd suggest by Anonymous Coward · · Score: 0

      You're correct that the natural instinct of a MS dev is to use VSS -- but, the stories of VSS corrupting or losing data are fairly infamous in the MS community. It's also very widely known that Microsoft does not "dogfood" SourceSafe (it is not used internally).

      Consequentally, there's probably more WinCVS users than you might expect.

  17. In addition to the coding standards pointed by... by Utopia · · Score: 3, Informative


    ....several other readers. Take a look at FxCop.
    It will help you check your code for conformance to design guidelines and point out possible usage errors, localization issues, security problems, and possible performance improvements.



  18. Wiki Wiki Wiki by Bat_Masterson · · Score: 2, Insightful

    A complete coding standard is difficult to come up with in one shot. Also, developers generally have their "de-facto" standards that they like to follow, so getting buy-in can be difficult. Perhaps it's easier to just allow the coding standard to evolve as needed by using a collaboration facility to come up with it.

    Take a look at Twiki.

  19. Poor guy. by pmz · · Score: 3, Insightful

    Recently though, my employer has standardized on C# and .NET, and since I'm new to the technology (isn't everyone?)

    I'm suprised your company would take such a high-risk action. "Standardizing" on something so new and untested is, IMO, irresponsible.

    Adopting .NET now is like adopting J2EE when it was at version 1.0 or 1.1. The details of the APIs aren't hammered out, yet, so a lot of code your company creates will be "legacy" very quickly--probably within one year. If you don't believe me, ask anyone who jumped onto the JSP and Java Servlet bandwagon when they first came out (before tag libraries, etc.).

    1. Re:Poor guy. by Arandir · · Score: 1

      They're not the only ones. You see, .NET is a religion, just like Java was ten years ago. My company is the seventh largest in the world, but someone got religion, and now C# and .NET are all the rage, to the point that they're specing them for embedded devices. Yet just last year we were forbidden to use Java for anything. The training coordinator asked me if I knew of any experienced C# instructors. I've seen hiring reqs that specify five years experience in .NET.

      It doesn't really matter how new or untested the technology is, Microsoft wants sheep to use it, so sheep do.

      --
      A Government Is a Body of People, Usually Notably Ungoverned
    2. Re:Poor guy. by Tablizer · · Score: 1

      I've seen hiring reqs that specify five years experience in .NET.

      And surprisingly they find them. I wish I knew how to BS so well. I am tired of seeing BS experts get the jobs over me. I don't like dishonesty, but in this dog-eat-dog economy it is a necessity, and I find that I am not good at it due to lack of practice.

  20. FxCop by awitod · · Score: 1

    http://www.gotdotnet.com/team/libraries/

    This very useful program is a code analysis tool that checks your .NET assemblies for conformance to the .NET Framework Design Guidelines . It uses reflection, MSIL parsing, and callgraph analysis to inspect your assemblies for more than 200 defects in the following areas: naming conventions, library design, localization, security, and performance (see rule descriptions). The package includes both GUI and command line versions of the tool, as well as the SDK to create your own rules.

  21. C# FAQ: *vital* coding standards for C# by Anonymous Coward · · Score: 2, Interesting

    I think it's pretty funny, yet deadly serious... They go through each feature of C# and end up concluding that you should avoid them all.
    C# Best Practice: Do not use boxing and unboxing

    check it out here:
    csharp faq

    1. Re:C# FAQ: *vital* coding standards for C# by Anonymous Coward · · Score: 0

      This site does a very good job of coming up with contrived ways to abuse various features of C#, but doesn't give good reasons for, or downplays, why you would want such features.

      For example, they suggest using wrapper classes to avoid boxing and avoiding structs in favor of classes. So imagine I have an array of 6 million pixel data structures containing bytes for red, green, blue, and alpha. Using my best practices, I would end up with a single heap allocation of 24 million bytes. Using these other "best" practices, I would have 30 million heap allocations.

      This guy seems to entirely miss the point of useful features like structs and delegates.

    2. Re:C# FAQ: *vital* coding standards for C# by Anonymous Coward · · Score: 0

      I think you missed the point yourself. Autoboxing entails the *same* performance penalties as wrapper classes - you just don't see it, and it can cause unintuitive and invisible differences. You might think - why wrap this primitive int in an Integer object when I can just stick it right into my collection object? But wrapping the primitive int in an Integer object is exactly what autoboxing does! It just does it silently and therefore confusingly. Code should be understandable on a statement by statement basis - the further back up you have to look and keep in your head, the harder it is to follow. That's why any sane programmer prefixes member vars with m_ or something similar. When I'm coming in on maintenance and I'm halfway down your method, I don't remember if 'someVar' is local, static, or an instance var. I have to break out of what I'm doing and go looking for the definition.

      As for him missing the point on structs and delegates, I think you're mistaken again. With delegates he shows exactly what the issue is. Delegates are not truly typesafe and they don't provide any advantage over interfaces. Where's the point-missing?

      Structs are even worse as he points out. The point of structs, as he 'points out', is to improve performance by reducing gc load. But the associated pitfalls, he concludes, outweigh the benefit - at least as a "best practice" rule-of-thumb. He's certainly got a point, and I don't see where he missed any.

    3. Re:C# FAQ: *vital* coding standards for C# by Anonymous Coward · · Score: 0

      Also, it can be confusing the way the compiler puts some of your data in machine registers and some in memory, causing performance differences you simply cannot tell beforehand. Better to indicate which variables to keep in registers by the 'register' declarator. Another thing the compiler likes to do behind your back, is store and retrieve stuff in a separate hidden memory area called the "stack", often in association with jump instructions. This can be avoided by placing your code in a single subroutine and using goto statements with explicit memory management. This can avoid many performance and complexity pitfalls, when the programmer can explicitly see what is going on statement by statement. Hope this helps.

    4. Re:C# FAQ: *vital* coding standards for C# by Anonymous Coward · · Score: 0

      Yeah, nice try. It would be funny - if it actually had anything to do with what I said. Apparently you think it does. I think you've missed "The Point" again. Better luck next time!

  22. One simple suggestion by The+Mayor · · Score: 2, Interesting

    When developing your coding standards, categorize the "rules" into three categories: recommended, guidelines, and rules.

    Recommendations are really just suggestions. For instance, the last coding standards I helped to author we recommended that open brackets (the '{' character) be placed at the end of the expression rather than on a separate line. This recommendation was not followed by some, but it really isn't that critical towards code readability. For the record, I actually like putting open brackets on new lines, so that the open & close brackets line up. I did change my practices, but I occasionally forgot, and didn't get yelled at since it was merely a "recommendation".

    Guidelines are "rules" to be followed at all times unless there is a really good reason not to. For instance, we had a guideline that instructions should not be divided between lines, and that only one instruction should appear per line. Well, if you have a really long piece of logic, splitting the instruction across two lines makes sense. Conditional expressions (i.e. something of the form of "(ab)? a : b") counted as a single instruction.

    Rules must be followed at all times. For instance, one rule we used was no "goto" statements. Pretty simple and obvious.

    We found that by having the rules in this form, people that would categorically reject some of the guidelines under different circumstances were more receptive towards the guidelines when presented in this manner. So long as they weren't forced to adopt these "rules" they somehow seemed less ominous. YMMV.

    --
    --Be human.
    1. Re:One simple suggestion by AtATaddict · · Score: 1

      I'll add one to this and see which category the folks here think it belongs in.

      Functions/methods should be separated into "functions", which return a value without modifying external values, and "procedures", which do exactly the opposite.

  23. Me thinks he was joking by Anonymous Coward · · Score: 0

    well, me thnks he was joking about the truth. but he's right most MS shops won't look at anything else...at my work we are an ms shop.
    -we develop on NT
    -using VB
    -we use VSS for source control
    -MS-SQL server bor DB
    -outlook
    -MS office

    We recently decieded we needed a good debuging package...(we have lots o bugs..:( )
    I suggested bugzilla as soon as my boos found out it ran on linux he was like nope.
    but like what ever the culture in an MS shop is weird they always want ms cause they want to go with the market leader....what ever that means.

  24. Trolling Trolling Trolling ....Haza by Anonymous Coward · · Score: 0
    Of course the problems with this approach is that it's way too easy to use the IDE as a crutch - especially Intellisense. One day you'll be in a situation (like a technical quiz for an interview) where you won't have these tools available, so unless you're paying attention you won't know what to do.


    what ever dude.
    you go back to using emacs, or VI ...(Ludites one and all).
    I will code in a modern IDE with fun little popups that remind me what function I was looking for because the guy who wrote the library I'm using left the company and used name like "NSTMRE" (can you remember that?) for functions.
    any way when I moved from Academics (emacs coding of Fortran and C)
    to Industrly VB and Java Coding in an uptodate IDE my productivity went up.

    1. Re:Trolling Trolling Trolling ....Haza by AtATaddict · · Score: 1

      I was thinking that functions can only modify their own local variables, and must return a value. Procedures may modify the object's instance variables(or class variables), as well as their ownn local variables, but may not return a value.

      Sort of...

      class A {
      private int foo;
      public void setFoo(int foo) {
      this.foo = foo;
      }
      public int getFoo() {
      return this.foo;
      }
      }

      Rather than...

      public int setFoo(int foo) {
      this.foo = foo;
      return this.foo;
      }

  25. Trolling Trolling Trolling ....Haza by Anonymous Coward · · Score: 0

    just my opinion but

    - Properties :
    should Return/set a value without modifiying the rest of the contents of the Object....ie if you call them repeatedly you will always get the same result every time...(asuming you don't do anything else inbetween)

    - Functions / Proceduters :
    can and should be anything modifying contents of the object, or not and returning a value or not.

    BTW...do you mean external to the function ? or external to the Object. cause do if you are Moding contencts directly that don't belong to you lookout.......(are there any languages left that let you do that?)

  26. One simple comment OT but about the comment... by krinsh · · Score: 1

    It is VERY nice to see people being helpful; and not just making cracks because C# is a Microsoft product.

    --
    I think with the interesting people, their lives can't possibly be wrapped up into a nice little package.
  27. Thoughts on coding standards by Anonymous+Brave+Guy · · Score: 1

    I wasn't going to comment on this thread, not being particularly informed on C# itself, but two things have struck me that might be worth mentioning.

    1. Coding standards shouldn't be about your style and layout. It's helpful to be consistent in which way you write your {} and how you capitalise your function names, but this is hardly the serious stuff of professional programmers. Coding standards should be a guide to, for example, which common idioms in the language are adopted and which are not (preferably with supporting reasoning for the benefit of those joining later). If there are particular language features that you don't use, e.g., because you've found them to be unstable or there are portability issues, these should go in as well. Any particular idioms that your own projects adopt widely should be included for the benefit of new starters, too. But it's not about whether a tab is 4 characters or 8; we have smart editors for that these days, and it doesn't really matter anyway.
    2. If you're asking this question, perhaps it's too early to be producing a full blown coding standard. The best coding standards I've seen have all evolved. By all means make a start at forming a consistent style within your teams, but until idioms develop (both in general use of C# and within your own project(s)) and best practices come to light with experience, IMHO it's better to keep an open mind than to prescribe one approach based on some artificial reasoning when you don't have the experience to suggest why it's better than any other.
    --
    If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
  28. Would that be a +1 Sarcastic or a -1 Sarcastic? by GreatOgre · · Score: 1

    We need a moderation for Sarcastic!

    I've thought about this as well. The problem is would it +1 Sarcastic or -1 Sarcastic? I think it should be something along the lines of +1 Sarcastic(Funny) and -1 Sarcastic(Asshole). Or how about a 0 Sarcastic that just adds "Sarcastic(" and ")" to the original modifier name?

    Just a thought.

    1. Re:Would that be a +1 Sarcastic or a -1 Sarcastic? by Zarf · · Score: 1

      I've thought about this as well. The problem is would it +1 Sarcastic or -1 Sarcastic? I think it should be something along the lines of +1 Sarcastic(Funny) and -1 Sarcastic(Asshole). Or how about a 0 Sarcastic that just adds "Sarcastic(" and ")" to the original modifier name?

      In my book Sarcastic would always be a +1. I would, however, like a "-1 poster is an idiot" while we're at it. Oh I suppose that's the Friend vs. Foe system.

      --
      [signature]
  29. almost useless by GCP · · Score: 1

    A site that purports to be a language FAQ and yet goes thru the features one at a time eliminating those that can be misused would rule out all good languages -- all useful tools in fact.

    There is some value in a list of wise warnings, but that's not how this site presents itself, so I'm forced to conclude that it's just another anti-MS propaganda piece.

    Since the REAL story about MS is pretty nasty, yet the technology of C# and .Net is very nice, I don't have much respect for nonsense like this.

    --
    "Those who have never entered upon scientific pursuits know not a tithe of the poetry by which they are surrounded."
    1. Re:almost useless by Anonymous Coward · · Score: 0

      I must agree that it shouldn't be called a FAQ, but it's ironic that the argument you make against its content could be rightfully made against your comment. We could call your response "another anti-anti-MS propaganda piece." While you label it nonsense without actually refuting any of it, they do the opposite and give salient examples on each point. It may be anti-MS at heart, but it's certainly well argued.

  30. Waiting by Anonymous Coward · · Score: 0
    There's a tradeoff between jumping on unproven technologies, and sticking with outdated junk because it's "proven." .Net's been out a year now, and while my company hasn't "standardized" on it, we've been using it in production since final beta, with no regrets. It was a huge jump in productivity.

    The language isn't so new, it's Java with all the annoying bits fixed. And while the APIs could change I suppose, I'd say it's better than using something which is already a legacy technology. For any Microsoft shop using VB6, COM, or MFC, moving to .Net is a no-brainer.

    1. Re:Waiting by pmz · · Score: 1

      For any Microsoft shop using VB6, COM, or MFC, moving to .Net is a no-brainer.

      VB6, COM, MFC, .NET, and who knows what comes next.

    2. Re:Waiting by Anonymous Coward · · Score: 0

      If whatever comes next is better, then I'm all for it. What are you, a COBOL programmer?

  31. Today's not tuesday, but... by Anonymous Coward · · Score: 0

    Don't.

    why not?

  32. VS.Net Web Form Designer is Very, Very Buggy by Why+Should+I · · Score: 1

    Be advised (warned ?) that the code written by the webforms designer is very, very buggy.

    If you want to wire in custom events for custom controls, or you just like to code your ascx controls in the source view (not the gui designer) then be prepared to have VS.Net intermittently decide to wipe out your event wirings.

    Also be prepared to have VS.Net hijack your xml (the aspx or ascx page) formating any time you switch from source editor to gui editor.

    1. Re:VS.Net Web Form Designer is Very, Very Buggy by Schnapple · · Score: 1

      Be sure you have this fix to minimize damage.

  33. Using (slightly OT) by MrBlack · · Score: 1

    I know this is slightly OT but...does anyone else find this "keyword overloading" (IIRR Don Box's essential .NET was where I saw this nice euphemism, or perhaps it was "namespace overloading") annoying? C# is C and C++ derived...why not use Imports (which has not been used for anyting in C#)?

  34. meta data by oliverthered · · Score: 1

    SFAIK you can assign meta-data to all functions etc.. in C#.

    Defing some basic meta-data that should be present.

    Say Author, Data, Changes / BUGS , Links to design and test documentation etc...

    It should be easy to link any good configuration management software into the meta-data.

    --
    thank God the internet isn't a human right.
  35. *BSD is dying by Anonymous Coward · · Score: 0
    It is official; Netcraft now confirms: *BSD is dying

    One more crippling bombshell hit the already beleaguered *BSD community when IDC confirmed that *BSD market share has dropped yet again, now down to less than a fraction of 1 percent of all servers. Coming on the heels of a recent Netcraft survey which plainly states that *BSD has lost more market share, this news serves to reinforce what we've known all along. *BSD is collapsing in complete disarray, as fittingly exemplified by failing dead last in the recent Sys Admin comprehensive networking test.

    You don't need to be a Kreskin to predict *BSD's future. The hand writing is on the wall: *BSD faces a bleak future. In fact there won't be any future at all for *BSD because *BSD is dying. Things are looking very bad for *BSD. As many of us are already aware, *BSD continues to lose market share. Red ink flows like a river of blood.

    FreeBSD is the most endangered of them all, having lost 93% of its core developers. The sudden and unpleasant departures of long time FreeBSD developers Jordan Hubbard and Mike Smith only serve to underscore the point more clearly. There can no longer be any doubt: FreeBSD is dying.

    Let's keep to the facts and look at the numbers.

    OpenBSD leader Theo states that there are 7000 users of OpenBSD. How many users of NetBSD are there? Let's see. The number of OpenBSD versus NetBSD posts on Usenet is roughly in ratio of 5 to 1. Therefore there are about 7000/5 = 1400 NetBSD users. BSD/OS posts on Usenet are about half of the volume of NetBSD posts. Therefore there are about 700 users of BSD/OS. A recent article put FreeBSD at about 80 percent of the *BSD market. Therefore there are (7000+1400+700)*4 = 36400 FreeBSD users. This is consistent with the number of FreeBSD Usenet posts.

    Due to the troubles of Walnut Creek, abysmal sales and so on, FreeBSD went out of business and was taken over by BSDI who sell another troubled OS. Now BSDI is also dead, its corpse turned over to yet another charnel house.

    All major surveys show that *BSD has steadily declined in market share. *BSD is very sick and its long term survival prospects are very dim. If *BSD is to survive at all it will be among OS dilettante dabblers. *BSD continues to decay. Nothing short of a miracle could save it at this point in time. For all practical purposes, *BSD is dead.

    Fact: *BSD is dying

  36. Coding Standard Standard by Anonymous Coward · · Score: 0

    I would suggest downloading the C# standards draft and it contains a suggested coding standard.