
Why Learning Prolog Can Make You a Better Programmer - gnosis
http://coliveira.net/software/why-learning-prolog-can-make-you-a-better-programmer/
======
swannodette
Prolog's ideas are alive and kicking in numerous interesting forms:

    
    
      * Constraint Handling Rules, http://dtai.cs.kuleuven.be/CHR/
      * Gecode http://www.gecode.org/
      * Monadic Constraint Programming Framework (Haskell)
        http://people.cs.kuleuven.be/~tom.schrijvers/MCP/
      * Google Operations Research http://code.google.com/p/or-tools/
      * Mozart/Oz http://www.mozart-oz.org/
      * Datalog 2.0 http://datalog20.org/

------
jimwise
Interesting timing for me -- I've been working through "The Art of Prolog"
(MIT Press, 1994) recently -- I'd done some Prolog in school, but never beyond
the ``here are a few weeks in a programming languages course'', and the logic
programming discussion in both SICP and ``The Reasoned Schemer'' had made me
want to go back to the source.

I'm about 2/3 of the way through the book, and I highly recommend it to anyone
looking to learn the language in a more or less rigorous way. It won't make
you a production Prolog programmer (any more than SICP will make you a
production Schemer), but it starts with a firm grounding in the theory of
logic programming, and works that up to a good grounding in Prolog step by
step, before spending the latter half of the book working through idiomatic
Prolog solutions to a bunch of standard (once-standard?) problems (a shell, an
interpreter, a compiler), as well as problems more in line with Prolog's
traditional uses (ELIZA, an expert system).

The book is here:

    
    
        http://www.amazon.com/Art-Prolog-Second-Programming-Techniques/dp/0262193388
    

``The Craft of Prolog'', which this post mentions is in the same series, and
provides somewhat of a more pragmatic view of the language. I may get to that
next. Meanwhile, ``The Reasoned Schemer'' provides the entry of ``the Little
Schemer'' series into the field of logic programming, using the MiniKanren
logic programming system for Scheme.

~~~
silentbicycle
_The Craft of Prolog_ has a lot of good bits, but is written in response to
something less readily available, so its organization seems a bit weird.

I also recommend the hell out of _The Art of Prolog_. Have done so here, many
times. Also: Prolog systems with constraint extensions are MUCH more powerful.
SWI Prolog (<http://www.swi-prolog.org/>) and GNU Prolog
(<http://www.gprolog.org/>) are both good.

~~~
_tef
Art of prolog makes an excellent first book, and the Craft complements it well
with seasoned advice on elegant and efficient prolog.

------
pkteison
Unimpressed with article. For example, it says prolog only returns true and
false. Prolog only returns "i proved it is true" and "I couldn't prove true",
which they mislabel as false - so false is not "not true". If you want to
focus on features that expand your understanding of what a programming
language is, that is surely a big one - false isn't !true? Wrap your brain
around that and try to program anything that is still correct, it breaks
everything you know about what you can do with a computer.

I disagree with seeing prolog classified as functional - my experience with
functional programming in lisp had a very very different view of side effects
than my experience with declarative programming in prolog.

Sure, learn prolog and you'll learn more about programming, but that's true of
any programming language. I'm not convinced the benefits of learning prolog
exceed the benefits of spending the same amount of time on something else. The
main thing I learned in a prolog class was the huge danger of relying heavily
on facts without also considering confidence in those facts. I can learn the
exact same lesson if the declarative language I choose is SQL, with the added
benefit that I might get to use the SQL someday.

------
cydonian_monk
I've always liked prolog, and seeing prolog love on HN makes ?-
happy(cydonian_monk) return true. My first exposure to the language, as I'm
sure was the case for many of you, was in an Intro to AI course. Though I've
never found the opportunity to use the language professionally, I do on
occasion drop it into personal projects.

That said, I've always considered prolog to be the language that most
threatens our sanity. Perhaps it's because the Graduate Assistant that taught
my Intro to AI course was a bit cracked (he tied his shoelaces around his legs
once in class because they "offended him"). Or maybe because I haven't been
entirely sane since that class....

------
stewbrew
"Prolog is a pure functional language ... so there are no variables to
update?—?only method calls."

It's been a while (some decades) since I wrote my last prolog program but this
seems to be rather wrong to me. First of all, there is also the paradigm of
logic programming and prolog is it's best known child. I don't think you can
equate logic programming to functional programming. Secondly, there are no
method calls as such. IIRC a prolog interpreter basically does a depth-first
search on a graph made up of assertions. The very point of prolog is though
that you don't tell the interpreter "call this method with these arguments and
then do that" but rather you tell it "show me valid solutions that fit this
template assertion, do however you think is best". At least that's what simple
interpreters did. I don't know what more sophisticated compilers like gnu
prolog made out of it. Please somebody correct me if I'm wrong. It's possible
that my memory fails me.

~~~
danieldk
There is a subset called "pure Prolog", which is restricted to Horn clauses.
But regular Prolog (with extralogical features) is not functional, and
definitely not pure. For instance, the proof_me predicate in the following
program will be true, only once:

    
    
      :- dynamic bla/0.
    
      proof_me :-
        \+ bla,
        assert(bla).

------
jdp23
Agreed. Back in the 1980s I did my Masters' project in Prolog (transistor
sizing, part of a "silicon compiler") and it gave me a lot of new tools for
thinking about programming in general.

The same's true for other langauges that offer different ways of thinking of
about world: the LISP family, Haskell, Eiffel, Forth, awk, ...

------
antiterra
Learning Prolog sounds worthwhile, but time spent learning Prolog is time not
learning something else. Why not Erlang or something obscure I've never heard
of like Fril?

Also, I'm getting fatigued by authoritative talk about computer science
curricula in the same "kids these days" manner as someone convinced the world
is falling apart while actual violent crime or teen pregnancy statistics drop.
I'd expect claims like Oliveira's to be supported by some kind of data we can
be privy to instead of vague anecdotal impressions.

"Schools are more interested in teaching marketable languages." Ok. All
schools, most schools, state schools? Where's justification for "It seems like
that they are looking for ways of getting people through the program as quick
as possible"? Why does it seem that way?

~~~
_tef
prolog is an interesting take on programming and by comparison, the style in
which you write code is still significantly different to approaches in other
languages.

sadly, most people when taught barely get past the 'parents and grandfathers'
stage of programming.

why not something else? sure! erlang is actually pretty neat (otp is golden)
and was originally implemented in prolog. why not learn a term re-writing
language? what about snobol?

why prolog? well,

prolog for me has just been one of the most fun and interesting experiences I
have had while programming. good prolog code is elegant in a way i've never
seen in other languages and it's a big rush when you crack the puzzle of
expressing your problem.

prolog was also used in ibm's watson and shipped as part of nt too :-)

------
smoody
I've always wished someone would do a JVM-version of Prolog, like Clojure
(Jalog?) where the prolog databases can, on demand, be linked directly to
MySQL databases and/or a networked in-memory cache of some sort. Do that and
don't charge an obscene amount and I can promise you that you'll have at least
one paying customer. :-)

~~~
nathanmarz
I wrote a library for Clojure called Cascalog. It's a variant of Datalog that
executes using Hadoop. It's not Prolog, but you may find it interesting.

<https://github.com/nathanmarz/cascalog>

------
nickolai
Agreed. Though i'd like to have someone name me a language, adding which to
one's skillset would make one a worse programmer.

~~~
lt
_It is practically impossible to teach good programming to students that have
had a prior exposure to BASIC: as potential programmers they are mentally
mutilated beyond hope of regeneration.

The use of COBOL cripples the mind; its teaching should, therefore, be
regarded as a criminal offence._

\-- Dijkstra

[http://www.cs.utexas.edu/users/EWD/transcriptions/EWD04xx/EW...](http://www.cs.utexas.edu/users/EWD/transcriptions/EWD04xx/EWD498.html)

~~~
kenjackson
_I guess I would recommend perhaps LISP, FORTRAN and APL if you wanted to pick
old time languages. More recently you might want to take a look at Ruby and
Haskell, to pick a functional language, and COBOL, which has some interesting
ideas in it you won't find in some of the other languages._

\-- Guy Steele

Notice that he lists COBOL as a language to learn. I've always found Dijkstra
to be a little over the top (often the only way to get people to listen), and
Steele more pragmatic.

[http://www.infoq.com/interviews/Programming-Languages-Guy-
St...](http://www.infoq.com/interviews/Programming-Languages-Guy-Steele)

------
_tef
As much as I agree with the title I find the contents of the article
misleading.

It is almost as if prolog didn't make him a better programmer, given the idea
that prolog 'returns values' or uses 'method calls' is 'not even wrong'.

------
plinkplonk
From the article.

"In Computer Science programs, there is a tradition of having a course of two
that represent the watershed between people that can grok CS concepts and the
ones that can’t. "

Would those HNers who've been through a masters or PhD in CS help an
uneducated brother hacker and list any such "watershed" courses they know of?
Thanks in advance.

EDIT: links to course home pages would be highly appreciated, plus any
reminiscences of how tough these courses were/felt like.

~~~
kovar
In my undergrad CS program, it was Operating Systems. The course required us
to move from writing programs to solve well constrained problems to addressing
issues of memory management, file systems, command line interfaces, etc.

~~~
doyoulikeworms
This was the same in my curriculum, and I'd throw in Compilers and CPU
Architecture & Design as well.

There's nothing like building a simple OS, compiler, and pipelined CPU to
transform "the computer" from a magical black box into a supremely powerful,
interesting tool.

