Solidity 0.5.0 Struct Update
In this article we’ll continue the series of stories about Solidity updates. Solidity is a well-known programing language used in the Ethereum crypto environment. Its popularity is due to the fact that developers keep supporting it with regular updates. Obviously, such a responsible attitude doesn’t go unnoticed. The majority of smart contracts placed on the Ethereum blockchain are written in Solidity. Other languages also exist and are used as side solutions for specific cases. However, all of them — without exceptions — address the Ethereum Virtual Machine.
We have already examined one of Solidity changes that conserned functions visibility. This detail is important because it relates to vital interaction properties on blockchain. Still it is only one of the many changes applied to Ethereum within the 0.5.0 update.
Solidity updates can be of different size and importance. In this article, we will not examine two small updates released after January 22, 2019. However, it must be kept in mind that they might have changed something in the 0.5.0 update because they were introduced later.
Important 0.5.0 Changes
Before turning to our research, let’s recollect major details of the 0.5.0 update. In general case, each update contains changes that fall into the following categories:
- breaking changes;
- necessary code updates;
- language features;
- compiler features;
- bug fixes.
In case of 0.5.0, the general number of influencing components is really huge. It also includes several blocks of changes, namely:
- semantic changes;
- semantic and syntax changes;
- explicitness requirements;
- deprecation section;
- issues of contracts interoperability.
In our previous article, we explained functions visibility changes. Now let's discuss the key points of the “Variables” section. It contains several changes but only one on them is of the greatest interest to us today.
A struct is a component that unites several data elements under the same name. Basically, these elements can be of different nature depending on the language. As for Solidity, there may be variables only. Considering variables as non-divisible solid units, sometimes it is convenient to unite them.
Imagine a single point in the three-dimensional space. It has three coordinates to define its position — X, Y and Z. Separately, they don’t give any visual logical connection. Compare the following examples:
Variables on the left side of the table may be connected or not, while on the right side we see strong, underlined connection between them. Visually, this can be presented as three components that are separated or united in a container:
Containers application already had restrictions before the 0.5.0 update. But then another one was added. It states that no empty structs are allowed. This means that before the update, it was possible to declare a struct with no components inside. Thus the name of the struct became reserved. After the update, it is impossible to declare structs that have no elements inside.
The reason for this change is simple: clearance. Indeed, it might be a problem to have several reserved names with no application, especially when it comes to such space economical project as Ethereum.
Variables are interesting to examine because they are the smallest bricks of any programming project. The way they are declared, assigned, managed and united into more complex components carries the general developers' aspiration. In our next articles, we will talk about other Solidity 0.5.0 changes.