Did You Know THIS Secret Kotlin Hack?

preview_player
Показать описание
Follow for more Kotlin & Android tips! 💻
#kotlin #kotlintips #androiddeveloper #android #androiddev #androidcoding #androiddevs #mobiledev #mobiledeveloper #mobiledevelopment #softwareengineering #softwareengineer
Рекомендации по теме
Комментарии
Автор

Funny story, on Saturday, as I was coming off anesthesia from surgery, my wife wrote down the things I was saying because they didn’t make sense to her. One was, “I wonder if I can export the Taipalese from a shared model in Collin.”

Then just now I was watching this Short and she overheard it and exclaimed that’s what I was talking about.

“I wonder if I can export the typealias from a shared module in Kotlin.”

BrandonJWSmith
Автор

i think value class looks better for this case instead of typealias

vzdwjrm
Автор

I've seen this in action in large code bases, and it really makes the code very hard to read and understand by other developers (specially if you declare this typealias in another file). IMO, its much better to wrap the data in either a value class or a data class.

sirlordpouya
Автор

Documentation also goes a long way so you dont have to have typealiases scattered around

javiere.gonzalez
Автор

You can use KDoc for example to document your code...

DenisKor
Автор

Similar feature is there for primitive type wrapping for a meaningful structure as value class. Slightly advanced form of data class

shrinivasmanjithaya
Автор

Ty for the info, but I think if the Int value is known to be a convention, then this step would make things harder to understand, especially when someone deals with a "NoteId" type as an Int!

ahmadhamwi
Автор

Android devs be like: check out this secret data structure! Do you know what enum is? It stands for enumeration 😅

Lonkly
Автор

But typealias is not compile safe. Nothing will stop you passing different aliased Id. Better way is using value class or data class (depending if the usage is in kmm since value classes don't work here). This way the compiler won't let you pass different Id class

tomasglazr
Автор

Yep. :) Though, to be more correct, this isn't a "hack" it's more of a language feature that many aren't aware of, I'd say. Perhaps also mention the visibility of the typealias -- which is also public, correct?

dakopyc
Автор

I like typealias as much as I hate them, from first side it’s look good but when you join some new project it’s kinda frustrating until you start feel confident of project typealias glossary

ivantrifonov
Автор

cpp programmers be like: meh😏, we use typealies to make our code unreadable😅

islomsheraliyev
Автор

I don't know why but in my code editing pannel Gemini not give me suggestions even I give her permission in settings

vikashkushwahinfo
Автор

In old good C it would be
typedef int NoteId
What's the point in introducing new keyword instead of using existing?

czajla
Автор

But I think Result(inserted row id) should be in Long

Sandy-dzqz
Автор

I think it is better to avoid introducing useless new types, it only makes the code harder to understand. Type aliases exist in many other languages, but they are rarely used

tcl
Автор

If you think this is a secret hack you need to study fundamentals more

o_glethorpe
Автор

Everyone knows this, stop saying stuff like "Not many know" / "I am sure none of you know this" click baits

aabhishek