Did You Know About THIS Kotlin Feature?

Did You Know About THIS Kotlin Feature?

Philipp Lackner

1 год назад

16,360 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Camilo Hernández Ruiz
Camilo Hernández Ruiz - 03.10.2023 04:44

I use them to clean the code in large functions. If anything goes wrong, the stack trace tells me the name of the inner function.

Ответить
Rin
Rin - 21.08.2023 23:32

too lazy to cut the last bit of this video off? lol same

Ответить
n1
n1 - 20.07.2023 02:46

It’s good for a cleaner code but you didn’t mention whether nested function able to access outer function’s local variables

Ответить
Vinay Rajagopal
Vinay Rajagopal - 22.06.2023 17:40

It's also quite useful to do recursive actions without modifying the outer function's parameters.

I also like to use it when I need to do a "helper" method that does the bulk of the work, we can avoid passing arguments from the outerscope.

Ответить
saif ahmed
saif ahmed - 24.05.2023 17:59

what about lamda functions i use it in this scenario instead of that normal fuction
is there is a diff ?

Ответить
Chase
Chase - 05.05.2023 13:03

It's a pretty common pattern in compose

Ответить
Chris Athanas
Chris Athanas - 05.05.2023 07:18

I like to use nested functions for helper functions that break up proceases without having to use comments.

Ответить
Rog
Rog - 05.05.2023 05:01

Should have cut out the last second 😅

Ответить
Narslimmus
Narslimmus - 04.05.2023 23:26

Why not just make a private function in the same file?

Ответить
Богдан Дерига
Богдан Дерига - 04.05.2023 22:25

I just use lamda variable in this case

Ответить
Asuras
Asuras - 04.05.2023 22:11

Its quite useful when dealing with recursive functions as you can have one function which accepts the start parameters and have an inner function for the actual recursive call with an accumulator initialized. Also works great when writing tailrec functions

Ответить
mo sayed
mo sayed - 04.05.2023 22:07

I use a lot, even if not repetitive code, like if a function does multiple tasks, and each task is a big chunck of code, then I move each chunck into an inner function, makes the code readable for me

Ответить
Ryszard Machmudow
Ryszard Machmudow - 04.05.2023 21:56

Useful in Composable functions, when you do not want to pass many parameters to nested function

Ответить
Anthony H
Anthony H - 04.05.2023 20:05

You could also put it in a lamda.

I.e:
val addNumbers: (Int, Int) -> Int = { x, y -> x + y }


val result = addNumbers(2, 3) // result = 5


Looks cleaner imo

Ответить
Darwin Delgado
Darwin Delgado - 04.05.2023 17:30

what is better, lambas inside a function or nested functions?

Ответить
//
// - 04.05.2023 16:52

I still do not see the use of it being a nested function. Need to understand it better.

Ответить
CYPHERX
CYPHERX - 04.05.2023 16:30

Kotlin is the best language.

Ответить
Muhammad Safi Ullah
Muhammad Safi Ullah - 04.05.2023 16:25

Hmmm

Ответить
Saikou
Saikou - 04.05.2023 16:00

oh nice cool. ishlarizga omad . hamma video va contentlaringiz ajoyib va foydali.

Ответить
Dmytro Omelchenko
Dmytro Omelchenko - 04.05.2023 15:54

Really useful feature for me.

Ответить
Oubihi Noureddine
Oubihi Noureddine - 04.05.2023 15:40

Nice trick, I once had a scenario where this could be useful and was thinking if it's possible 😂

Ответить
Tatavarthi Tarun
Tatavarthi Tarun - 04.05.2023 15:25

Interesting but still it looks wrong to me 😅, may be we need to get used to it

Ответить
Mr Jackson
Mr Jackson - 04.05.2023 15:16

that's mindblowing!

Ответить