in Link Post

The Viper Experimental Programming Language

Source: Viper @

I originally planned to post this yesterday, but fell down the hole of trying to get my head around Solidity, Ethereum’s current smart contract programming language. I can’t say I’ve fully achieved that yet, to be honest.

Nevertheless, Viper does seem to be more cleanly aligned to the goal of creating a machine readable legalese:

Viper is an experimental programming language that aims for some of the following goals:

  • Security – it should be possible and natural to build secure smart contracts in Viper.
  • Language and compiler simplicity – the language and the compiler implementation should strive to be simple.
  • Auditability – Viper code should be maximally human-readable. Furthermore, it should be maximally difficult to write misleading code. Simplicity for the reader is more important than simplicity for the writer, and simplicity for readers with low prior experience with Viper (and low prior experience with programming in general) is particularly important.

There are obviously a few trade offs made here1. One thing which stands out to me is that it’s likely to be harder to write DRY2 code given the lack of inheritance. It also drops some of Solidity’s speed and efficiency based constructs.

Given the auditability goal, Python is an interesting choice of language to use as a basis. It can get dangerously close to be a write only language. Unlike regular Python, Viper is statically typed only, though. That should help with readability. At the same time, Python itself is one of the most popular and well used languages out there. A potential auditor only needs to learn the differences to Python, rather than learning a whole new language. Since Viper mostly seems to remove things from Python, the extra learning required is likely to be minimal. From the Viper by Example page:

[…]all Viper syntax is valid Python3 syntax, however not all Python3 functionality is available in Viper.

  1. Not the least of which is that weaselly “some” in the first sentence.
  2. Don’t Repeat Yourself, or in other words: write code once and reuse it.