Video summary

Kotlin Basics || Display Book function || Humble Coders

Main summary

Key takeaways

Technology

Tech/product concepts covered (Kotlin)

Function creation for library management

  • Defines a function like displayBooks to print/display the books stored in a library.
  • Emphasizes that the function’s job is to act on the existing data (a list of Book objects).

CamelCase naming convention

  • Explains camelCase for function/variable names:
    • First word starts lowercase
    • Subsequent words start uppercase (e.g., displayBooks)
  • Notes this is an industry standard and contrasts with other conventions (e.g., PascalCase mentioned later).

Using list types with Kotlin generics

  • The library variable is described as a List<Book>.
  • The function iterates through that list and displays each Book.

Return type / Unit concept

  • Clarifies that if a function only prints and doesn’t compute a meaningful value to return, it doesn’t need an explicit return type.
  • Notes Kotlin’s Unit exists for “doesn’t return anything meaningful,” but the example avoids writing it explicitly.
  • Key idea: after a function runs, its results are either printed or stored; this example is printed.

Iteration with for loop over a list

  • Uses a loop like for (temp in library) (conceptually similar to for book in library).
  • Explains that the loop variable (e.g., book, later renamed to Temp) is a temporary variable representing the current item from the list.
  • Highlights that the loop variable is used to access fields of each Book object.

Data class usage

  • The Book is treated as a data class containing multiple properties (e.g., title, author, publishYear).
  • Demonstrates accessing fields via the dot operator, such as:
    • Temp.title
    • Temp.author
    • Temp.publishYear

String interpolation for formatted output

  • Uses string interpolation (e.g., $...) to build readable lines for each book (title/author/publish year).
  • Explains that the loop prints each object’s information until the list ends.

Function calling with required parameters

  • Since the function doesn’t return anything, it’s called directly (not assigned to a variable).
  • The function requires an input parameter: a list of books (passed as library in the example).

Code reuse vs duplication

  • Emphasizes the benefit of functions: printing the book list once instead of repeating the same formatting/loop logic in multiple places.

Main speakers/sources

  • Humble Coders (channel/source referenced in the video title)

Original video