Here is an article on Ethereum: When to use «permanent» and «unchanging»:
When to use ‘permanent’ and ‘unchanged’ in ethereum
When writing intelligent contracts on Blockchain Ethereum, developers must carefully consider when to use keywords «permanent» and «unchanging». In this article, we will examine the differences between these two key words and provide scenarios in which one or both are appropriate.
continuous keyword
The «permanent» keyword is used to declare variables that should not be changed after initialization. These variables can be used for permanent calculations, buffering or other goals in which the value remains the same throughout the life of the contract.
`Solidity
// Uint256 Public minimum public_usd = 50 * 1e18;
Here are a few scenarios in which «stood» is useful:
- Calculation of fixed: If you need to calculate a specific value that does not change over time, use a fixed one.
- Buffing data: If the contract must remember to often access the value, use a permanent.
- Returning permanent: When returning permanent from the function, use a permanent.
unchanging keyword
The «unchanging keyword» is used to declare variables that can never be changed after initialization. These variables are unchanged due to design and should not be modified after creation.
`Solidity
// uint256 public unchanging minimum_usd;
Here are some scenarios in which «unchanging» is useful:
- Creating permanent: If you want to create permanent value, use «immutable».
- Creating unchanging structures: If you use the structure and you want to make sure that its fields cannot be changed after creating, use «immutable».
- Variable protection: When protecting variables, use `
unchanged 'to prevent accidental changes.
key differences
Here are the key differences between "permanent" and "unchanging":
|.
Keyword |
goal
|
Case of use |
|. --- | --- | --- |
|.ConstantCalculations, buffering, recurring permanent Calculation of fixed values that do not change over time. |.
|.Immutable` Unchanging variables that cannot be changed after initialization Creating unchanging structures or variable protection to prevent accidental changes. |.
To sum up, use the «permanent» keyword when calculating permanent or bouffling of data that remain the same throughout the life of the contract. Use the keyword «unchanged» when creating unchanging variables that should not be modified after initialization.
By using these guidelines and the best practices regarding the use of «permanent» and «unchanging», you can write more efficient, legible and maintained intelligent contracts for blockchain ethereum.