As was foretold, we've added advertisements to the forums! If you have questions, or if you encounter any bugs, please visit this thread: https://forums.penny-arcade.com/discussion/240191/forum-advertisement-faq-and-reports-thread/
Options

Programming the declarative way

peterdevorepeterdevore Registered User regular
I recently came across these free video recordings of MIT programming lectures. They are a very succinct and engaging introduction to declarative programming. Declarative programming languages like Lisp, Prolog, Haskell and Curry treat all data, 'normal' primitive values, and code (functions) in your program the same, as metaphysical objects with a name. The implication of this is that you can program on a much higher level, do more with less code, and with more abstraction and separation.

In the second hour or so, they already explain something that is pretty hard to do in your average C++/C#/Java/Pascal/whatever (imperative) programming language.

These might be from the eighties, and they use Lisp as their language, but please believe me when I say that if you watch and understand that whole course, you just learned enough to call yourself a Real Programmerâ„¢. If anything, it is a wonderful introduction to the power of declarative languages, where functions are first class citizens and can be used, changed and passed like variables to other functions as if they were just a piece of data. And the wonderful concise syntax Lisp has (bracket overload notwithstanding), really gives you insight into what a program is and how it gets its meaning.

If anything, you can watch it for the historical value. How some guy with a goatee and a brooch (tie ornament?) at the top of his business shirt (?! right there in lecture 2b at 0:37:48) is surprised you would want to defer designing the specifics of your program until you really need to (instead of designing it all at once and then implementing it :lol:), how the teacher has a different flower arrangement on his desk each day, how they had a digital presentation system even back then that does about everything powerpoint can, how memory 'complexity' was just as big a deal as time complexity and typical eighties hair and dress (seriously, the attendants look like they just walked off the set of Revenge of the Nerds).

Anyone who paid good attention to math in high school can follow this course. This is unfortunately so because they mostly use examples from the mathematical world. The programming itself is detached from actual math, since declarative languages do not have the need to use primitive mathematical operations as much as your average language.

I wish someone would make a course like this with more engaging examples, like common combinatorial or statistics questions for researchers, things that matter to business people or binary logic and set problems. You can breathe life into every theoretical model ever thought of by transcribing it into a declarative language, so why stick to math, where people often do not see the direct use of it.

You then have powerful general metaphysical tools at your disposal to transform, test and simulate your model. There are ways of looking at data that see patterns in gene sequences as good as they do in radio signals, weather readings or population statistics. Unfortunately they are reinvented every time someone from those fields needs to solve a problem with them and written again and again in an imperative language, or even worse, a spreadsheet or statistics program, where the method is hard to abstract from the data it works on.

Tell us how you see the future of declarative programming. Do you have experience in a declarative language? Why is it exactly that these languages have trouble with some things like real time user interaction?

peterdevore on

Posts

  • Options
    SenjutsuSenjutsu thot enthusiast Registered User regular
    edited December 2007
    Declarative programming languages like Lisp, Prolog, Haskell and Curry treat all ...
    Nitpick: Of those four, only Prolog is truly a Declarative language. Lisp, Haskell, and Curry (which is basically just a superset of Haskell) are more or less straight Functional languages, and everything you go on to say is much more true of Functional languages than of Declarative languages.

    In Declarative languages you (basically) define the problem in code, and then ask questions which the runtime computes the solution to. eg) (in pseudo-code)
    Parent(Bob, Joe); 
    Parent(Jim, Bob); 
    Grandparent(x, y) if (Parent(x, z) and Parent(z, y);
    

    Where a sample question given that program:
    Parent(Jim, Joe)?
    > True.
    

    Declarative languages were a big thing 30 years ago, but they're more or less a completely uninteresting dead-end for most things. There aren't that many programming projects that involve asking questions about a bunch of predicates, and Declarative languages are spectacularly unwieldy for doing anything other than that.

    Senjutsu on
  • Options
    jackaljackal Fuck Yes. That is an orderly anal warehouse. Registered User regular
    edited December 2007
    Senjutsu wrote: »
    Declarative programming languages like Lisp, Prolog, Haskell and Curry treat all ...
    Nitpick: Of those four, only Prolog is truly a Declarative language. Lisp, Haskell, and Curry (which is basically just a superset of Haskell) are more or less straight Functional languages, and everything you go on to say is much more true of Functional languages than of Declarative languages.

    In Declarative languages you (basically) define the problem in code, and then ask questions which the runtime computes the solution to. eg) (in pseudo-code)
    Parent(Bob, Joe); 
    Parent(Jim, Bob); 
    Grandparent(x, y) if (Parent(x, z) and Parent(z, y);
    

    Where a sample question given that program:
    Parent(Jim, Joe)?
    > True.
    

    Declarative languages were a big thing 30 years ago, but they're more or less a completely uninteresting dead-end for most things. There aren't that many programming projects that involve asking questions about a bunch of predicates, and Declarative languages are spectacularly unwieldy for doing anything other than that.

    The terminology isn't set in stone, but as far as I can tell "declarative" is used as an umbrella term for functional and constraint programming.

    jackal on
  • Options
    SenjutsuSenjutsu thot enthusiast Registered User regular
    edited December 2007
    That's true.

    When I was in uni they tended to use declarative to exclude any language in which you need to specify how to solve a problem, which excludes most functional programming

    Senjutsu on
  • Options
    peterdevorepeterdevore Registered User regular
    edited December 2007
    Senjutsu wrote: »
    Declarative languages were a big thing 30 years ago, but they're more or less a completely uninteresting dead-end for most things. There aren't that many programming projects that involve asking questions about a bunch of predicates, and Declarative languages are spectacularly unwieldy for doing anything other than that.

    I believe there is a small resurgence of the declarative languages going on though.

    PRISM for example, can properly model complex combinatorial systems and output its statistics. It is already easy to solve a simple combinatorial problem (like 'when you throw two dice, how many outcomes are there where the total of eyes is greater than 5') in a declarative language without these extensions. PRISM makes it possible to give possibility values to your facts and go a step further.

    Another thing which has me excited is this paper, which combines qualitative temporal logic (symbols and properties to describe concepts like 'eventually this must happen', 'if this has happened, that must happen next') and qualitative spatial logic ( 'this is area contained by that one' or 'this is area overlaps that one') to simulate solutions to problems like how you could juggle balls if you were given rules like "if you have the red ball in your hand, the green ball must be in the air and the blue ball must be thrown next". Or the solving the Piano movers problem without involving complicated learning algorithms or spatial manifolds.

    With the semantic web being touted as the hot new thing, declarative languages become relevant again. "solving questions about a bunch of predicates" as you call it is exactly what a search algorithm does. The standard for storing metadata, called RDF is based on the idea of defining a relation between a subject, a predicate and an object, together called a triplet. These relations can be loaded directly into declarative language programs and asked questions about.

    I'm thinking about making a simple search engine which takes interesting data from DBpedia (basically, a repository of RDF dumps of various Wikipedia data) and does things to it based on Prolog programs. For example, it has a database of all persons on wikipedia containing their names, places and dates of birth/death and a short description. Couple that with the geographic location dump and you can make all kinds of nice Google Maps overlays.

    Software like Yahoo Pipes, Google Mashups and Intel Mash Maker will result into having EVERY website parsed properly into RDF very soon (IBM explains). This opens up so much data you want to search and combine meaningfully, declarative languages might finally be able to show their strength.

    peterdevore on
  • Options
    SenjutsuSenjutsu thot enthusiast Registered User regular
    edited December 2007
    That looks pretty interesting, actually

    Senjutsu on
  • Options
    MblackwellMblackwell Registered User regular
    edited December 2007
    I learned Scheme in college and it was pretty much the biggest pain in the ass ever, if only for the fact that it left little to experimentation. You basically had to write your program before your wrote your program. Obviously this is not always a bad thing, but it was still not the funnest thing in the world for someone like me that likes to dick around.

    Although, I appreciate the simplicity quite a bit.

    Mblackwell on
    Music: The Rejected Applications | Nintendo Network ID: Mblackwell

Sign In or Register to comment.