Video summary
Kotlin Basics || Display Book function || Humble Coders
Main summary
Key takeaways
Tech/product concepts covered (Kotlin)
Function creation for library management
- Defines a function like
displayBooksto print/display the books stored in a library. - Emphasizes that the function’s job is to act on the existing data (a list of
Bookobjects).
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
libraryvariable is described as aList<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
Unitexists 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 tofor book in library). - Explains that the loop variable (e.g.,
book, later renamed toTemp) is a temporary variable representing the current item from the list. - Highlights that the loop variable is used to access fields of each
Bookobject.
Data class usage
- The
Bookis treated as a data class containing multiple properties (e.g.,title,author,publishYear). - Demonstrates accessing fields via the dot operator, such as:
Temp.titleTemp.authorTemp.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
libraryin 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)