Logo

Developer learning path

Processing

Functions and methods in Processing

Functions and methods

61

#description

In processing, functions and methods are used to group a set of instructions that perform a specific task or manipulation of data. Functions are standalone blocks of code that return a value, called the function's "output," based on certain input parameters that are passed to the function.

On the other hand, methods are built-in functions that are pre-defined within classes or objects in processing. Methods are used to manipulate the data within the object or class to which they belong.

Both functions and methods can be called multiple times, making them reusable and efficient for coding. Writing functions and methods can simplify coding by allowing you to use the same set of instructions multiple times without having to write them out each time. Additionally, functions and methods can be designed to take in different types of input parameters, making them versatile and able to be applied to a variety of situations.

To create a function in processing, you can use the following syntax:

                    
outputType functionName(inputType1 parameter1, inputType2 parameter2, ...) {
  // function body
  return outputValue;
}
                  

To call a function, use the function name followed by the input parameters in parentheses:

                    
outputType result = functionName(parameter1, parameter2, ...);
                  

To use a method in processing, you can use the following syntax:

                    
objectName.methodName(inputType1 parameter1, inputType2 parameter2, ...);
                  

In summary, functions and methods are programming constructs in processing used to group and organize code, making it more efficient and reusable. They can be called multiple times, and designed to accept different input parameters. Functions are standalone blocks of code, while methods are built-in functions within classes or objects.

March 27, 2023

If you don't quite understand a paragraph in the lecture, just click on it and you can ask questions about it.

If you don't understand the whole question, click on the buttons below to get a new version of the explanation, practical examples, or to critique the question itself.