答案 0 :(得分:8)
声明性格式是指声明程序的意图/最终结果,而不是它应该如何到达的格式。基本上它是配置文件和一段代码之间的区别。比较:
CC=gcc
CFLAGS=-I.
DEPS = hellomake.h
%.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS)
hellomake: hellomake.o hellofunc.o
gcc -o hellomake hellomake.o hellofunc.o -I.
VS。像(python-pseudocode):
CC = "gcc"
CFLAGS = "-I."
DEPS = ["hellomake.h"]
def make_o_file(o_file, deps):
#don't recompile if it exists & is current
c_file = "%s.c" % os.path.splitext(o_file)[0]
if (os.path.exists(o_file)
and is_newer(o_file, c_file)
and all(is_newer(o_file, dep) for dep in deps)):
return
#else actually compile it
compile_c_file(CC, code_file, o_file, CFLAGS)
if target == "hellomake":
make_o_file("hellomake.o", DEPS)
make_o_file("hellofunc.o", DEPS)
link_o_files("hellomake", ["hellomake.o", "hellofunc.o"])
如果格式设计合理,前者可以更容易处理。 declarative programming上的维基百科可能很有用。