[docs] <Omit local variable types?> #3307
Replies: 5 comments
-
Ah yes, that makes sense from reading that doc. Not sure however about the linter, could be quite restrictive, sometimes you may want to add a type for readability purposes. |
Beta Was this translation helpful? Give feedback.
-
The issue with not providing local types is that with documentation, it's sometimes tricky to read if you don't know the returned type. |
Beta Was this translation helpful? Give feedback.
-
That's a good point. I just want to point out that for the official Firebase documentation, the Kotlin version also omits the types for the local variables. For example: https://firebase.google.com/docs/auth/android/google-signin#kotlin+ktx private fun firebaseAuthWithGoogle(idToken: String) {
val credential = GoogleAuthProvider.getCredential(idToken, null)
auth.signInWithCredential(credential)
.addOnCompleteListener(this) { task ->
if (task.isSuccessful) {
// Sign in success, update UI with the signed-in user's information
Log.d(TAG, "signInWithCredential:success")
val user = auth.currentUser
updateUI(user)
} else {
// If sign in fails, display a message to the user.
Log.w(TAG, "signInWithCredential:failure", task.exception)
// ...
Snackbar.make(view, "Authentication Failed.", Snackbar.LENGTH_SHORT).show()
updateUI(null)
}
// ...
}
} I think from my experience, I rarely care about the types for local variables. And omitting them makes the code more concise. Maybe we can keep the types for variables that are meant to be returned? |
Beta Was this translation helpful? Give feedback.
-
So what should we do? If we don't want to remove the annotations, I'll just close this issue😄 |
Beta Was this translation helpful? Give feedback.
-
Personally I prefer them being visible on documentation as it makes its clearer what types are being used and helps if you wanted to lookup a certain type in the reference documentation. But I agree the docs should be consistent in this case. We would love to see PRs for improving the documentation, theres an edit button at the bottom of every page that will take you were you need to go 🤓 and PRs are getting reviewed and merged fairly quickly now. |
Beta Was this translation helpful? Give feedback.
-
Is your feature request related to a problem? Please describe.
Thanks for providing the amazing new documentation!
While reading through the docs, I noticed that the usage of type annotations for local variables is not consistent.
For example, in the GitHub auth section: https://firebase.flutter.dev/docs/auth/social#github,
we omitted the type for
result
but not other variables.But according to Effective Dart, we should AVOID type annotating initialized local variables: https://dart.dev/guides/language/effective-dart/design#avoid-type-annotating-initialized-local-variables. And there's also the linter rule "omit_local_variable_types": https://dart-lang.github.io/linter/lints/omit_local_variable_types.html.
Describe the solution you'd like
So should we modify the docs by removing all the type annotations for local variables?
Additional context
Beta Was this translation helpful? Give feedback.
All reactions