

NYTimes Objective–C Style Guide - tater
https://github.com/NYTimes/objective-c-style-guide

======
calhoun137
I hate absurdly long variable names like this:

    
    
        static const NSTimeInterval NYTArticleViewControllerNavigationFadeAnimationDuration = 0.3;
    

I feel like if your naming convention forces you to have variable names over
50 letters long, there is a problem.

~~~
5teev
Objective-C's tendency to long names (variables, selectors, classes) makes it
more "self-documenting" than any language I've worked with. Besides, it's not
that bad with autocomplete.

~~~
taspeotis
I'm not an Objective-C native, but every time I write Objective-C it feels
like I'm writing a short story.

    
    
        applicationDidLoad:withANotification:iWonderWhatTheWeatherTodayIs:LetsAskSiri:

~~~
w0utert
>> _I 'm not an Objective-C native, but every time I write Objective-C it
feels like I'm writing a short story._

That's the whole point of it ;-). Remember you usually only have to write the
code once, but you or someone else may have to read it many times.

I used to hate long variable and function names in the past, and I used to
hate named parameters. Going on the assumption the time spent typing the code
was somehow relevant, and also feeling a little more badass being able to
write all this cryptic gibberish to 'control the computer'. In time, I've
learned none of this matters and readability of your code is one of the most
important quality metrics of any piece of software that needs to be maintained
by multiple people and/or over a long timespan.

------
srik
> 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"?

~~~
masklinn
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 have a linter letting you add such a syntax rule.

~~~
SeanLuke
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?

~~~
w0utert
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 of a coding style.

Enforcing a single line for each variable declaration does not sound like a
good idea, in mathematical code this can quickly grow unwieldy due when lots
of variable are involved. It also often makes sense to group declarations of
related variables on the same line to indicate they are used in the same way,
for example 'int v0i, v1i' to indicate two vertex indices.

------
hudibras
Here's their blog post about it:
[http://open.blogs.nytimes.com/2013/08/01/objectively-
stylish...](http://open.blogs.nytimes.com/2013/08/01/objectively-stylish/)

~~~
5teev
Tag line: "All the Code That’s Fit to printf()"

~~~
mlchild
NSLog(@"All the code that's fit to NSLog()");

------
adamnemecek
It's strange that NYT seems to be transitioning to a full blown tech company.
Good strange though.

~~~
matthewbischoff
It's fun working here during the transition.

------
valtron
Why do so many style guides mandate spaces for indentation?

~~~
jyap
It is consistent across different editors.

Deterministic layout view. Tabs are non deterministic as it depends on user
settings.

~~~
masklinn
Plus not all tools can ignore whitespace changes (so indentation changes
everywhere intermixed with actual code changes drown the code stuff), and if
your codebase mixes whitespace-significant and whitespace-insignificant
code...

------
frr149
I see a lot of obsession with the irrelevant: when you're allowed to use dot-
notation, number of spaces for indentation (sic), etc... The only reasonable
item, it the singleton one, the rest... what a waste of time!

~~~
rimantas
Yeah, there is no value in consistency.

------
stigi
Has anyone ever tried to configure uncriustify [0] with a complex style guide
like this and succeeded?

Are there other similar tools that might be a better fit?

[0] - [http://uncrustify.sourceforge.net](http://uncrustify.sourceforge.net)

------
justincormack
They seem to have an en dash between Objective and C which made me misparse
the title. Surely that's not in their style guide?

~~~
matthewbischoff
Fixed. Thanks for reporting that.

------
HaloZero
why not provide a post-commit hook enforcing a lot these styles?

~~~
matthewbischoff
We've got some people here working on it.

