1

Consider the following method:

+(void) myMethod:(int)arg1 **argument2**(int)arg2 **argument3**(int) arg3;

See how the first argument, unlike the 2nd and 3rd, doesn't have a description, giving it an impression of bad symmetry. Also you would expect the extra typing will provide named argument as you pass it in, but you still have to pass them in the correct order.

Can anyone help me make sense of this?

Moshe
  • 57,511
  • 78
  • 272
  • 425
Haoest
  • 13,610
  • 29
  • 89
  • 105
  • "Weird" is a fairly subjective and argumentative term. I suspect this question will get closed. Recommend you think about what the real question or questions you have are, and then if they're not "why did they do it this way" sorts of questions, try again with a specific technical question. – T.J. Crowder Mar 13 '11 at 07:52

4 Answers4

1

You're missing : after argument2 and argument3

Also, first argument is named myMethod. By Apple's naming recommendation guide, you'd see the method should be named in the manner that identifies semantics of first argument.

EDIT:

check out this document Coding Guidelines - Naming Methods

rdamborsky
  • 1,920
  • 1
  • 16
  • 21
1

Hopefully the response to this other question will help you make sense of what you see.

Community
  • 1
  • 1
1

The logic behind this exists though hard to get used to.
regarding your first note, about the naming of the first param, Apple encourage you to name your methods as follows:

+(void)myMethodWithArg1:(int)arg1 Arg2:(int)arg2 Arg3:(int)arg3;

thus making the name readable like a sentence in english
(my method had Arg1 of type int, Arg2 of type int, etc)

regarding the named params and the inability to change the order, that makes no sence to me either

and the comment above me is correct, you are missing those annoying : after the params

In addition, the syntax of ObjC has strong relation to that of Smalltalk (http://www.smalltalk.org/main/)
I'd encourage you to read on that and the relation between the two languages

hope this helps

Nadav
  • 1,167
  • 2
  • 19
  • 43
0

The method name is supposed to described the first argument.

Like:

+ (void)updateUserWithId:id andAge:age

So that the whole expression gives sort of a natural sentence.

Heiko Rupp
  • 30,426
  • 13
  • 82
  • 119