AnnanFay
AnnanFay

Reputation: 9749

Functions are to Arguments as Statements are to ...?

Maybe this question makes little sense, however I feel I need clarification.

Functions and methods have parameters when defined and are called with arguments.

What are the values that are passed into a statement called? By statements I mean conditionals, loops, and the like.

For example:

print 'foo'
print('foo')

PHP treats these roughly the same, Python 3 is now using the function instead of the statement.

What is the relation of 'foo' to the print statement called?

Upvotes: 2

Views: 63

Answers (2)

Dan F
Dan F

Reputation: 17732

Statements are usually composed of operators and operands so if print is the operator then I suppose you could call 'foo' the operand.

Upvotes: 1

Ekkehard.Horner
Ekkehard.Horner

Reputation: 38745

Functions (and Expressions) return/state/deliver answers for questions. If you want to know "What is the sum of 5 and 3" you write an expression "5 + 3" or call a function "add( 5, 3 )". The arguments you pass to the function (or the operands you write in the expression) pose the question and thereby determine the answer.

But programmers have to change the world too - at least the content of the console window and at the end of a long day they want to shutdown the computer. So statements (and subroutines, i.e. named/callable pieces of code) are the means "to do something". A print statement/subroutine will just change the monitor's pixel, but answer no question; a print function will do that (side-effect) and answer "How many characters were written?". Whether an If will branch to here or there, or a While will stop or continue, is determined by the expressions/functions (= information) you put in the syntactically correct places. These arguments to statements determine what is to be done (not what is to be known).

Technically the difference between know and do is blurred. You can have assignment statements that return/deliver the assigned value (to make "a = b = c = 5;" or "while( line = getNextLine() ) {}" possible) or a ternary operator that let you use If in an expression.

But in all cases: The information (arguments/parameters/operands) you feed to the 'knowers' or 'doers' determine the results - so take care!

Upvotes: 1

Related Questions