Professional coding

This is a discussion on Professional coding within the C Programming forums, part of the General Programming Boards category; Originally Posted by Richardcavell Common Tater, You're like a professor I once had who read my essay and said that ...

  1. #16
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Richardcavell View Post
    Common Tater,

    You're like a professor I once had who read my essay and said that it was obvious that I had written it hastily the night before I handed it in, when in fact I had spent 6 weeks preparing it and put in far more effort than anyone else in my tutorial group.

    Richard
    I can only call them like I see them.

    I see no evidence of preparation in your code... More like as you added stuff you added even more stuff, getting into a cascade of global variables, poorly formed functions and bad program stucture...

    I do not mean to offend, beyond constructive criticism, but there are very real problems in the way you write code.

  2. #17
    Registered User
    Join Date
    Feb 2011
    Posts
    126

    Am I doing okay?

    Hi,

    I've spent several days rewriting my bot according to much of the criticism that's been offered on this forum. My Wikipedia bot is now 2500 lines of source instead of 6500, and exists in only 6 .c files. Note that I haven't yet implemented all the functionality of the previous version, but it compiles and runs.

    Yet I am bothered by a number of things.

    1: There are a number of items that feel like they should be global (such as the Wikipedia edit token, the file handle of our log file and our preferences). Is it that wrong for me to make them globals? I might try to make this code multithread in the future, although it's not a huge priority and even if it does multithread, the threads will have to be able to lock each other out and play nicely etc.

    2: I am worried that I'm more likely to make a mistake with this style of coding. There's less error checking because I assume that all parameters passed into a function contain sensible values.

    3. Do I need to rationalise the parameters I pass into the functions? Could I put them into a structure and just pass the structure pointer, or make some of them global, or forgo my "zealous" error checking, which is the main reason for needing at least 4 for each function?

    4. Is there anything else I should focus on?

    Download RichardcavellBot from SourceForge.net

    Richard (TIA)

  3. #18
    Registered User
    Join Date
    Jun 2005
    Posts
    6,628
    There are some things that make sense as globals (eg things that there only need to be one of in the whole program) but, in practice, globals often cause more problems than anything else. Usually you are better off avoiding globals completely. Globals and multi-threading often don't mix together well.

    It is okay for a function to assume its arguments are sensible, if it is also okay to assume the caller will provide sensible arguments. If the caller can't be trusted to do that - and another programmer writing code cannot be sure of getting things right - then the function should check its arguments.

    You should aim to pass no more data to a function than it needs. Using globals in order to reduce numbers of function arguments is a bad idea. If you have values that make sense being together, place them into a data structure.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Sunshine, and read this, this, and this before posting again.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 03-20-2009, 06:22 PM
  2. Coding Guideline ....!!
    By imfeelingfortun in forum Tech Board
    Replies: 8
    Last Post: 10-08-2006, 08:09 AM
  3. Coding Contest....
    By Koshare in forum A Brief History of Cprogramming.com
    Replies: 46
    Last Post: 10-14-2001, 05:32 PM

Tags for this Thread


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