RAD
14 Mar 2020
Table of Contents
Excel
Excel: “Return value”’s “data type” from a method named average
:
Think of a “return value” as a hint that you can take away coffee from the drive-through window of a Starbuck’s.
Excel: “Input parameters” to a method named average
:
Think of “input parameters” as a hint that Starbucks expects you to pay them and to specify what size coffee you want before they’ll give you coffee!
Excel: “Calling” a method named left
(using the string "Katie"
as an input parameter), saving its value to a “variable” (cell B1
), and then writing more code that “calls” a method named concatenate
and “passes” the value in B1
as an “input parameter”:
- This requires planning ahead and thinking about what the “data type” of the “return value” from the
left
method would be (answer: “string”). - This requires planning ahead and thinking about what the “data types” of the “input parameters” to the
left
method would be (1 “string” as the first “parameter”, and 1 “integer” as the second “parameter”), which will help guide where in the list of “input parameters” to type a reference to the “string”-typed data contained within cellA1
. - This requires planning ahead and thinking about what the “data types” of the “input parameters” to the
concatenate
method would be, which will help guide where in the list of “input parameters” to type a reference to the “string”-typed data returned by the formula in cellB1
.
This act of “planning ahead” can be done by looking at the Excel method’s “signature.”
The “hover-over text” shown above for average
demonstrating its “return value” “data type” and its “expected input parameters” is about the closest thing you’ll find in Excel to a “method signature.”
A note on “saving things to a variable” that come out of a method:
Imagine that the Starbuck’s drive-through doesn’t give you your coffee in a paper cup.
Instead, they expect you to know that you’re coming to a place that serves coffee and bring a reusable mug.
All they promise to do, when paid, is reach out the window with a pot of hot coffee and start pouring it for 3 seconds.
If you don’t want to waste your money, you’ll probably want to have brought a mug and hold it under the stream of hot cofee!
That’s what it’s like to “save the return value” of a method into a variable.
Excel’s user interface makes it so intuitive to do this that you don’t think about where the variable B1
came from. Maybe we can say that Excel’s “Starbucks” window attendant … hands you a paper cup to catch the coffee with right before it starts pouring the coffee out the window.
(In Apex, you’re going to have to manage your own mugs.)
Excel:
- “Calling” a method named
left
(using the list-of-integers1, 2, 3, 4, 5, 6
as an input parameter) - Saving its value to a “variable” (cell
B1
) - “Calling” a method named
left
(using the list-of-integers7, 8, 9, 10, 11, 12
as an input parameter) - Saving its value to a “variable” (cell
D1
) - Writing more code that “calls” a method named
max
and “passes” the values fromB1
andD1
as “input parameters” - Writing yet more code that directly “calls” the
left
method from within the “call to” themax
method, just to show that it has the exact same effect.
Formula Fields
“Return value”’s “data type” from a Formula Field:
Defining a “body” for a Formula Field named Eighteen_Digit_ID__c
:
“Calling” a Formula Field named Eighteen_Digit_ID__c
from within a Formula Field named Link_To_Record_With_18_Digit_ID__c
:
Apex
“Calling” an Apex method named getAverageOfBiggerList
that is saved inside a file represented by the Apex class MyDemoClass
:
Note that getAverageOfBiggerList
in turn “calls” an Apex method named average
that is saved inside a file represented by the Apex class HandyMathMethods
:
Here’s what the contents of the file represented by the Apex class HandyMathMethods
looks like:
- This requires planning ahead and thinking about what the “data type” of the “return value” from the
left
method would be (answer: “string”). - This requires planning ahead and thinking about what the “data types” of the “input parameters” to the
left
method would be (1 “string” as the first “parameter”, and 1 “integer” as the second “parameter”), which will help guide where in the list of “input parameters” to type a reference to the “string”-typed data contained within cellA1
. - This requires planning ahead and thinking about what the “data types” of the “input parameters” to the
concatenate
method would be, which will help guide where in the list of “input parameters” to type a reference to the “string”-typed data returned by the formula in cellB1
.
This act of “planning ahead” can be done by looking at the various Apex methods’ “signatures.”
- The “signature” of
getAverageOfBiggerList
(which I spread out across lines 3-6 for legibility) indicates that it the “data type” of the value it “returns” is a number that is allowed to have digits after the decimal point. - The “signature” of
getAverageOfBiggerList
indicates that it “takes,” as “input parameters,” 1 “list of integers” as the first “parameter”, and 1 “list of integers” as the second “parameter”. - The “signature” of
average
(line 3) indicates that it the “data type” of the value it “returns” is a number that is allowed to have digits after the decimal point. - The “signature” of
average
indicates that it “takes,” as an “input parameter,” 1 “list of integers” as the first and only “parameter.”