Skip to content
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

Add tip for avoiding var #57

Closed
ethers opened this issue Aug 27, 2016 · 5 comments
Closed

Add tip for avoiding var #57

ethers opened this issue Aug 27, 2016 · 5 comments

Comments

@ethers
Copy link
Contributor

ethers commented Aug 27, 2016

also mentioned in solidity docs

@JohnAllen
Copy link

Can someone expand on why? Because 'var's are mutable?

@maurelian
Copy link
Contributor

Good question. Its non-explicit and kind of lazy.

The only reason I can think of to use var, is to avoid having deciding what kind of type you want to use, which shifts the cognitive load to devs reading and reviewing your code. Readability is key to security.

@JohnAllen
Copy link

JohnAllen commented Jul 19, 2017 via email

@maurelian
Copy link
Contributor

Yeah. The "solidity is like js" meme is a pretty bad one, which this var feature reinforces. Fortunately it looks like it's on its way to deprecation, as the compiler gives a warning:

browser/Untitled1.sol:8:9: Warning: The type of this variable was inferred as uint8, which can hold values between 0 and 255. This is probably not desired. Use an explicit type to silence this warning.
        var n = 2;
        ^-------^```

@maurelian
Copy link
Contributor

Consolidating this with #78.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants