Declarative Programming

Shane Brinkman-Davis Delamore edited this page Mar 29, 2018 · 26 revisions

Related: Functional Oriented Programming, React-style programming

What is Declarative Programming?

A program that describes what computation should be performed, not how to compute it.

Facebook's React and Imikimi's ArtReact are examples of declarative style programming.

DSL (Domain Specific Languages)

Declarative programming in an imperative language like JavaScript typically takes the form of embedded DSLs. CaffeineEight is a DSL for writing parsers. Below is an example of a complete Json parser using CaffeineEight, written in CaffeineScript.

class JsonParser extends &CaffeineEight.Parser

    root: :array :object

      "" '[' _? ']'
      "" '[' _? value commaValue* _? ']'

      "" '{' _? '}'
      "" '{' _? pair commaPair* _? '}'

    commaValue: "" _? ',' _? value
    commaPair:  "" _? ',' _? pair
    pair:       "" string _? ':' _? value

    value: :object :array :number :string :true :false :null

    string: /"(?:[^"\\]|\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4}))*"/
    number: /-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/
    true:   /true/
    false:  /false/
    null:   /null/
    _:      /\ +/

CaffeineScript Enhancements for Declarative Programming

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.