Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚀 Feature: Make .NET SDK and code examples feel more authentic and remove anti-patterns. #2926

Closed
2 tasks done
gewenyu99 opened this issue Mar 8, 2022 · 7 comments
Closed
2 tasks done

Comments

@gewenyu99
Copy link

🔖 Feature description

The .NET SDK has issues with code examples and SDK generated. Code use is not authentic to the language and contains anti-patterns. Here are some example:

string path = "/database/collections/{collectionId}".Replace("{collectionId}", collectionId);
Should be:
string path = $"/database/collections/{collectionId}";

And

client
    .setEndpoint('http://[HOSTNAME_OR_IP]/v1') // Make sure your endpoint is accessible
    .setProject('5ff3379a01d25') // Your project ID
    .setKey('cd868c7af8bdc893b4...93b7535db89')
    .setSelfSigned() // Use only on dev mode with a self-signed SSL cert

Uses "Java-esque setXXX() idioms in C#." This is considered an anti-pattern.

use proper properties instead. For reference see ASP.NET's startup and Options code examples.

We could use our community's help here, to suggest similar issues with good code practice in the examples and generated SDK we provide.

🎤 Pitch

As mentioned by Reddit user f-berasategui, our .NET SDK feels like it's "written by a Java person." We should strive to have each SDK feel authentic to it's user base, and we should try to make changes to examples and SDK generator to make this happen. We need to avoid anti-patterns.

https://www.reddit.com/r/programming/comments/t9gmn1/comment/hzugo45/?utm_source=share&utm_medium=web2x&context=3

👀 Have you spent some time to check if this issue has been raised before?

  • I checked and didn't find similar issue

🏢 Have you read the Code of Conduct?

@gewenyu99
Copy link
Author

I think this is an issue worthy of discussion, would love to hear what other C# users in our community think.

@tty418
Copy link

tty418 commented Mar 11, 2022

Regarding the Client example you gave above (similar to https://github.com/appwrite/sdk-for-dotnet#initialize--make-api-request ):

I see two viable options here. The first one is using a ClientBuilder that then 'builds' the client:

(1) Using the builder pattern (nothing specific to C#), note the capitalized method names (this is C# specific):

  var cb = new ClientBuilder();

  var client = cb
    .SetEndpoint('http://[HOSTNAME_OR_IP]/v1') 
    .SetProject('5ff3379a01d25')
    .SetKey('cd868c7af8bdc893b4...93b7535db89')
    .SetSelfSigned()
    .Build() // note the call to build, which 'finalizes' the builder and generates a valid instance of Client
  ;

(2) Using C# properties:

  var client = new Client(); // using the Client constructor

  client.Endpoint = "http:https://[HOSTNAME_OR_IP]/v1";
  client.Project = "5ff3379a01d25";
  // etc

Properties are basically syntactic sugar and avoid us having to add all the clunky getter/setter methods you would see in e.g. Java.

Also note that im creating a new instance of Client using the constructor. Static methods are only useful as 'factories' but in the example above, there is nothing special (eg arguments) about the call. The constructor can (should) be used for simple initialization and dependencies or mandatory parameters can be declared on it.
@gewenyu99

@gewenyu99
Copy link
Author

@TorstenDittmann @adityaoberai Thoughts?

@adityaoberai
Copy link
Member

adityaoberai commented Mar 15, 2022

With C#, I personally prefer using properties as well. But I don't think the example shown above will be the best way forward for us considering that aside from the Endpoint, other properties like Project, Key, or JWT are not independent primitive properties but a part of the headers and config dictionaries, which can be seen in the Client.cs file in the SDK. In this scenario, I do believe that the abstraction provided by the setXXX functions makes life a little easier for the developer. That being said, I am relatively a novice developer and would love more thoughts on this too.

@myThorsten
Copy link

myThorsten commented Oct 28, 2022

May I ask where I can find the .NET SDK? It isn't mentioned in the docs under https://appwrite.io/docs/.
Or does this issue refer to https://github.com/appwrite/sdk-for-dotnet. In that case, is there a roadmap as to when an updated SDK for appwrite 1.0 is expected?
Thanks :)

@adityaoberai
Copy link
Member

May I ask where I can find the .NET SDK? It isn't mentioned in the docs under https://appwrite.io/docs/. Or does this issue refer to https://github.com/appwrite/sdk-for-dotnet. In that case, is there a roadmap as to when an updated SDK for appwrite 1.0 is expected? Thanks :)

The issue does refer to the sdk-for-dotnet repo, which is currently out of date. A .NET server-side SDK is under the works, however, and you can track progress on this PR here in our SDK Generator repo.

@joeyouss
Copy link

Closing this issue since the PR : appwrite/sdk-generator#320 is now merged 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants