Live data from Hacker News

NYTimes Objective–C Style Guide

github.com

1–10 of 51 posts

Re: NYTimes Objective–C Style Guide

#2
> Asterisks indicating pointers belong with the variable, i.e. NSString text not NSString text or NSString * text, except in the case of global string constants.

I know I have it wrong, but I always feel that the the variable is of type "pointer to type" so isnt it fairer to have the asterisk paired with the type denoting it is of the kind "pointer to type"?

Re: NYTimes Objective–C Style Guide

#3
post #2

> Asterisks indicating pointers belong with the variable, i.e. NSString text not NSString text or NSString * text, except in the case of global string constants. I know I have it wrong, but I always feel that the the variable is of type "pointer to type" so isnt it fairer to have the asterisk paired with the type denoting it is of the kind "pointer to type"?

I've previously shared your opinion on this issue as well, but the first answer to this StackOverflow question shows one good reason why one should opt for having the asterisk touching the variable. http://stackoverflow.com/questions/2452335/asterisk-sometime...

Re: NYTimes Objective–C Style Guide

#4
post #2

> Asterisks indicating pointers belong with the variable, i.e. NSString text not NSString text or NSString * text, except in the case of global string constants. I know I have it wrong, but I always feel that the the variable is of type "pointer to type" so isnt it fairer to have the asterisk paired with the type denoting it is of the kind "pointer to type"?

My take on this has always been the pointerness is semantically part of the type, but syntactically it belongs with the variable.

Therefore I annoy both parties by putting a space on either side to protest the fact that everyone is wrong.

Re: NYTimes Objective–C Style Guide

#7
post #2

> Asterisks indicating pointers belong with the variable, i.e. NSString text not NSString text or NSString * text, except in the case of global string constants. I know I have it wrong, but I always feel that the the variable is of type "pointer to type" so isnt it fairer to have the asterisk paired with the type denoting it is of the kind "pointer to type"?

It's pretty easy to convince yourself that "* with the type" is wrong when you see this:

int* a, b; // a is int* but b is int

Re: NYTimes Objective–C Style Guide

#9
post #2

> Asterisks indicating pointers belong with the variable, i.e. NSString text not NSString text or NSString * text, except in the case of global string constants. I know I have it wrong, but I always feel that the the variable is of type "pointer to type" so isnt it fairer to have the asterisk paired with the type denoting it is of the kind "pointer to type"?

[deleted]

Re: NYTimes Objective–C Style Guide

#10
post #2

> Asterisks indicating pointers belong with the variable, i.e. NSString text not NSString text or NSString * text, except in the case of global string constants. I know I have it wrong, but I always feel that the the variable is of type "pointer to type" so isnt it fairer to have the asterisk paired with the type denoting it is of the kind "pointer to type"?

C has a sort of declaration-by-example syntax. You're declaring that *someVar has type NSString. (IMHO, thinking of it this way also makes more complex declarations like function-pointer types, types with qualifiers, etc., easier to read.)
Post reply on HN