1

Contract-oriented programming, like Solidity, is similar to OOP, in a syntactical sense. For example, both have concepts of encapsulation, abstraction, inheritance, and polymorphism. They also share similar keywords, and a contract seems analogous to an object. However, they are not.

Does anyone know of any resources regarding contract oriented design?

  • Hi there. Have you seen this term used in the Ethereum space? Contract-orientated programming in a computer science/software engineering sense is nothing to do with smart contracts, unless there's now a blockchain-specific definition :-) – Richard Horrocks May 23 '21 at 20:00
  • Ah I must be mistaken then. For some reason I swear I've seen the term "contract oriented programming" somewhere, maybe at the introduction of a tutorial. Update: here it is: https://www.tutorialspoint.com/solidity/index.htm. Is there a difference? I'd never heard of "design by contract" before – pastacompany May 23 '21 at 20:27
  • Interesting. In more recent versions of the Solidity docs, they've changed "contract-oriented" to "object-oriented" -> https://docs.soliditylang.org/en/v0.8.4/ Perhaps they realised that it wasn't the right term to use? – Richard Horrocks May 23 '21 at 20:30
  • 1
    I've added an answer in case it helps other people wondering a similar question. – Richard Horrocks May 23 '21 at 20:30
  • Okay, final update. It looks like originally "contract-oriented" was meant as a pun on "object-oriented", which implies they probably didn't know about the definition I've mentioned in my answer. -> https://github.com/ethereum/solidity/pull/4995#discussion_r218450303 – Richard Horrocks May 23 '21 at 20:42
  • Yeah I just read through that thread and I think "contract-oriented" can make if confusing if you know about DbC (which I didn't until now), but also if you didn't, like me. But as described on the solidity docs, the first line describes it as "object-oriented". I think this is especially confusing because a contract is not analogous to an object, as answered in this post: https://ethereum.stackexchange.com/questions/12596/is-a-smart-contract-analogous-to-an-oop-class?rq=1 – pastacompany May 23 '21 at 21:05

1 Answers1

1

Contract-Orientated Programming - also called Design by Contract (DbC) - is a software engineering paradigm aimed at making software more reliable.

"Design by contract (DbC), also known as contract programming, programming by contract and design-by-contract programming, is an approach for designing software."

The "Contract" part of the name has (confusingly) nothing to do with smart contracts.

Further, it isn't tied to a particular language, nor a particular language type, rather it's a methodology and approach to writing code.

(There's the related "Condition-Orientated Programming" that Gavin Wood wrote about, here. Again, this is a methodology rather than syntax or language trait, but that article does give a walk-through of how it can be applied to Solidity.)

Richard Horrocks
  • 37,835
  • 13
  • 87
  • 144