sdk-for-flutter icon indicating copy to clipboard operation
sdk-for-flutter copied to clipboard

πŸ› Not a Bug Report: There are two different Account classes

Open vrescobar opened this issue 3 years ago β€’ 2 comments

πŸ‘Ÿ Reproduction steps

There are two accounts: models.Account and appwrite.Account

πŸ‘ Expected behavior

While this is not an actual bug, it is annoying to say the least, and usually a bad practice. I would like to propose to refactor appwrite.Account (services/Account.dart) to AccountService and avoid name clash in the files that both definitions are needed.

πŸ‘Ž Actual Behavior

Unambiguous naming is hard, and I ended up with quite long refactoring due autoimports and large misunderstanding.

🎲 Appwrite version

Version 1.0.x

πŸ’» Operating system

MacOS

🧱 Your Environment

Flutter

πŸ‘€ Have you spent some time to check if this issue has been raised before?

  • [X] I checked and didn't find similar issue

🏒 Have you read the Code of Conduct?

vrescobar avatar Sep 19 '22 07:09 vrescobar

Perhaps it is between bug (usability) and enhancement.

vrescobar avatar Sep 19 '22 07:09 vrescobar

@vrescobar this is the downside of language that doesn't support namespace. We don't want to switch to AccountService for the sake of consistency across our SDKs and platforms. And we don't yet have a better solution than this where you can import import package:appwrite/models.dart as models to avoid name clash. Let us know if you have other better suggestions, which can help us be consistent and provide better usability as well.

lohanidamodar avatar Sep 21 '22 02:09 lohanidamodar

I can totally understand your point, and yes, I also import it as models. However still a week after, having a class instance that returns an object of a class with the same name lead me to many subtle messes during this last week, even being aware of it.

Another option could be renaming the user account to User or Profile, perhaps that could also make sense in the other frameworks as it is often recommended in semantic maps to have different names for different concepts.

Sure that you may want to just close here now this not-a-bug report as many more options aren’t there, but here lays my feedback.

Atentamente/ Kind regards/ mit freundlichen Grüßen

VΓ­ctor R. Escobar vrescobar.com

On 21. Sep 2022, at 04:38, Damodar Lohani @.***> wrote:

ο»Ώ @vrescobar this is the downside of language that doesn't support namespace. We don't want to switch to AccountService for the sake of consistency across our SDKs and platforms. And we don't yet have a better solution than this where you can import import package:appwrite/models.dart as models to avoid name clash. Let us know if you have other better suggestions, which can help us be consistent and provide better usability as well.

β€” Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.

vrescobar avatar Oct 11 '22 06:10 vrescobar

or the sake of consistency across our SDKs and platform

I feel consistency must come second if it causes way worse side effects like code that does not compile and needs extra code in many places. This causes way more other inconsistencies in the code.

biovolt avatar Oct 11 '22 19:10 biovolt

I totally agree with this, code generation and consistency is great, but this inconvenience is really not very pleasant

M123-dev avatar Jan 02 '23 13:01 M123-dev

we can access the Service class by defining a custom Type for the Account.

// access Account using AccountService Type
typedef AccountService = Account

class Account extends Service {
// . . .
}

Using the above approach would solve this issue and also it won't affect existing written programs that use this class.

i want to contribute.

jasimameen avatar Jan 29 '23 16:01 jasimameen

The SDK now uses User instead of Account:

https://github.com/appwrite/sdk-for-flutter/blob/54f30faa4a4fab2af0fe57c172550b288c9cbb4b/lib/src/models/user.dart#L4

stnguyen90 avatar Apr 18 '23 17:04 stnguyen90