Video summary

Kotlin Basics || Functions || Humble Coders

Main summary

Key takeaways

Educational

Main ideas / concepts conveyed

  • Functions are presented as an essential programming concept (especially in Kotlin) that helps avoid repeating the same code many times.
  • A function is likened to a “function machine”:
    • Inputs: the parameters (e.g., a and b)
    • Process: the logic inside the function body (e.g., a + b)
    • Output: the computed result (e.g., c)
  • The video emphasizes the time-saving benefit:
    • Instead of rewriting the same few lines thousands of times, you define the logic once and reuse it.

How functions are created (methodology / step-by-step)

  • Function definition structure

    • Start with the keyword: fun
    • Provide a function name (example given: add)
    • Use round brackets (...) for parameters
    • Use curly braces { ... } for the function body
  • Parameters (inputs)

    • Inside the round brackets, define parameters with:
      • a chosen parameter name (e.g., number1, number2)
      • a type (example given: : Int)
    • Multiple parameters are separated by commas.
    • The names used in the function definition are what the function body refers to, but callers can pass values regardless of the caller’s variable names.
  • Return type and return value (output)

    • After the round brackets, specify the function’s return type using : <type> (example: : Int).
    • In the function body, output the result using return <value> (example: return c).
    • The video stresses that the return type must match what the function actually returns.

How functions are called (using the function)

  • To use a function that returns a value:
    • Store the return value in a variable, because the function produces output.
  • Example idea described:
    • Call the function with arguments inside parentheses, e.g. add(10, 20)
    • Assign the result to a variable like c = add(10, 20)
  • The video contrasts:
    • Function definition (writing the logic once)
    • Function calling (using the logic repeatedly in one line)

Practical takeaway / lessons

  • Write the “hard” or repeated logic inside a function once.
  • When a function returns something, assign that result to a variable before printing/using it.
  • Parameter naming inside the function definition doesn’t limit how the caller labels its values—only the types and order of inputs matter.

Speakers / sources featured

  • No specific named speaker identified in the subtitles (appears to be an unnamed video instructor/host).

Original video