I can only call them like I see them.
Originally Posted by Richardcavell
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.
Am I doing okay?
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
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.