-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Introduce a real constant keyword and rename the current behaviour #992
Comments
This seems like the wrong word; |
I'm trying to find the word and stateless ia far from perfect. It should describe that the state is not modified. Also additionally we could introduce real constant functions, which are indeed stateless and dont depend on the state. I.e. calculating something based on the inputs. |
Well, from a CS-theoretic POV, 'pure' is definitely the term you want. More informally, 'side effect free', but that's harder to condense into a keyword. |
I think 'immutable' will be the least ambiguous to most developers. |
I like pure, but are we likely to find another use for it? Does view as keyword make sense? |
@redsquirrel immutable wouldmean to me that child classes cannot ovveride it. |
@axic I suggest following Java and using 'final' for functions that cannot be overridden. |
I don't think so; certainly this is the only usage for the term I'm aware of.
I don't think that was under discussion here? |
I agree that we should use pure...perhaps |
|
too long...overly blunt descriptive. Less is more imo. |
|
what's wrong with |
Many of the definitions of Therefore it does not suit our application. @VoR0220 Updated the description with further clarification which should help coming up with a good name. |
hmmm...so I like that idea in regards to |
The problem with |
right but the output does. Perhaps you could create such a differentiation. You might do something like this
|
@VoR0220 it is not the output or the function which is mutable/immutable. Case 1: function can read state variables (sload). The output of this function will depend on the current state. Case 2: function can modify state variables (sstore). The output of this function will depend on the current state, as well as it can change the state, which then affects any future invocations. I've borrowed |
Can we agree that the behaviour called |
I don't see much need for
Doesn't the current proposal fit I think the 4 proposals are good. No one else has made comments about
|
Sorry for the confusion, the description was updated after those comments. For 1) I like |
Yes, you're right - I stand corrected. RE constant/volatile/etc, besides dropping the functionality (which seems good to me), why not call it 'alias' or 'define'? That seems to be effectively what it is. |
I think that I updated the description to specify the behaviour in more detail. Question: Can a pure function return From the keywords: The problem with |
@chriseth moved
That is a good question. I would argue that it is more useful to allow Storage should not be accessed by |
I think we more or less found that our framework is not yet fully specified because pure functions might modify memory. My current proposal would be the following: view and pure are attributes applied to the function, and they only concern storage and other permanent state. So in essence, "view" and "pure" apply to "this" (and other state including other contracts) and all other input variables have their own specifiers. |
I suggest the new name as contract LockableCoin is AbstractCoin {
//creation time, defined when contract is created
uint public creationTime = now;
//time constants, defines epoch size and periods
uint public constant UNLOCKED_TIME = 25 days;
uint public constant LOCKED_TIME = 5 days;
uint public constant EPOCH_LENGTH = UNLOCKED_TIME + LOCKED_TIME;
//current epoch constant formula, recalculated in any contract call
uint public constant CURRENT_EPOCH = (now - creationTime) / EPOCH_LENGTH + 1;
//next lock constant formula, recalculated in any contract call
uint public constant NEXT_LOCK = (creationTime + CURRENT_EPOCH * UNLOCKED_TIME) + (CURRENT_EPOCH - 1) * LOCKED_TIME;
//(...)
} From https://github.com/ethereans/github-token/blob/master/contracts/LockableCoin.sol |
Why word volatile being not considered? I see use cases for this, and its really useful and easy to understand. Volatile are expressions that result a value change due contract storage, chain or call variables change.
I was first fooled by a constant owner that changed in any call, but using a special keyword for this case makes sense. |
I like to restrict the number of keywords as much as possible, especially if there is another solution that does almost the same thing. |
Related: #2181 |
Here is a summary of the current design: There's enum for view:
pure:
Remarks:
|
This is finally implemented and documented. To only thing left is enforcing these restrictions and that is tracked in #2606. |
What version is this implemented in? |
@fulldecent I believe |
Is it normal behavior for a It make sense architecture-wise, but is this intended and will be doubled down on? |
A |
#992) * Give more instructions on the author field with format for email addresses and Github usernames * comma separated authors * colon
I think the following makes more sense compared to what we have now.
Now:
constant
function should not modify the state (not fully enforced yet)constant
state variable (ie. the one in the class and not in a method) is evaluated every time it is calledAfter the change:
view
is introduced for functions (it replacesconstant
). Calling aview
cannot alter the behaviour of future interactions with any contract. This means such functions cannot useSSTORE
, cannot send or receive ether and can only call otherview
orpure
functions.pure
is introduced for functions, they areview
functions with the additional restriction that their value only depends on the function arguments. This means they cannot useSSTORE
,SLOAD
, cannot send or receive ether, cannot usemsg
orblock
and can only call otherpure
functions.constant
is invalid on functionsconstant
on any variable means it cannot be modified (and could be placed into memory or bytecode by the optimiser)5) the keyword[agreed to remove this functionality]volatile
is introduced for variables, which read their referenced value every time (this is whatconstant
does today to variables)Any example of the
volatile
keyword:I'm not sure the
volatile
option is useful and thus we might decide to remove it.The text was updated successfully, but these errors were encountered: