What's the difference between data and code?

前端 未结 13 792
青春惊慌失措
青春惊慌失措 2020-12-13 10:52

To take an example, consider a set of discounts available to a supermarket shopper.

We could define these rules as data in some standard fashion (lists of qualifyin

13条回答
  •  情书的邮戳
    2020-12-13 11:02

    This is a rather philosophical question (which I like) so I'll answer it in a philosophical way: with nothing much to back it up. ;)

    Data is the part of a system that can change. Code defines behavior; the way in which data can change into new data.

    To put it more accurately: Data can be described by two components: a description of what the datum is supposed to represent (for instance, a variable with a name and a type) and a value. The value of the variable can change according to rules defined in code. The description does not change, of course, because if it does, we have a whole new piece of information. The code itself does not change, unless requirements (what we expect of the system) change.

    To a compiler (or a VM), code is actually the data on which it performs its operations. However, the to-be-compiled code does not specify behavior for the compiler, the compiler's own code does that.

提交回复
热议问题