On 01/11/2016 02:21 PM, Jakub Hrozek wrote:
On Mon, Jan 11, 2016 at 02:09:48PM +0100, Sumit Bose wrote:
> On Mon, Jan 11, 2016 at 01:03:33PM +0100, Pavel Reichl wrote:
>> Hello Sumit, thanks for comments and sorry for my delayed response, I'm
addressing the issues right now, in this mail I just want quickly discuss the concern you
have about
>> in loop declaration.
>>
>> I generally I prefer this kind of declaration as it limits scope of variables to
minimum and thus makes it easier to read and comprehend (It makes it obvious that variable
is
>> used just in this single loop and it's insignificant for the rest of the
code).
>>
>> In my experience there's not a performance hit at all some even claim that by
limiting scope of variables you give hints to compiler and thus generated code is faster.
>>
>> This topic was discussed for example here:
>>
>>
http://stackoverflow.com/questions/407255/difference-between-declaring-va...
>>
http://stackoverflow.com/questions/1956353/efficiency-of-c-variable-decla...
>>
>> I think that the conclusion of these threads complies with what I have stated
above. But I suppose it would be possible to find threads claiming opposite so I'm
aware it's
>> not definite source of truth :-)
>>
>> Anyway, If you prefer If I kept all declaration at the begging of the function
for legacy purposes or other I will do it (without any hard feelings).
>
> Thank you for the link, so it looks compilers can handle this well. I'm
> fine with this scheme, iirc we had this discussion for the loop index
> before and agreed that it makes sense to reduce the scope where possilbe
> to the loop. But I don't remember if there was an agreement about
> variabled inside the loop as well? But if we can agree on this I would
> like to ask you to update the paragraph in the coding style which
> currently reads "HIGHLY RECOMMENDED: Always declare all variables at the
> top of the function, normally try to avoid declaring local variables in
> internal loops.".
I really don't want to turn this threat into code style discussion, so I'll do as
you decide.
I personally think that as soon as you start mixing variable
declarations into code,
I always declare vars at the beginning of the block and
separate it with new line from the rest of the code so IMO I don't mix code
declaration and code.
you should maybe think about splitting the code
That's certainly true, but I think we can agree that there are many, many functions
that declare long list of vars that are just used in single loops and single ifs. But you
have to find that out by carefully reading the code. I just make this
obvious and thus i do provide hints that maybe we should decompose function into more
functions.
into more function..
>
> IMO with the exception of indexes mixing code and declaration actually
> /decreases/ readability.
> _______________________________________________
> sssd-devel mailing list
> sssd-devel(a)lists.fedorahosted.org
>
https://lists.fedorahosted.org/admin/lists/sssd-devel@lists.fedorahosted.org
>