[haiku-development] Re: Haiku Coding Guidelines Issues

  • From: Stephan Assmus <superstippi@xxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Wed, 05 Sep 2007 15:05:01 +0200

Hi Truls,

> I'm no Be/Haiku coding standard expert, or even developer, but I still 
> want to mention the following. There's a reason why it's considered good 
> practice to write * and & next to the variable rather than the type. 
> Consider this declaration:
> 
>     char* foo, bar;
> 
> Intuitively, this should declare two string variables, but the fact is 
> that this makes foo a string and bar a character. Grouping the * with the 
> variable name makes it more obvious that it modifies the type of a single 
> variable only. While this reasoning does not really apply to method 
> signatures, it's more consistant to use the same convention for both 
> methods and variables.

Yes, we are absolutely aware of this issue. Our coding guidelines forbid 
the above form of declarations, not only because of the mentioned issue, 
but because it quickly leads to not so easily readable code. The effect of 
the above statement is considered a bad oversight of the C/C++ standard by 
most of us. It is really much easier to think of "char*" as the type of a 
variable, and this is also how the compiler will treat it in terms of type 
safety. Starting to think of "char *foo" as of type "char" but really a 
pointer is just all messy.

char foo -> sizeof(foo) == 1
char *foo -> sizeof(foo) == 4

... really, it is much easier to think of "char" and "char*" simply as too 
different types. The issue you pointed out should not spoil the fun. :-)

Best regards,
-Stephan

Other related posts: