Set the name of the network thread #871

Closed
wants to merge 2 commits into
from

Projects

None yet

6 participants

@steipete
Contributor

This makes debugging a lot nicer.

before
after

@lxcid
Contributor
lxcid commented Mar 24, 2013

👍

@mattt
Contributor
mattt commented Mar 29, 2013

Ah geez, that is a world of a difference.

...but

 [NSThread currentThread].name = @"AFNetworking";

Didn't your parents teach you your manners about mixing dot and bracket syntax? ;)

@tewha
Contributor
tewha commented Mar 29, 2013

TIL you can use dot syntax on classes. Thanks, @mattt. :)

@mattt
Contributor
mattt commented Mar 29, 2013

TIL you can use dot syntax on classes.

Oh, no no no no no. But how will we separate ourselves from the uncleaned masses of scripting languages?!

Call me old-fashioned, but [[NSThread currentThread] setName:@"AFNetworking"]; looks quite handsome to me.

@kcharwood
Contributor

+1 @Mattt :)

@tewha
Contributor
tewha commented Mar 29, 2013

I think I like the []. form; currentThread isn't really a property of the class, but name is a property of the instance.

But, you know:

#include "DotSyntaxArgument.h"

Yes, #include. #import's semantics are not appropriate here.

@blakewatters
Contributor

I have to agree with @mattt here, but for another reason: the NSThread header declares set name as:

- (void)setName:(NSString *)n NS_AVAILABLE(10_5, 2_0);

Aside from simply respecting the headers as declared, there is a benefit to conforming to property vs. method syntax: When you paste code into LLDB that uses dot syntax but the interface declares a method it gives you shit:

(lldb) po [NSThread currentThread].name
error: property 'name' not found on object of type 'id'
error: 1 errors parsing expression
(lldb) po [[NSThread currentThread] name]
$2 = 0x02e77844 <object returned empty description>

If you follow the convention, then you can often just copy arbitrary portions of code and introspect it in the debugger. Going with whatever you feel like means you will be doing casts within LLDB to see values for arbitrary objects.

@tewha
Contributor
tewha commented Mar 29, 2013

Good point, @blakewatters.

@mattt
Contributor
mattt commented Mar 29, 2013

[[GitHubThread currentThread] setBikeShedColor:color includesSurprisingLevelOfInsight:YES];

@steipete
Contributor

I'm OK with either way, as long as this one gets merged :)

@mattt I did change the commit extra for AFNetworking, I used this in my code:

NSThread.currentThread.name = @"AFNetworking";

And I know that it's not declared as property, but it behaves like a property. (isn't that what ObjC is all about?)

@blakewatters Good catch. Let's hope the lldb people continue working on it, since the debugger could infer the type from currentThread (it's declared as NSThread, not id). I bet this will work at some point.

@tewha
Contributor
tewha commented Mar 29, 2013

Yes yes. The dot syntax conversation is interesting, but @#$%!!! We can fix the thread name.

@mattt
Contributor
mattt commented Apr 6, 2013

Merged! bab6a8b

@mattt mattt closed this Apr 6, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment