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

Suggestion to Standardize SDK Initialization Method Naming #39

Closed
dimitrianoudi opened this issue Oct 25, 2023 · 6 comments
Closed

Suggestion to Standardize SDK Initialization Method Naming #39

dimitrianoudi opened this issue Oct 25, 2023 · 6 comments

Comments

@dimitrianoudi
Copy link

I've been going through the documentation for the SDK drivers for our database, and I've noticed a discrepancy in the way we initialize a new host across different languages. Specifically, in the .NET SDK, we currently use SurrealDbHttpClient.New(host) for initialization. In contrast, other languages' documentation frequently employs the .init() convention.

To maintain consistency and predictability for developers familiar with other SDKs or expecting a more standard initialisation method, I'd like to suggest renaming the method from:

SurrealDbHttpClient.New(host)

to

SurrealDbHttpClient.Init(host)

@Odonno
Copy link
Contributor

Odonno commented Oct 25, 2023

Weird, on most packages, the method is named new.

In Rust:

let db = Surreal::new::<Ws>("127.0.0.1:8000").await?;

In Golang:

db, err := surrealdb.New("ws://localhost:8000/rpc")

For information, I tried to stay as close as possible to the Rust SDK.

And IMO, Init feels more confusing than New to me. Does Init also execute Connect or not?

@dimitrianoudi
Copy link
Author

It's very confusing to have so many constructors. Maybe make the following one's private and not documented.
SurrealDbHttpClient.New(host)
SurrealDbHttpsClient.New(host)
SurrealDbWsClient.New(host)
SurrealDbWssClient.New(host)

@simon-curtis
Copy link
Contributor

Agreed, I think it would make more sense to be able to pass this into a generic factory method and it returns ISurrealDbClient.

SurrealDbClient.New("ws://localhost:8000/rpc") should return a SurrealDbWsClient

I also found it quite confusing that the first parameter in the SurrealDbWsClient constructor doesn't accept a full connection string as the first parameter.

@Odonno
Copy link
Contributor

Odonno commented Nov 28, 2023

Now, I can understand your point of view.

I made those extra functions for the following reasons:

  1. Made as static so that we can call the function anywhere. But we can call the new SurrealDbClient() everywhere too. So, not a real benefit here.
  2. Trying to mimic the let db = Surreal::new::<Ws>("127.0.0.1:8000").await?; Rust version of the statically instance. But, like point 1, no real benefit for C# developers.
  3. As a syntactic sugar form, where you only have to pass the minimum info required for the type you know you will need (WS, HTTP).

So, like you both are trying to say. If there is no value, we can definitely get rid of it.

@Odonno
Copy link
Contributor

Odonno commented Mar 21, 2024

For information, those static methods are gone from at least v0.3.

@Odonno
Copy link
Contributor

Odonno commented Mar 21, 2024

PR #58 for reference

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

4 participants