Logic Programming with PuzzleScript

I hate IF...

...and:

  • FOR
  • FOREACH
  • WHILE
  • DO...WHILE
  • ...

Now with less HN hyperbole

I have limited brain power and I waste it thinking about control of program flow and basic result construction mechanisms


  // I want to find out which sandwiches are dairy free
  foreach piece in sandwiches:
    if piece.has_dairy is false:
      my_menu.add (piece)
                                  

Declarative Programming

Declarative Programming languages and techniques focus on

  • Specifying what you want...
  • ...not how to get it

Logic Programming

Subparadigm where we get results through application of rules about a problem domain

Goodbye, IF

Our only concern as developers is to write rules and their outcomes

PuzzleScript

Tile based game engine using a rules based DSL to define game logic

A PuzzleScript Rule

                                    
           [ > Player | Crate ] -> [ > Player | > Crate ]
                                    
                                  

My PuzzleScript Rules

                                    
======
RULES
======

[ >  Player | Crate ] -> [  >  Player | > Crate  ]
[ Crate | Lava ] -> [ DOWN Crate | Lava]
[ Crate Lava ] [ Player ] -> [ Crate Lava ] [ HappyPlayer ]
                                    
                                  

It's Logical; Be Declarative

Higher level abstractions and different approaches help us focus on solving problems

Lower level artifacts like IF are important but too widely present in our code

That's great...what about the REAL world?

SQL

LINQ in C#

Google: declarative programming [your language]