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

Update Meta Standard to include snake case method names as a standard #96

Open
ilblackdragon opened this issue Jul 18, 2020 · 13 comments
Open
Assignees

Comments

@ilblackdragon
Copy link
Member

We need to define which naming convention standards suppose to follow:

  • Snake case for Rust
  • Camel case for AS/TS/JS & Ethereum

Specifically, it's important because frontend is mostly in JS and expectation is that all calling of arguments will be in Camel Case. While Rust is enforcing Snake case.

I think we can lean toward Camel case to maintain compatibility with frontend and Ethereum standards and add whatever flags required in Rust to enforce that instead of Snake case. This though requires among other things adjusting our Fungible Token standard.

Thoughts?

@MaksymZavershynskyi
Copy link
Contributor

MaksymZavershynskyi commented Jul 18, 2020

We can do both. Every contract method can be exposed in both camel and snake case, it is a tiny modification to near-sdk-rs and will have a negligible effect on contract size.

@MaksymZavershynskyi
Copy link
Contributor

Specifically, currently for each impl method my_method(&self, args..) near-sdk-rs generates method my_method(). It should generate three methods: _my_method(), my_method() { _my_method() }, and myMethod() { _my_method() }. It already exports inflector for converting between snake case and camel case https://github.com/near/near-sdk-rs/blob/master/near-sdk-core/Cargo.toml#L18 .

@MaksymZavershynskyi
Copy link
Contributor

Closing in favor of near/near-sdk-rs#209

@ilblackdragon
Copy link
Member Author

ilblackdragon commented Jul 25, 2020

We still need the guideline for standards. The standards is what people will be using when composing contracts and using them from frontend.

E.g. when writing code like this should work with ANY contract in the future: https://github.com/ilblackdragon/balancer-near/blob/master/balancer-pool/src/btoken.rs#L127

@ilblackdragon ilblackdragon reopened this Jul 25, 2020
@MaksymZavershynskyi
Copy link
Contributor

MaksymZavershynskyi commented Jul 26, 2020

This issue does not explain why we need standard, if near-sdk-* can expose all contract methods in both camel and snake case.

For example. Alice writes Rust contract

#[near_bindgen]
impl AliceContract {
  pub fn alice_method() {
  }
}

Bob writes AS contract:

export function bobMethod(): void {
}

Then anyone can call Alice's contract from near-api-js as contract.aliceMethod or contract.alice_method. Similarly anyone can call Bob's contract from near-api-js as contract.bobMethod or contract.bob_method. Similarly, anyone can call them by snake or camel case from other contracts.

How standardization or guidelines would be useful here?

@robert-zaremba
Copy link
Contributor

robert-zaremba commented Jul 29, 2020

IMHO, generating additional names only create confusions. I like styles and naming conventions. I don't see much reason of duplicating names through SDK. Especially, that it will incure extra gas cost.

@ilblackdragon
Copy link
Member Author

This issue does not explain why we need standard

We need standard because we have standards - https://nomicon.io/Standards/Tokens/FungibleToken.html#reference-level-explanation.
And these standards have naming convention that both contracts and off-chain code will be using.
We definitely should not list two sets of names in those standards (and if we do ===> that's a standard too, and AS, Go, Haskell, whatever other language contracts must implement them as well).

@ilblackdragon
Copy link
Member Author

This is more critical then before with 141 finalization.
@evgenykuzyakov @robert-zaremba Are we committing that all standards should be using snake case?

@zahhar
Copy link
Contributor

zahhar commented Feb 21, 2021

Both approaches (duplicate method names or stick to single style) look wrong for me.

How about removing the root cause of a problem by sticking to single-word names for common methods, and leaving complete freedom for user-defined methods?

Here is what I mean: in both Rust, AS or what-so-ever-language-NEAR-is-gonna-support-in-the-future we can write all public methods required by standard this way:

export function transfer() and pub fn transfer() that will be called using any kind of SDK as contract.transfer

It is a matter of finding enough single-word names for a handful of mandatory methods.

And when it comes to private methods, or to contract-specific methods, there should be no limit imposed how to name things. Anyhow developer working with contract must familiarise himself with its interfaces.

@oysterpack
Copy link

sticking to single-word names for common methods

That simply won't work because all contract functions are effectively scoped globally. NEAR standard API interfaces must be namespaced to avoid collisions.

The problem is that the NEAR library ecosystem is pretty much non-existent at this phase of the lifecycle. Think of defining the JSON RPC API just like defining any HTTP API. Regardless which route you go, i.e., REST, GraphQL, etc, the HTTP API is too low level to work with. Higher level client libraries, frameworks, and tooling is lacking in the NEAR ecosystem. This is what we need to make developers productive and accelerate time to market.

I have said this before multiple times on multiple other posts ... and I'll keep saying it until the idea sticks ...

As for NEAR standard APIs .. the bottom line is

"Talk is cheap. Show me the code" - Linus Torvalds

I would argue that at a minimum, the NEAR DEV team is responsible for delivering on the high level libraries for every NEAR standard API by any means necessary. If the NEAR DEV team does not have the personnel and time to develop them internally, then I propose that the NEAR DEV team tap into the NEAR developer community through bounties, guilds, and partners.

It's a chicken and egg problem ...

@evgenykuzyakov
Copy link
Contributor

Let's just with snake_case since we're going for mostly Rust. near-api-js can expose methods in camelCase while calling contract in snake_case.

@robert-zaremba
Copy link
Contributor

This is more critical then before with 141 finalization.
@evgenykuzyakov @robert-zaremba Are we committing that all standards should be using snake case?

Yes. Having a single style for standards has a benefit in readability. As @evgenykuzyakov - for whatever reasons, libraries can do the translation if needed.

@ilblackdragon ilblackdragon changed the title Decide on naming convention for standards Update Meta Standard to include snake case method names as a standard Mar 2, 2021
@ilblackdragon
Copy link
Member Author

Let's publish this as part of meta-standard here in NEPs.
Also this should be followed up by work in near-sdk-as to export the snake case function names: near/near-sdk-as#430

FYI @mikedotexe

I do want to mention that camelCase is actually more compact (less bytes on chain :D) and leave this topic silent forever.

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

7 participants