You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When #239 lands we'll have support for SomeContract.create(..) and SomeContract.create2(..) which can both be thought as being static methods on a contract type. We should change static call syntax to use double colon syntax instead. To stick to the given examples, they would look like SomeContract::create(..) and SomeContract::create2(..)
Rational:
It clearly separates instance function calls from static function calls
It follows Rust syntax which we prefer to use over Python syntax in situations where we believe Rust syntax brings a clear benefit to the table
This will also work nicely with struct factory methods as demonstrated with the following example taken from #96
struct Rectangle:
width: u256
height: u256
# Static method to create a rectangle that happens to be a square
def square(size: u256) -> Rectangle:
Rectangle(width=size, height: size)
# An instance method to check if the rectangle can hold another rectangle
def can_hold(self, other: Rectangle) -> bool:
return self.width > other.width and self.height > other.height
Taking self as the first parameter is what would decide whether something is a static method or an instance method (just like in Rust)
Usage:
big = Rectangle(width=10, height=20)
square = Rectangle::square(5)
big.can_hold(square)
The text was updated successfully, but these errors were encountered:
What is wrong?
When #239 lands we'll have support for
SomeContract.create(..)
andSomeContract.create2(..)
which can both be thought as being static methods on a contract type. We should change static call syntax to use double colon syntax instead. To stick to the given examples, they would look likeSomeContract::create(..)
andSomeContract::create2(..)
Rational:
This will also work nicely with struct factory methods as demonstrated with the following example taken from #96
Taking
self
as the first parameter is what would decide whether something is a static method or an instance method (just like in Rust)Usage:
The text was updated successfully, but these errors were encountered: