Skip to main content
Clarified point 2 more
Source Link
Daniel M.
  • 3.9k
  • 9
  • 8

Here is my definition of a function:

  1. A function must have the ability to be called by its name, object, reference, or other handle (this prevents code snippets). The only exception to this is the main method (or equivalent) of a program.
  2. A function must be able to pass aroundtake data as input by accepting parameters and output data by returning values. If side-effects occur, the function shouldn't exploit them; any parameters should be arguments, and any results should use your language's equivalent of return.
  3. Multiple functions can be counted as one function, provided that each helper function meets the 2 previous conditions.

Lastly, as @Downgoat's answer says, if something is obviously not a function, then it shouldn't be treated as such.


A full program is any code that can be compiled, interpreted, or otherwise executed in a non-REPL environment without any modification. Note that some code can be classified as both functions and full programs.

Anything that is not either a function or a full program is a code snippet.


For an example, let's look at Java lambda expressions.
  1. You can assign a lambda expression to an object, so it passes the handle test.
  2. It is possible to write a lambda expression that accepts parameters and returns values.

For example:

(int a, double b)->{
    return 4;
}

Since a lambda that satisfies #2 exists, any lambda is considered a function, even those that don't accept parameters:

()->{
    System.out.println("Lambda is running");
}
  1. N/A

I made a quick flowchart to categorize various bits of code (sorry for my lack of flowcharting skills):

A flowchart

Here is my definition of a function:

  1. A function must have the ability to be called by its name, object, reference, or other handle (this prevents code snippets). The only exception to this is the main method (or equivalent) of a program.
  2. A function must be able to pass around data by accepting parameters and returning values. If side-effects occur, the function shouldn't exploit them; any parameters should be arguments, and any results should use your language's equivalent of return.
  3. Multiple functions can be counted as one function, provided that each helper function meets the 2 previous conditions.

Lastly, as @Downgoat's answer says, if something is obviously not a function, then it shouldn't be treated as such.


A full program is any code that can be compiled, interpreted, or otherwise executed in a non-REPL environment without any modification. Note that some code can be classified as both functions and full programs.

Anything that is not either a function or a full program is a code snippet.


For an example, let's look at Java lambda expressions.
  1. You can assign a lambda expression to an object, so it passes the handle test.
  2. It is possible to write a lambda expression that accepts parameters and returns values.

For example:

(int a, double b)->{
    return 4;
}

Since a lambda that satisfies #2 exists, any lambda is considered a function, even those that don't accept parameters:

()->{
    System.out.println("Lambda is running");
}
  1. N/A

I made a quick flowchart to categorize various bits of code (sorry for my lack of flowcharting skills):

A flowchart

Here is my definition of a function:

  1. A function must have the ability to be called by its name, object, reference, or other handle (this prevents code snippets). The only exception to this is the main method (or equivalent) of a program.
  2. A function must be able to take data as input by accepting parameters and output data by returning values. If side-effects occur, the function shouldn't exploit them; any parameters should be arguments, and any results should use your language's equivalent of return.
  3. Multiple functions can be counted as one function, provided that each helper function meets the 2 previous conditions.

Lastly, as @Downgoat's answer says, if something is obviously not a function, then it shouldn't be treated as such.


A full program is any code that can be compiled, interpreted, or otherwise executed in a non-REPL environment without any modification. Note that some code can be classified as both functions and full programs.

Anything that is not either a function or a full program is a code snippet.


For an example, let's look at Java lambda expressions.
  1. You can assign a lambda expression to an object, so it passes the handle test.
  2. It is possible to write a lambda expression that accepts parameters and returns values.

For example:

(int a, double b)->{
    return 4;
}

Since a lambda that satisfies #2 exists, any lambda is considered a function, even those that don't accept parameters:

()->{
    System.out.println("Lambda is running");
}
  1. N/A

I made a quick flowchart to categorize various bits of code (sorry for my lack of flowcharting skills):

A flowchart

Clarified point 2
Source Link
Daniel M.
  • 3.9k
  • 9
  • 8

Here is my definition of a function:

  1. A function must have the ability to be called by its name, object, reference, or other handle (this prevents code snippets). The only exception to this is the main method (or equivalent) of a program.
  2. A function must be able to acceptpass around data by accepting parameters and returnreturning values without the use of any variable that is also used outside of the function. In other wordsIf side-effects occur, athe function mustshouldn't exploit them; any parameters should be capablearguments, and any results should use your language's equivalent of operating without side-effectsreturn.
  3. Multiple functions can be counted as one function, provided that each helper function meets the 2 previous conditions.

Lastly, as @Downgoat's answer says, if something is obviously not a function, then it shouldn't be treated as such.


A full program is any code that can be compiled, interpreted, or otherwise executed in a non-REPL environment without any modification. Note that some code can be classified as both functions and full programs.

Anything that is not either a function or a full program is a code snippet.


For an example, let's look at Java lambda expressions.
  1. You can assign a lambda expression to an object, so it passes the handle test.
  2. It is possible to write a lambda expression that accepts parameters and returns values.

For example:

(int a, double b)->{
    return 4;
}

Since a lambda that satisfies #2 exists, any lambda is considered a function, even those that don't accept parameters:

()->{
    System.out.println("Lambda is running");
}
  1. N/A

I made a quick flowchart to categorize various bits of code (sorry for my lack of flowcharting skills):

A flowchart

Here is my definition of a function:

  1. A function must have the ability to be called by its name, object, reference, or other handle (this prevents code snippets). The only exception to this is the main method (or equivalent) of a program.
  2. A function must be able to accept parameters and return values without the use of any variable that is also used outside of the function. In other words, a function must be capable of operating without side-effects.
  3. Multiple functions can be counted as one function, provided that each helper function meets the 2 previous conditions.

Lastly, as @Downgoat's answer says, if something is obviously not a function, then it shouldn't be treated as such.


A full program is any code that can be compiled, interpreted, or otherwise executed in a non-REPL environment without any modification. Note that some code can be classified as both functions and full programs.

Anything that is not either a function or a full program is a code snippet.


For an example, let's look at Java lambda expressions.
  1. You can assign a lambda expression to an object, so it passes the handle test.
  2. It is possible to write a lambda expression that accepts parameters and returns values.

For example:

(int a, double b)->{
    return 4;
}

Since a lambda that satisfies #2 exists, any lambda is considered a function, even those that don't accept parameters:

()->{
    System.out.println("Lambda is running");
}
  1. N/A

I made a quick flowchart to categorize various bits of code (sorry for my lack of flowcharting skills):

A flowchart

Here is my definition of a function:

  1. A function must have the ability to be called by its name, object, reference, or other handle (this prevents code snippets). The only exception to this is the main method (or equivalent) of a program.
  2. A function must be able to pass around data by accepting parameters and returning values. If side-effects occur, the function shouldn't exploit them; any parameters should be arguments, and any results should use your language's equivalent of return.
  3. Multiple functions can be counted as one function, provided that each helper function meets the 2 previous conditions.

Lastly, as @Downgoat's answer says, if something is obviously not a function, then it shouldn't be treated as such.


A full program is any code that can be compiled, interpreted, or otherwise executed in a non-REPL environment without any modification. Note that some code can be classified as both functions and full programs.

Anything that is not either a function or a full program is a code snippet.


For an example, let's look at Java lambda expressions.
  1. You can assign a lambda expression to an object, so it passes the handle test.
  2. It is possible to write a lambda expression that accepts parameters and returns values.

For example:

(int a, double b)->{
    return 4;
}

Since a lambda that satisfies #2 exists, any lambda is considered a function, even those that don't accept parameters:

()->{
    System.out.println("Lambda is running");
}
  1. N/A

I made a quick flowchart to categorize various bits of code (sorry for my lack of flowcharting skills):

A flowchart

Modified for languages that don't have scope (js arrow functions)
Source Link
Daniel M.
  • 3.9k
  • 9
  • 8

Here is my definition of a function:

  1. A function must have the ability to be called by its name, object, reference, or other handle (this prevents code snippets). The only exception to this is the main method (or equivalent) of a program.
  2. A function must have its own scope.
  3. A function must be able to accept parameters and return values without the use of variablesany variable that is also used outside the scope of the function. In other words, a function must be capable of operating without side-effects.
  4. Multiple functions can be counted as one function, provided that each helper function meets the 32 previous conditions.

Lastly, as @Downgoat's answer says, if something is obviously not a function, then it shouldn't be treated as such.


A full program is any code that can be compiled, interpreted, or otherwise executed in a non-REPL environment without any modification. Note that some code can be classified as both functions and full programs.

Anything that is not either a function or a full program is a code snippet.


For an example, let's look at Java lambda expressions.
  1. You can assign a lambda expression to an object, so it passes the handle test.
  2. A lambda expression has its own scope.
  3. It is possible to write a lambda expression that accepts parameters and returns values.

For example:

(int a, double b)->{
    return 4;
}

Since a lambda that satisfies #3#2 exists, any lambda is considered a function, even those that don't accept parameters:

()->{
    System.out.println("Lambda is running");
}
  1. N/A
  1. N/A

I made a quick flowchart to categorize various bits of code (sorry for my lack of flowcharting skills):

A flowchart

Here is my definition of a function:

  1. A function must have the ability to be called by its name, object, reference, or other handle (this prevents code snippets). The only exception to this is the main method (or equivalent) of a program.
  2. A function must have its own scope.
  3. A function must be able to accept parameters and return values without the use of variables outside the scope of the function.
  4. Multiple functions can be counted as one function, provided that each helper function meets the 3 previous conditions.

Lastly, as @Downgoat's answer says, if something is obviously not a function, then it shouldn't be treated as such.


A full program is any code that can be compiled, interpreted, or otherwise executed in a non-REPL environment without any modification. Note that some code can be classified as both functions and full programs.

Anything that is not either a function or a full program is a code snippet.


For an example, let's look at Java lambda expressions.
  1. You can assign a lambda expression to an object, so it passes the handle test.
  2. A lambda expression has its own scope.
  3. It is possible to write a lambda expression that accepts parameters and returns values.

For example:

(int a, double b)->{
    return 4;
}

Since a lambda that satisfies #3 exists, any lambda is considered a function, even those that don't accept parameters:

()->{
    System.out.println("Lambda is running");
}
  1. N/A

I made a quick flowchart to categorize various bits of code (sorry for my lack of flowcharting skills):

A flowchart

Here is my definition of a function:

  1. A function must have the ability to be called by its name, object, reference, or other handle (this prevents code snippets). The only exception to this is the main method (or equivalent) of a program.
  2. A function must be able to accept parameters and return values without the use of any variable that is also used outside of the function. In other words, a function must be capable of operating without side-effects.
  3. Multiple functions can be counted as one function, provided that each helper function meets the 2 previous conditions.

Lastly, as @Downgoat's answer says, if something is obviously not a function, then it shouldn't be treated as such.


A full program is any code that can be compiled, interpreted, or otherwise executed in a non-REPL environment without any modification. Note that some code can be classified as both functions and full programs.

Anything that is not either a function or a full program is a code snippet.


For an example, let's look at Java lambda expressions.
  1. You can assign a lambda expression to an object, so it passes the handle test.
  2. It is possible to write a lambda expression that accepts parameters and returns values.

For example:

(int a, double b)->{
    return 4;
}

Since a lambda that satisfies #2 exists, any lambda is considered a function, even those that don't accept parameters:

()->{
    System.out.println("Lambda is running");
}
  1. N/A

I made a quick flowchart to categorize various bits of code (sorry for my lack of flowcharting skills):

A flowchart

Simplified rules a bit
Source Link
Daniel M.
  • 3.9k
  • 9
  • 8
Loading
Helper functions
Source Link
Daniel M.
  • 3.9k
  • 9
  • 8
Loading
Added clarification for point 4
Source Link
Daniel M.
  • 3.9k
  • 9
  • 8
Loading
Source Link
Daniel M.
  • 3.9k
  • 9
  • 8
Loading