[PATCH 2/5] reg.exe: Add path_get_key() to remove boilerplate

Hugh McMaster hugh.mcmaster at outlook.com
Wed Sep 3 07:09:14 CDT 2014


On Wed, 3 Sep 2014 13:15:43 +0200, Jonathan Vollebregt wrote:
>> Single line code in if/else blocks can be compacted to use less space. E.g.:
>>
>> if (path_get_rootkey_name(path))
>>      return HKEYs[(path_get_rootkey_name(path) - &long_HKEY_name[0][0]) / 20];
>> else
>>      return NULL;
> 
> Isn't it a best practice to always use braces?

You could certainly argue that it is a best practice, and, in many ways, it is. But consider the if... else if... blocks from http://source.winehq.org/source/programs/reg/reg.c#0411 and following. If braces were included for each single line, each block would be far, far longer and (in my opinion) harder to read.

>> +static const WCHAR type_names[][MAX_TYPE_LENGTH] = {
>> +    {'R','E','G','_','N','O','N','E',0},
>> +    {'R','E','G','_','S','Z',0},
>> +    {'R','E','G','_','E','X','P','A','N','D','_','S','Z',0},
>> +    {'R','E','G','_','B','I','N','A','R','Y',0},
>> +    {'R','E','G','_','D','W','O','R','D',0},
>> +    {'R','E','G','_','D','W','O','R','D','_','B','I','G','_','E','N','D','I','A','N',0},
>> +    {0},
>> +    {'R','E','G','_','M','U','L','T','I','_','S','Z',0},
>> +};
>> +
>> +
>> +
>>
>> Also, what is the purpose of {0}?
> 
> REG_LINK isn't supported by anything in wine as far as I can tell, so I 
> thought I'd just leave it empty. Would it be better to fill it in anyway?

http://source.winehq.org/ident?_i=REG_LINK&_remember=1 shows that REG_LINK appears in the source in some form. Whether it is actively used in registry operations, I'm not sure.

Given that it appears, however, I'd include it anyway.
 		 	   		  


More information about the wine-devel mailing list