Thread: Clean Code...

  1. #16
    Registered User
    Join Date
    Mar 2005
    Posts
    37
    Hi,
    I totally agree with nvoigt.. Thats its more a sort of personal about the styling of the code..

    What you need to do is have a standard notation as to how you would identify a variable it a const. or not how would you declear a gobal variable. eg. #defined variables are usally in Caps.

    One more thing is that you need to give in more comments. Some times (personals experiance) when you right a piece of code you might think that its very trival but when you look at it after couple of times you really find it difficiult to understand.

    check out the book.. " The Practice of Programming " by, Brian W Kernighan and Rob Pike. it might help.. :-)

    happy coding..

  2. #17
    Dump Truck Internet valis's Avatar
    Join Date
    Jul 2005
    Posts
    357
    A few things that might help you that took me 3 or 4 years to pick up:
    - verbose variable names (cryptic names such as f and dii are bad)
    - document your code (with comments) as you write it, assuming anyone else could be reading it at some point
    - use more spaces, (hat<4)&&(bat>'j') is less readable than (hat < 4) && (bat > 'j')
    - This was extremely painful for me, but try to use industry standards where appropriate, if your programming for windows you should probably use hungarian notation and microsofts standards, for unix and linux you will probably have underscores in your function names and less camel caps

  3. #18
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    - This was extremely painful for me, but try to use industry standards where appropriate, if your programming for windows you should probably use hungarian notation and microsofts standards, for unix and linux you will probably have underscores in your function names and less camel caps
    So to have a different style per OS, it's kinda hard...
    btw, where can i find microsoft standart?
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  4. #19
    Dump Truck Internet valis's Avatar
    Join Date
    Jul 2005
    Posts
    357
    I haven't actually come across any consolidated source, I have found scattered sources, but I use the conventions found in device driver and header code.
    It's apparent that FunctionWithCamelCaps are preferred over unix_style, hungarian notation is used, TRUE and FALSE are used over true and false. Most mfc classes have C prepended to the name (eg CObject).
    If you search google you should find some sources that have bits and chunks of information, msdn has some articles too.

  5. #20
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Quote Originally Posted by Devil Panther
    So to have a different style per OS, it's kinda hard...
    btw, where can i find microsoft standart?
    Open a header file such as windows.h, scream in disgust, then decide you'd rather not use their standards
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  6. #21
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Seriously though, some of the stuff microsoft's 'programmers' write does look absolutely, just, completely wrong. They use variable names like '_X' and T_', I mean WTF is up with that?
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  7. #22
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    true... but then again, did you see the windows2000 code?
    look to your left above my avatar and you will see that i am not a microsoft supporter, but that coded looks pretty good
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  8. #23
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    No i've never used Windows 2000. Do you mean the Windows 2000 source code? I was under the impression that was quite well kept away from the internet or wherever?
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  9. #24
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    yeah the source code... well it leaked, like 6 month ago or so.
    it's not the complete source, but it's long enough.

    if you search in the right communities you can still find it
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  10. #25
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Awesome I'll look into that
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  2. Can someone please clean up my code
    By ki113r in forum C Programming
    Replies: 10
    Last Post: 09-12-2007, 10:03 AM
  3. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 10:20 AM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM