Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm going through some training on objective-c. The trainer suggests setting single character parameter names. The .NET developer in me is crying. Is this truly the convention? Why?

For example,

@interface Square : NSObject
{
  int size;
}

-(void)setSize: (int)s;

I've seen developers using underscores int _size to declar variables (I think people call the variable declared in @interface ivar for some unknown reason). Personally, I prefer to use descriptive names. E.G.

@interface Square : NSObject
{
  int Size;
}

-(void)setSize: (int)size;

C, like C# is case sensitive. So why don't we use the same convention as .NET?

share|improve this question
add comment

2 Answers

up vote 7 down vote accepted

There are many standards for variable naming, it depends on the programming language used, and on the core developers involved in the project.

In case of objective-c, I think this page should answer your question: https://developer.apple.com/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/NamingIvarsAndTypes.html

As per using single-letter parameter names as a general rule, it is clearly a horrible idea, don't listen to it.

share|improve this answer
1  
+1 to heck with terse variable names! –  Jason Holland Jun 28 '12 at 17:33
    
Especially with good autocompletion. Self-documenting code ftw! –  pwny Jun 28 '12 at 17:34
add comment

If I have understood correctly you are talking about Hungarian Notation.

In this case you can refer to this answer for an explanation.

You can also refer to this answer for the second part of your question.

share|improve this answer
1  
Yes and no. To me, Hungarian Notation implies appending type information to variable names, which is not what I am suggesting at all. I simply mean to say variable names should be descriptive. Regarding underscores, the underscores make sense for private variables. Still, I prefer using casing over appending underscores. This avoids breaking intellisense-like features which sort alphabetically. –  P.Brian.Mackey Jun 28 '12 at 16:23
    
what do you mean with "descriptive"? appending type names is also descriptive but is wrong, in general creating this bind between labels and descriptions leads to a lot of useless noise in the communication, also remember that this kind of work ( naming ) should be "atomic", as short as possible and with all the meaning in a single word. Something like Tyre.getPressure(), it's abstract enough and you get all the info that you need, it's abstract because you are not binding the concept of the Tyre with a Car or a Bus, continues –  user827992 Jun 28 '12 at 16:36
    
writing CarTyre.getPressure() is wrong because you are not taking advantages of the OO design and you can simply have a class Tyre that inherits from the class Car. If you read the post that i have linked you will find that this behaviour can only generate noise and is just useless and wrong. –  user827992 Jun 28 '12 at 16:39
    
Using single letters for parameters/variables is not Hungarian notation. –  JBRWilkinson Jun 28 '12 at 16:58
    
@user827992, I'm sorry, but Tire inherits from Car? In what world do you live where a "Tire is a kind of Car"? Because that's what inheritance implies. Also, this is indeed not Hungarian Notation at all. –  pwny Jun 28 '12 at 17:31
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.