What is the difference between declarative and procedural programming paradigms?

后端 未结 8 689
旧巷少年郎
旧巷少年郎 2020-12-07 08:00

What is the difference between the declarative and procedural programming paradigms? Could you please provide some examples?

What other programming

8条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-07 08:27

    To address the ansible comment and maybe provide an example between the differences of the two. Ansible is procedural where as something like puppet or terraform are declarative. For example, you create an ansible yaml file to deploy 10 ec2 instances like this:
    -ec2: count: 10 image: ami-058c6e5b73b074cd2 instance_type: t2.micro

    If you were to run that file twice, you would end up with 20 t2.micro ec2 instances. If you wrote the equivalent in a declarative language like terraform and ran it twice you would only have 10 t2.micro instances running no matter how many times you ran it. Declarative languages specify end state. Procedural languages just do what you tell it without regard to current or past state.

提交回复
热议问题