1

What is the difference between

@property (nonatomic, retain) NSString *subject, *name, *kind;

and

@property (nonatomic, retain) NSString *subject;
@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSString *kind;

I think the functionality is exactly the same but the first one only saves you typing and some lines of code. I am not sure though that is why I am asking :)

  • 3
    For me the main difference is readability and clarity. The second is much more readable than the first. – Fogmeister Jan 22 '13 at 09:16
  • 1
    note, that you probably want copy properties for NSStrings http://stackoverflow.com/questions/387959/nsstring-property-copy-or-retain – vikingosegundo Jan 22 '13 at 09:34

1 Answers1

1
@property (nonatomic, retain) NSString *valtOnder, *name, *soort;

and

@property (nonatomic, retain) NSString *valtOnder;
@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSString *soort;

Both the way are same.

But I prefer later one. Reason??

If you have any typo or whatever bug, you will be pointed by compiler in exact the line having that property/variable name.

If I write dozens of property and/or variable then I have to look for each of them, which one is root cause for error.... As I used @synthesize for quite a time, it was too difficult to find.

So I always advised and guided others to make one line declaration of variables, properties, synthesize etc.

I am lazy. Few think why to write same thing multiple times? Extra time and work.

But multiple lines will be more readable. You code just once and it is read hundreds of times, so just few seconds to type some extra keywords. And thanks to all the IDEs that provide you autocomplete so nowadays this reason is nearly obsolete.

EDIT:

As per vikingosegundo comment,

you should never use retain for NSString, use copy.

For Immutable objects copy should be used not retain.

Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140
  • Nice answer, I am definitely going to use the second way now! –  Jan 22 '13 at 09:20
  • 3
    Good answer, it saves you typing two extra lines but time lost to readability in the future is much greater. – Carl Veazey Jan 22 '13 at 09:21
  • I upvoted, I find this a perfect answer and there is nothing to add to it anymore, I think. –  Jan 22 '13 at 09:32
  • @moderator : I am getting fed up here, If some one downvotes it good for me and us, but there should be reason. isn't it? I am getting so many upvotes on my answers and in between one down vote comes, as someone has targeted me. – Anoop Vaidya Jan 22 '13 at 09:34
  • if you are experiencing serial down votes, a script will identify that and remove those votes. I got 11 down votes within a minute few hours ago. those will be delete around 3:00 UTC. – vikingosegundo Jan 22 '13 at 09:40
  • @vikingosegundo : you can see on few of my answers and questions... OP accepts it, other upvotes still someone downvotes, and it not serial down votes, 3 and 4 in a day. – Anoop Vaidya Jan 22 '13 at 11:05
  • If it is not serial, you will have to accept it. and actually looking at your answers, I know a reason to vote you down: Most of the questions you are answering were answered before. But instead of linking them and vote to close you answer them again. this results into more and more noise — interesting questions and answers get lost into a flood of primitive informations. Quite probably that some users get annoyed of this and «bay-back». Not nice but understandable. – vikingosegundo Jan 22 '13 at 11:30
  • @vikingosegundo: Ok, i will take this suggestion. And what about this question? – Anoop Vaidya Jan 22 '13 at 11:32
  • I dont know, why you got down voted on this question. maybe because you also use `retain` (see my comment under OP). But in your case I wouldnt care. you lost 2 points — and? you won't starve. – vikingosegundo Jan 22 '13 at 11:35