[SSSD] Coding standard question (was ELAPI Adding file... )

Dmitri Pal dpal at redhat.com
Fri Sep 4 19:28:51 UTC 2009


Simo Sorce wrote:
> On Fri, 2009-09-04 at 12:38 -0400, Dmitri Pal wrote:
>   
>> Hm, I was testing you :-)
>> I did not do the typedef exactly because the of the policy you
>> mentioned.
>> Simo mentioned during the coding style discussions that he would
>> prefer
>> defines to typedes since the debugger in such cases works correctly
>> and shows the contents of the structure while the typedef
>> obfuscates things.
>>     
>
> Honestly, I don't remember saying something like that, certainly not
> when it comes to structures or pointers.
>
> In general we prefer to use the explicit structure declaration instead
> of typdefing it. But we can accept typedef's if there's a very good
> reason for them.
>
> In this particular instance your use of a #define is semantically
> identical to a typedef (and therefore you still need the very good
> reason :-).
>
> But a #define used instead of a typedef is in general just an error
> waiting to happen because of it's unexpected behavior if you do it with
> pointers.
>
> Example:
>
> 1. typedef int * int_p;
>
> if in a program you declare
> int_p foo, bar;
> then you get 2 pointers to integers as you would expect.
>
> 2. #define int_p int *
> if in a program you declare
> int_p foo, bar;
> then you get a pointer to integer, and a simple integer. Certainly not
> what you want/expect.
>
> Use defines for static values.
> And use typedefs only for basic types if there is a good reason.
> Having a shorter name is in general not a good reason, if "struct
> <struct name>" is too long then you probably just have a way too long
> structure name, shorten that one please.
>
> Simo.
>
>   
Ok, I can dig you comment on the matter but this is not the point.
If the bottom line is not to use either in such cases I am fine with them
but if the line gets too long it is not my problem then. :-)
I can shorten names but it makes sense only up to the point
when name makes sense.
If name starts to turn into a sequence of the letters hard to interpret
the whole point is lost.
I prefer meaningful names with the interface prefix.
If because of that line gets too long so be it.

As promised I will file a bug to change it.

-- 
Thank you,
Dmitri Pal

Engineering Manager IPA project,
Red Hat Inc.


-------------------------------
Looking to carve out IT costs?
www.redhat.com/carveoutcosts/




More information about the sssd-devel mailing list