Pergunta

I am enjoying the puppet declarative model. I'd like to try to incorporate more of this into my code.

I program in python currently, however, and I tend to think imperatively while doing so. It's just like my problem with graphic design: I know what I like to see in an end product, but have no idea how to assemble it.

How can I structure things so that the code would be declarative? What initial steps are taken if the solution is to be recognizably "declarative?"

Functional, Declarative, and Imperative Programming I've just read this, bringing insight, a bit.

Not enough though, can't put it into words exactly, my confusion :(

EDIT: Words have come: The examples given for declaration always are given in terms of some other high level thing:

Regexen are declarative, sure, but you make the engine out of C.

Make is declarative,certainly but it's written in C.

Puppet mainifests are declarative of course, but the Ruby code is not.

So at what point do I say: "Ok, here is the methods, now I can begin the declarative part" ?

Foi útil?

Solução

When in a functional language, write in a functional style, when in in an imperative language write in an imperative style, and when in a declarative language, write in a declarative style.

As per above (excluding all the "cross styles" allowed), when you write in a language you write in the style of a language. In the case of writing 'declartively' in an 'imperative' or 'functional' language this would usually break down to writing a declarative DSL and/or API without actually changing the fundamental style used to expose (or even glue) said declarative-friendly DSL/API.

For instance, make (or any number of XML-languages like ant) are just declarative DSLs (with some blurring). The host language is not important. This can be generalized for pretty much all Turing Complete host languages.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top