Vyper: VIP: Constant Variables

Created on 10 Aug 2018  路  6Comments  路  Source: vyperlang/vyper

Preamble

VIP: 990
Title: Constant Variables
Author: Ryuya Nakamura (@nrryuya)
Type: Standard Track
Status: Draft
Created: 10-8-2018

Simple Summary

Adding constant variables (like Solidity's one) for readability and usability.

Abstract

Adding constant variables which is assigned from an constant expression and can be used in whole the contract. Every occurrence is replaced by the constant expression at compile time.

Motivation

Constant variables reduces hard coding of same value repeatedly and improve readability. It also helps code auditing.

Specification

Spec on declaring constant variables.

# Block interval of Plasma chain
CHILD_BLOCK_INTERVAL: constant(uint256) = 1000

Backwards Compatibility

No problem

Copyright

Copyright and related rights waived via CC0

Approved Discussion

Most helpful comment

@nrryuya yes, above the all the functions just after globals perhaps?

All 6 comments

I wonder

  • []specification on declaring constants in Python's style
  • []types allowed as constants(uint256, int128, address, decimal, bytes?)

I think we should leave types of the equation, and just follow the principal that each constant is a literal.

CHILD_BLOCK_INTERVAL: constant = 100

Also I think there is merit in limiting constants to only be defined at the top of a program (also outside functions).

I think constants should have types.
Currently I have to do like this within function.

    secondsPerMonth:uint256(sec/mon) = 2592000 # 30脳24脳60脳60
    seconds:timedelta = _durationInMonths * secondsPerMonth

typed constants will make a code cleaner

Also I think there is merit in limiting constants to only be defined at the top of a program (also outside functions).

You mean the definition of constants is above the definition of interfaces, events and storage variables?

@nrryuya yes, above the all the functions just after globals perhaps?

Starting on this.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nrryuya picture nrryuya  路  3Comments

denis-bogdanas picture denis-bogdanas  路  3Comments

lsaether picture lsaether  路  4Comments

fubuloubu picture fubuloubu  路  3Comments

robinsierra picture robinsierra  路  3Comments