Amazon.com Widgets A good definition of an argument.
Welcome, Guest. Please login or register.
Did you miss your activation email?
June 18, 2013, 01:00:40 AM
Home Help Search chat Login Register   
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+  Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+  Old Stuff
| |-+  Chapter Study
| | |-+  Chapter 3 - Classes, Objects, and Methods
| | | |-+  A good definition of an argument.
Pages: [1]   Go Down
Print
Author Topic: A good definition of an argument.  (Read 1023 times)
JackRabbit
Jr. Member
**
Posts: 54



Email




« on: October 25, 2011, 02:34:34 AM »

Greetings,

Look at this line of code as an example:

NSLog(@"The sum of %i and %i is %i.", value1, value2, sum);

In this line of code there are 4 arguments separated by commas.


In the notes that I make as I read the book, I try to define terms. But I am having trouble giving a succinct definition to the term "argument" in relation to Objective-C.

I looked in the Glossary at the back of the book in Appendix A but to no avail.

Can someone help me here with a good definition?

JR
« Last Edit: November 27, 2011, 12:21:21 PM by JackRabbit » Logged
fujilla
Global Moderator
Sr. Member
*****
Posts: 270


WWW




« Reply #1 on: October 25, 2011, 08:52:50 AM »

Maybe you are having trouble because you are trying to define something which is not an argument.

With regards to
Code: (Objective-C)
NSLog(@"The sum of %i and %i is %i.", value1, value2, sum);
value1, value2, and sum are not arguments

In terms of this statement they are the variables which you are using to fill the place of your %i's.  How I describe this is that %i is a "variable placeholder", so
"The sum of (variable placeholder) and (variable placeholder) is (variable placeholder)."
you then have to declare which variables you are going to use to populate the placeholders with (value1, value2, sum).

As for an argument, this is used in relation to methods, for instance if you look at page 36 (3rd edition):
Code: (Objective-C)
-(void) setNumerator: (int) n;
n is the argument name, and (int) is the argument type so
- = instance method
(void) = return type
setNumerator: = method name
(int) = argument type
n = argument name

How I would describe an argument is something/value you are sending into a method, so with respect to the previous statement

Code: (Objective-C)
-(void) setNumerator: (int) n;
the full method could look like

Code: (Objective-C)
-(void) setNumerator: (int) n
{
    numerator = n;
}

so we are saying the value of numerator will be whatever is sent into the method via n.

Does this help?
Nick
http://myfirstiphoneapp.co.uk
http://easyintervalsapp.co.uk
Logged
JackRabbit
Jr. Member
**
Posts: 54



Email




« Reply #2 on: November 27, 2011, 12:19:35 PM »

Sorry that I took so long to get back to your excellent reply Nick.

Yes, it helps a lot.

I especially like your definition:

Quote
How I would describe an argument is something/value you are sending into a method, so with respect to the previous statement

But before we close up shop on this discussion I want to go back to the line in question:

NSLog(@"The sum of %i and %i is %i.", value1, value2, sum);

On page 23 (of the e-book on O'Reilly's Safari) 3 paragraphs after "Program 2.5 Output it says:
Quote
The call to the NSLog routine now contains four arguments. Once again, the first argument, commonly called the format string, describes to the system how the remaining arguments are to be displayed. The value of value1 is to be displayed immediately following the phrase “The sum of.” Similarly, the values of value2 and sum are to be printed at the points indicated by the next two occurrences of the %i characters in the
format string.

So in the book they call these 4 parts of the code line in question "four arguments". Is this just a type-o error? It was that line that confused me about the term "argument" in relation to Objective-C.

JR
Logged
mitchb
Jr. Member
**
Posts: 98






« Reply #3 on: November 27, 2011, 12:46:44 PM »

The statement about NSLog having four arguments is right.
Consider the following code:

 NSString *str = @"The sum of %i and %i is %i.";
   
 NSLog( str, value1, value2, sum);

Try it out, and you will see that the format string is an argument.

Mitch
Logged

If you give a man a program, you will frustrate him for a day;
If you teach him how to program, you will frustrate him for a lifetime;
     - Anonymous
JackRabbit
Jr. Member
**
Posts: 54



Email




« Reply #4 on: November 27, 2011, 10:30:54 PM »

Greetings mitchb.

OK I will try it out. Here......

//
//  main.m
//  4 argument try out
//
//  Created by JackRabbit on 11/28/11.
//  Copyright (c) 2011 __kaleidoscope__. All rights reserved.
//

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[])
{

    @autoreleasepool
    {
        int sum, value1, value2;

        // declare variables here

        value1 = 1;
        value2 = 2;
        sum = value1 + value2;

        // insert code here...

        NSString *str=@"The sum of %i and %i is %i.";
        NSLog(str, value1, value2, sum);
        
    }
    return 0;
}


And the output.....

The sum of 1 and 2 is 3.

I'm not being ungrateful here but I'm not sure what this proves.

And while we are on the topic; what is your definition of an argument, mitchb?


JR
« Last Edit: November 28, 2011, 12:24:12 AM by JackRabbit » Logged
fujilla
Global Moderator
Sr. Member
*****
Posts: 270


WWW




« Reply #5 on: November 28, 2011, 12:54:26 AM »

Sorry JR, looking back at my reply - I was talking about parameters, not arguments ( my bad)

Nick
Logged
JackRabbit
Jr. Member
**
Posts: 54



Email




« Reply #6 on: November 28, 2011, 01:10:05 AM »

Sorry JR, looking back at my reply - I was talking about parameters, not arguments ( my bad)

Nick

Don't worry about it Nick. The way I see it, I will remember your definition about [sic] arguments and apply them to parameters when I get to that in the book.

In the meantime, I am still in the dark about the definition of "arguments" in Objective-C.

Does anyone have a light?

JR
Logged
mitchb
Jr. Member
**
Posts: 98






« Reply #7 on: November 28, 2011, 01:29:10 AM »


On page 23 (of the e-book on O'Reilly's Safari) 3 paragraphs after "Program 2.5 Output it says:
So in the book they call these 4 parts of the code line in question "four arguments". Is this just a type-o error? It was that line that confused me about the term "argument" in relation to Objective-C.

JR

I took the above to mean that you had trouble understanding that the "format string" was an argument. I made it into an NSString to demonstrate how it can be passed as an argument just like the other arguments. Str, value1, value2, and sum are all arguments being passed to NSLog().

To me any data passed from one place to another is an argument. Arguments can be passed to methods, functions or variables and they can be passed by value or by reference.

Mitch
Logged

If you give a man a program, you will frustrate him for a day;
If you teach him how to program, you will frustrate him for a lifetime;
     - Anonymous
fujilla
Global Moderator
Sr. Member
*****
Posts: 270


WWW




« Reply #8 on: November 28, 2011, 09:59:13 AM »

JR,

Hopefully this will help your understanding:
http://en.m.wikipedia.org/wiki/Parameter_(computer_programming)
Logged
JackRabbit
Jr. Member
**
Posts: 54



Email




« Reply #9 on: November 28, 2011, 11:16:35 PM »

Thank you Nick and mitchb,

You both have given me enough to work out a definition to what an argument is in Objective-C.

Nick, one thing, that Wikipedia link you gave me, I notice that the examples were in C not Objective-C. Even though C is a procedural language and not OOP, I was struck by how similar in appearance it was to Obj-C.

JR
Logged
fujilla
Global Moderator
Sr. Member
*****
Posts: 270


WWW




« Reply #10 on: November 29, 2011, 12:19:22 AM »

JR

Arguments and parameters are used in probably the majority of programming languages, procedural ornitherwise.

Also C is the underlying language of Objective-C, hence the similarities.

Basically Ovbjective-C sits on top of C (so to speak), with the added functionality OO.

Nick
Logged
Pages: [1]   Go Up
Print
Jump to:  



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.