![]() The general guidance in type-inferred languages is to specify the types of functions, so your interface is more stable, and so programmers don't have to read your entire function body in order to know how to call it. My understanding is type inference gets run no matter what, and if you explicitly specify types, it just checks that the specified type unifies with the expected type. I don't believe there's an effect on build times. Is there any kind of well regarded convention on when we should include them in Kotlin? I believe in the Haskell community where type declarations are also optional, it's considered a good idea to always explicitly declare the types of functions. I know the Kotlin coding conventions say to include them in the interface of a library, which makes sense but doesn't apply to most of my code. On the other hand, there are a couple of benefits of not including type declarations: I haven't found a definitive answer on how big an effect it has though. It makes the code more explicit and therefore more clear.It sometimes makes type errors more understandable as when types don't match it helps the compiler determine which is wrong and which is right.I've encountered a few benefits of including them: In Kotlin, specifying the return types of functions and the types of variables is usually optional but can be optionally included.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |