3

I've learned Solidity first and now I am learning the Go language. Throughout my learning process I am noticing that both languages are very similar. So, is it possible in future to include Go code in a Solidity contract? Or am I wrong?

  • 1
    Related: ethereum.stackexchange.com/questions/3112/… – eth Jan 3 '17 at 22:26
  • @eth thanks for the link, this is almost my answer but with much more detail and from someone who knows much more than me. Very valuable answer. – Nicolas Massart Jan 5 '17 at 22:28
  • @NicolasMassart Thanks for your comment because it highlights the related Q&A more which I do hope people don't miss because it's also valuable as you've noted. – eth Jan 6 '17 at 1:48
3

First don't mix Go as the language used for building some Ethereum tools and base implementation and languages for writing smart contracts such as solidity that can be compiled into evm code.

Today i'm not aware of any evm compiler that would be able to use Go code as input or a mix of Go and Solidity. But you can imagine one as some are able to use JavaScript as smart contract language (Lisk).

The main reason why smart contracts are written in solidity (or less used Serpent) for ethereum is that it's a deterministic language. Go isn't deterministic and could lead to fatal code behaviour or you would have to tell developers not to use some functions, but can't force them not to use these functions. Just think about the use of random function: rand.Intn(100). Each time the contract executes, the result should be different. So how can you have concensus on the result of the contract execution? No concensus means the contract won't be useful at all, because concensus is the main purpose of blockchains. ( Randomness in contracts somwhat possible but is a tricky thing to use very carefully and not just by simply using a random function, see this answer for instance)

Lisk cryptocurency made the bet that having a widely known language would be more important than having a deterministic one. Ethereum made the other choice and preferred a deterministic language even if it's a new one to learn (we thought it was a not so complicated language at the begining, but that was before The DAO...). Look at how much "bugs" are written in contracts even using a simple deterministic language as solidity and imagine the mess if it was written with some other language like Go. I like Go, it's a nice language for many things but not for smart contracts IMO.

| improve this answer | |
  • 1
    but You can write a deterministic program in go. You just need to eliminate the possible sources of non-determinism.no? – Sig Touri Jan 4 '17 at 23:45
  • 1
    @SigTouri yes, as Lisk does with JS. But that's error prone as you will have to maintain a documentation on top of original Go language documentation to indicate what is possible or not and hope people will take it in account... – Nicolas Massart Jan 5 '17 at 8:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.