For Programmers: Free Programming Magazines  


Home > Archive > Software Engineering > July 2006 > Re: 'academic' problem ( speed/memory efficiency vs. human readability









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: 'academic' problem ( speed/memory efficiency vs. human readability
Thad Smith

2006-07-29, 6:59 pm

burningsunorama@gmail.com wrote:

> .. Recently we've had at work a little talk about the way of providing
> const modifier for function parameters. From my point of view are, of
> course, design requirements always more important and thus one should
> always use const keyword with parameters whose values shouldn't get
> changed inside a function ( lets call these ,In' parameters ).

....
> The opposite opinion was based on fact, that when you need to
> use/declare a local variable inside the function, the code is less
> efficient (because you lose speed and memory usage is higher), since
> you could you use a stack variable provided as a parameter


Although both approaches work (and I have used both), I lean towards the
first. My rule of thumb is to specify the usage of each variable as a
comment where it is defined. In the case of function parameters, their
comment reflects the interface, not the implementation. Changing their
value usually would invalidate that specification, so I tend to use
local variables, instead. There are exceptions where a count parameter
is decremented to zero, with a comment such as "number of items to
process", which remains correct as the items are processed. I suppose
my dilemma could be solved by having an external definition and an
internal definition of a parameter, but that gets messy.

--
Thad
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com