Details Of Solidity 0.5.0 Update With Respect To Variables
Solidity updates can be big or small. Either way, they bring changes both to the existing environment and planned projects. We have already examined some important details on particular updates related to struct components and functions visibility. Still, there are many other interesting questions left.
As it was mentioned in previous articles devoted to Solidity, all Solidity updates may be divided into several categories and relate to different components.
In terms of categories, these changes are:
- Top language changes;
- Updates that are crucial for the code;
- Updates related to language features;
- Updates related to compiler features;
- Bug removal.
In terms of components, these changes are associated with:
- Changes in language semantics and syntax;
- Explicitness management;
- Unnecessary component removal;
- The management of contract interoperability.
In this article, we will talk about changes regarding variables. Since variables are the smallest components of a smart contract, their modification can be attributed to the first three categories and any of types. A more detailed classification is impossible without a specific example.
Changes In Variables Introduction
The first change we are going to talk about concerns the way variables are introduced in a contract. The change statement itself looks like this:
The var keyword is now disallowed to favor explicitness.
So what does it mean? Basically, there are two ways of creating new variables in the programing language. The first way presupposes that there should be a keyword before the variable declaration section. For example, this approach is used in the Pascal language. In order to create new variables, one needs to enter “var” and then specify their list.
The second change presupposes that there is no special declaration word. This means that new variables are introduced in any place of a program. Each unknown word will be automatically checked for syntax and defined by the compiler as a variable, a function, or any other program component.
Let’s compare these two examples:
Previously, it was possible to declare variables in Solidity in both ways. We can see this in the previous language versions. Such a mixed approach can confuse developers, it takes free space in the code and requires additional code processing. Eliminating such redundancy improves the quality of the code.
Change In Storage Variables
The second change is about storage variables. There are several different areas where developers can store variables data. The most crucial one is the contract storage area. It takes place on blockchain. Thus, any possibility of clearing unnecessary memory load is positive.
The change statement is:
Uninitialized storage variables are now disallowed
What does this mean? In general case, it is possible to create a variable without giving a value to it. This means that you reserve the name and space but the variable doesn’t participate in program execution yet. When it comes to temporary memory, it doesn’t matter how much variables exist. But in the case of blockchain memory or contract execution memory, this plays a great role.
Removing the option of variables introduction eliminates unnecessary reservation of empty space.
The above examples of changes in the Solidity language are important ― they are responsible for saving space and increasing clarity. However, such an actively developing language may reverse them in the future. Other interesting changes include tuples management, arrays, and assignment issues. We are going to talk about them in our next articles.