-
硬编码:直接将数据写入到代码中进行编译开发。
-
软编码:将数据与代码分离。
-
变量:用来存储信息,然后在计算机程序中使用这些信息;变量的值是存储在内存中,变量可以起到定位的作用。
Variables are used to store information to be referenced and manipulated in a computer program.
They also provide a way of labeing data with a descriptive name,so our programs can be understood more clearly by the reader and ourselves.
It is helpful to think of variables as contains that hold information.
Their sole purpose is to label and store data in memory.
This data can then be used throughout your program.
第一版代码
这是一个简简单单的输出5+6的值,没有变量,数值和代码完完全全重叠在一起,因此输入硬编码中的硬编码!此代码之后我们在过渡到下一版代码:
第二版代码:
在这一版代码中我们我们多了变量的定义,因此程序相比上一版代码我们程序灵活多了,而且通过变量我们能多次调用数量的值而且更容易定位数值在内存中的位置。
我们在看这一版代码,对于数字的输入更加灵活了起来,而且这完全脱离了硬编码的形式。属于地地道道的软编码。
- 感悟:程序的灵活性在于代码的灵活性,代码的灵活性在于程序的思维。