|
>>
|
No. 5733
>>5723
> Ok I'll just go ahead and assume OP is hinting at C
Not sure how you got C from my various blatant C# snippets.
> When you try to write a single line function, the overhead of context switching, copying parameters and so forth mean that you're practically incurring a 50% speed penalty, than just copying and pasting whatever one-liner that function was supposed to do.
Typical C programmer; obsessed with CPU cycles. To you, I suppose, spending a load of time optimising every line of code is a better use of time, than, say, spending a short time writing big systems that actually do something.
I don't think "having a function incurs a speed hit" is a very good argument against a function that happens to contain one sequence point.
int max(int a, int b) {
return a > b? a : b;
}
void DebugMsg(string msg) {
Console.WriteLn("Debug message: " + msg);
}
Some thing just shouldn't be repeated. What if I want to change "Debug message: "?
Do you propose that for functions like this we ought to use macros because of the speed hit?
I'm not convinced that the speed hit of calling a function is particularly bothersome for most of the code of most of the software out there. Oh no, my debug messages aren't fast enough?
... but I do have a morbid interested in anyone advocating macros.
> So again, why are you writing one line functions[?]
I like abstract, maintainable, readable code, which demands means of abstraction like functions. I have no anal speed concerns, therefore the length of those functions is of no concern either. (If I had speed concerns, I'd be optimising hot spots anyway.)
|