Live data from Hacker News

NYTimes Objective–C Style Guide

github.com

41–50 of 51 posts

Re: NYTimes Objective–C Style Guide

#41
post #8

Why do so many style guides mandate spaces for indentation?

the right way to use tabs (tabs for indentation, spaces for alignment) needs some amount of discipline to get right always. It's more flexible but very easy to make a mistake and mess it up.

Re: NYTimes Objective–C Style Guide

#42
post #41
post #8

Why do so many style guides mandate spaces for indentation?

the right way to use tabs (tabs for indentation, spaces for alignment) needs some amount of discipline to get right always. It's more flexible but very easy to make a mistake and mess it up.

Agreed. But doesn't it take discipline to follow a coding convention in general? I'd argue learning tabs-indent/spaces-align is easier than following most other semantic conventions (e.g. what constitutes a good name, how to organize code).

Re: NYTimes Objective–C Style Guide

#44
post #38

Earlier quoted context omitted.

Given the numerous advantages of int* a; rather than int a;, and the general laziness of declaring variables together anyway, wouldn't it be more reasonable, as a house style, to require int and to disapprove the declaration of multiple variables in the same statement?

Note: using % instead of * below because I can't for the life of me figure out how to type an asterisk without it being used as an italics markup directive. >> Given the numerous advantages of int% a; rather than int %a; Care to elaborate what 'numerous advantages' there are to use int% a instead of int %a, because I can't think of a single one besides 'it feels more natural', which IMO is irrelevant in the context o…

[deleted]

Re: NYTimes Objective–C Style Guide

#47
post #40
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 used to think like you do, but this changed my mind; int *a; is saying, when you dereference a, you have an integer. and when you think about it - a pointer is the same length for any data type, even pointers to functions, so it would be pointless to have a different pointer type for each data structure.

> a pointer is the same length for any data type, even pointers to functions

No that's not guaranteed despite being common. And function pointers are not even guaranteed to be representable by void* (POSIX08 does mandate it though.)

Relevant sections of the standard here http://stackoverflow.com/a/3941867/1546653

Re: NYTimes Objective–C Style Guide

#48
post #38

Earlier quoted context omitted.

Given the numerous advantages of int* a; rather than int a;, and the general laziness of declaring variables together anyway, wouldn't it be more reasonable, as a house style, to require int and to disapprove the declaration of multiple variables in the same statement?

Note: using % instead of * below because I can't for the life of me figure out how to type an asterisk without it being used as an italics markup directive. >> Given the numerous advantages of int% a; rather than int %a; Care to elaborate what 'numerous advantages' there are to use int% a instead of int %a, because I can't think of a single one besides 'it feels more natural', which IMO is irrelevant in the context o…

[deleted]

Re: NYTimes Objective–C Style Guide

#49
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"?

That's how it feels, but the syntax for declaring multiple variables breaks it: int* a, b; is equivalent to int *a; int b; not int *a; int *b; So while I think it makes sense to think of the pointer nature as part of the type I stopped using it as the risk of writing incorrect code was too great. Though there's also the option of forbidding shorthand declaration. Then you can write int* a; int* b; especially if you h…

The "don't declare multiple variables on one line" is a more important rules IMO, that makes the thing that's relatively unimportant (where the * is next to) go away.

Re: NYTimes Objective–C Style Guide

#50
post #8

Why do so many style guides mandate spaces for indentation?

Python really gets murderously difficult to debug in an organization with multiple types of indentation. Spaces are the least easy to screw up there, and has been why many guides I've seen have "spaces" instead of "tabs" as the default.
Post reply on HN