Mordax

Software Developer

View My GitHub Profile

A Series of Code refactors

Solidity has released v0.5.0 of the language.

The Solidity repo utilizes its Github projects really well, and most of the code that I had done before was tackling some basic issues that were needed to get the next version out.

Incredibly, I ended up being thanked on the 0.5.0 release. I didn’t expect it but it happened. I really enjoy spending time in that repo, everyone is very intelligent and very kind.

Now onto the issue.

0.5.1 is the next update, and there’s an issue thats opened up regarding code refactoring. Made up of many sub issues, basically the goal is to enhance the performance of the language and to remove redundancy. Here’s one of the sub issues I worked on.

Issue:

When a function is declared with an override remove the redundant virtual.

Side Issues:

I’d realized before starting this relatively major refactoring (36 pages changed), that I had screwed up my repository. I had built from source following the Solidity instructions, and I had built my original repo that worked on the three other issues in Powershell on Windows. I had ended up with around 500+ build files that were shown as changes that needed to be added to Git.

My previous issues were small in size, working mostly in 1 to 2 files, so it wasn’t a problem to avoid adding them. The issue came from needing to make sure I properly found and removed every instance of virtual partnered with an override. Having so many changed files would make it difficult for me to navigate and understand which files I needed to add, and which I didn’t. A lot of unecessary clutter.

Here’s how you avoid that issue if you are a Windows user.

Important: run all of these in Command Prompt, not Powershell.




The next issue I ran into was replacing the redundant statement. I had to remove virtual but only if there was an override following it. Following cppreference, it seemed to not negatively affect the virtual-ness of a function if there was only override present.

Solidity being a language, you get quite worried about accidentally introducing some unforeseen vulnerability in the language. Especially since it handles real, valuable currency on a daily basis.

VSCode is the editor I’m using at the moment. CTRL+SHIFT+F nets you a repo-wide search and extends to a replace functionality. You can write which files to ignore as well. Now, you can extend this search with a regex toggle which was extremely useful for me working on this issue.

But there was an unforseen limitation of VSCode’s replacement functionality. Let me break down the issue:

That works but I had to manually analyze that the highlighted repo search matches did in fact contain override, which some of them didn’t.

I believe this could be remedied by adding this functionality to VSCode, because I reckon I’m not the only one who ran into this case before. I also accidentally removed a virtual from an exception that was needed but the maintainers fixed that (thanks).

Anyways, onto the solution.

Solution:

Benefits:

Happily merged.