gpt4 book ai didi

coding-style - 什么是“声明式格式”?

转载 作者:行者123 更新时间:2023-12-03 22:36:48 25 4
gpt4 key购买 nike

The Twelve-Factor App说:


使用声明性格式进行设置自动化,以最小化新开发人员加入项目的时间和成本


“声明性格式”是什么意思?

最佳答案

声明性格式是一种声明程序的意图/最终结果的声明格式,而不是声明程序的意图。本质上是配置文件和一段代码之间的区别。比较:

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.


与类似(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上的Wikipedia可能有用。

关于coding-style - 什么是“声明式格式”?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16908028/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com