writing professional code

This is a discussion on writing professional code within the Tech Board forums, part of the Community Boards category; I would like to know how the professionals among you write proffessional code. I downloaded an example that Adrianxw wrote ...

  1. #1
    Banned maes's Avatar
    Join Date
    Aug 2001
    Posts
    744

    writing professional code

    I would like to know how the professionals among you write proffessional code.

    I downloaded an example that Adrianxw wrote (that button thing). And noticed some interesting things, like he declares every variable on a new line, puts every argument on a new line. Why, was this just for a easy readable example or will this truly benefit when you write large programs?

    Also how do you handle realy large WndProc (WindowFunc in the example) Because, If you have a large menu, big WM_PAINT, Scrollbar and all that stuff in it, it can be very big. And it would be hard to read or find anything in it.

    And how about global variables. Do you say they are the devil?
    Is it better to make a function pass 10 variables then make a few global?


    How many line of code do you usually put in one file?


    Let's hear it proffies. Give the amateur some pointers

    Also, maybe attach some programs you made, they don't have to be complete or working.
    It is just to learn the style

  2. #2
    tgm
    tgm is offline
    Registered User tgm's Avatar
    Join Date
    Jun 2002
    Posts
    150
    Get your hands on a copy of "Code Complete" by McConnell. It's a good place to start.

  3. #3
    BMJ
    BMJ is offline
    Banal internet user BMJ's Avatar
    Join Date
    Aug 2002
    Location
    Chicagoland
    Posts
    1,380
    this board rocks!!

  4. #4
    Shadow12345
    Guest
    I do like code complete as well, very sexy

  5. #5
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    I can be sexy for you if you want me to.

  6. #6
    5|-|1+|-|34|) ober's Avatar
    Join Date
    Aug 2001
    Posts
    4,429
    Not that I'm what you would call a "professional", but I do write software for my company which is in use on a daily basis, so I guess I shall comment on this topic.

    Basically, the only difference between my personal coding and the coding I do for my company is that I comment a lot more, making sure that everything is explained, because I know that I will not be here forever, much less much longer.

    As far as coding practices in general, I tend to put several global variables in modules/classes that I can turn on/off depending on the various situations. Some people feel that global varialbes are dangerous, and yes, they are at times, but as long as you're careful, there's no need to worry too much.

    Anyways... I guess that's about it... I code, I comment, I produce. That's it.
    EntropySink. You know you have to click it.

  7. #7
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    You've seen how I write! Basically, code for clients would be the same but I would have added comments, (even to a trivial example like that you have).

    In a big program, I would have functions or class members for the various messages, so it doesn't get too big.

    I don't worry about globals. When they are the correct solution, I use them.

    I have as many lines in a file as is necessary. Sometimes having a big file keeps things together in a more sensible/memorable way than chopping things up just because the file is long.

    Modern IDE's go a long way with overcoming the alledged problems you raise.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  8. #8
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    Every professional team of programmers has a set of rules called a "coding standard". Look for some public ones on the web. They define how a team member has to write code, so each member can easily understand and modify it later. In a team, most of the time there aren't 100% C gurus. Some are fluent in Java, C#, Scripting or even ASM. But all have enough experience to have a look into other fields, if all of them are organized cleanly.

    Example:

    char* a,b;

    For a normal non-C programmer, this clearly reads: two char*'s, one named a, one named b. First line of code, first silly misunderstanding.

    char* a;
    char b;

    Much better.

    char* a = NULL;
    char b = 0;

    Even better yet. Always initialize variables.

    Then there are naming standards. Our company will always prefix class names with "CSAZ" as this clearly shows it's a class ("C") and if something fails we ( "saz" ) can grab the guy who wrote it and make him change it. Just one example. Look up hungarian notation for more naming standards.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  9. #9
    Banned maes's Avatar
    Join Date
    Aug 2001
    Posts
    744
    Thx guys,

    I appreciate the pointers you gave me and I will defently look in to it some more.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Writing Code
    By ILoveVectors in forum C++ Programming
    Replies: 4
    Last Post: 06-13-2005, 01:27 AM
  2. Writing code for a program in C
    By Sure in forum C Programming
    Replies: 7
    Last Post: 06-11-2005, 02:33 PM
  3. professional programmers, do you spend more time writing or modifying code
    By Terrance in forum A Brief History of Cprogramming.com
    Replies: 29
    Last Post: 11-25-2002, 10:54 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 06:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21