copyStructToStruct(someMyStruct, someOtherMyStruct);
then personally I'm immediately wondering which is source and which is destination. With the extra ampersand of the pointer version, it's pretty obvious which is which.
copyStructToStruct(someMyStruct, someOtherMyStruct);
Quote:Original post by HarryW
It's not really about people not knowing the function prototype while writing the code. It's about reading (quickly) code that uses many different functions, when you don't know (or have forgotten) what the prototypes are.
Quote:Also, Coder gave this quote:Quote:...
I'd hardly call myself an 'old line' C programmer, but I'm intrigued by this statement. I've read it a few times now and it's looking a lot like some buzzwords strung together to make a catchy quote. What's the information here that's being hidden, and why is it beneficial to hide it?
Quote:The point that I'm trying to make with this example is that, for someone looking at the DoTest() function for the first time, with the call using the reference it's ambiguous whether or not it may change the second parameter, since I need to look at the function definition to know if it's a const parameter or not. In the pointer case I can see at a glance that the structure might be changed without having to look at the function definition.
This kind of thing is very important when working in a big team, were ambiguity can lead to bugs.
size_t num_selected_files;m_folder_view->get_num_selected_files(num_selected_files, _T("*.bmp"));// orstd::vector<string_t> selected_files;m_folder_view->get_selected_files(selected_files);...etc
Quote:Original post by HarryW
_the_phantom_: You're right, that is a better example - if I'm calling that like this:copyStructToStruct(someMyStruct, someOtherMyStruct);
then personally I'm immediately wondering which is source and which is destination. With the extra ampersand of the pointer version, it's pretty obvious which is which.
copyStructToStruct(&someMyStruct, someOtherMyStruct);
Quote:Original post by Coder
- That's a convention. In similar situations, I'd say destination is first, source is second (as it is in Intel asm and standard C memory functions), and then use references. That would be:
- Just as clear as your convention (to me and my team and almost every other programmer who've used C string/mem functions).
Quote:In that case I'd read the prototype. Point is, why am I reading the code? Maintainence/Extension? Then I should make sure I understand what's going on before adding or changing anything. If I don't know what a function does, I'll check its prototype.Generally I'd agree, but consider this situation: there's 2 weeks left til the deadline to go gold. QA has been working double shifts and I've got a big list of bugs assigned to me. If I don't get at least half of them fixed by this evening, there's a dev manager that's gonna be on my back about it. Maybe I wasn't even working on this game until a month ago, but as usual the crunch has hit and the producers are throwing warm bodies at the problem, but if that's the case then it's probably not using my coding standard. In this case, I want it to be as obvious as possible what's happening so I can roughly find the likely source of the bug by scanning through code, and the less headers I need to examine the better. I'd like to be able to make reasonable assumptions about the code at first, and then verify those assumptions later if it seems they're likely to be inaccurate.
Quote:Original post by _the_phantom_
the problem with your 'example' is that the function name is bad to start with.
If it was changed to something more meaning full (such as CopyStructToStruct(const &, &) ) then using references makes perfect sense, infact more so.
*** Source Snippet Removed ***
Now, I'd argue that a function with a sane name with references is just as a good, if not better, than the pointer system.
However, if you want to use pointers with bad function names which are non-descriptive in themselves thats up to you [smile]
Quote:Original post by HarryW
Generally I'd agree, but consider this situation: there's 2 weeks left til the deadline to go gold. QA has been working double shifts and I've got a big list of bugs assigned to me. If I don't get at least half of them fixed by this evening, there's a dev manager that's gonna be on my back about it. Maybe I wasn't even working on this game until a month ago, but as usual the crunch has hit and the producers are throwing warm bodies at the problem, but if that's the case then it's probably not using my coding standard. In this case, I want it to be as obvious as possible what's happening so I can roughly find the likely source of the bug by scanning through code, and the less headers I need to examine the better. I'd like to be able to make reasonable assumptions about the code at first, and then verify those assumptions later if it seems they're likely to be inaccurate.
Quote:Original post by iMalc
You should never use a function for which you don't know exactly what the parameters should be. Always look it up, and maybe you wont be running so close to the deadline since there would be fewer bugs.
e.g. It's all too easy for new programmers to get the last two arguments to memset the wrong way around. That doesn't play too well with the execution of your program!
Quote:Original post by HarryW
That's fine, but this isn't about writing code that uses the functions, it's about reading code where they're already used.
Quote:Besides, the whole avoiding-the-crunch issue is not particularly a programming problem, it's a political one. If you know it's going to happen, I'd suggest it's better to plan for it.
if (blah) { blah }
if (blah) { blah }