CashScript / cashscript

⚖️ Easily write and interact with Bitcoin Cash smart contracts
https://cashscript.org
MIT License
112 stars 79 forks source link

Add 'constant' keyword #119

Closed nathanielCherian closed 2 years ago

nathanielCherian commented 2 years ago

13. The syntax is similar to solidity int constant m = 5.

When a variable declared constant is mutated, the ConstantModificationError is thrown.

rkalis commented 2 years ago

This is great, thanks!

I have one request:

And I also have one more thought that I'd like to discuss. Do you think we should create an array of modifiers in case we would want to add additional modifiers in the future? It may be premature optimisation because I can't really think of other modifiers, so I'll leave the decision up to you.

nathanielCherian commented 2 years ago

For sure! Thanks for the pointer!

Regarding the array of modifiers... I was really torn on this one. At first, I supported an array of modifiers but after implementing it I felt that accommodating additional modifiers right now made the code less concise. Favoring simplicity at this stage, I think we shouldn't use an array of modifiers.

However, I saved the array of modifier code to a different branch in my fork, so if we ever have a need for another modifier it should be convenient to implement.

rkalis commented 2 years ago

Awesome! Thanks for taking the time to consider the trade-off. Let's go with your suggestion then, we'll always be able to add the array when necessary in the future. I'll merge this soon and include it in the 0.7.0 mainnet release.