Some use FP, some use OOP, some use procedure.
It seems few universities start with logic programming, why?
Computer Science Educators Stack Exchange is a question and answer site for those involved in the field of teaching Computer Science. It only takes a minute to sign up.
Sign up to join this communitySome use FP, some use OOP, some use procedure.
It seems few universities start with logic programming, why?
I do and am currently teaching a high school student Prolog but not as a first language.
Is it OK to use logic programming(like Prolog) as students' first language?
While you could do it I would not advise doing it, let a student do it if they asked or be on a committee that would advocate for it.
The reasons are
Prolog is so much unlike other programming languages that there are very few other resources that a student could use as references for learning it and they would be very dependent on the teacher for learning. Many of the students I teach talk to others to round out their understanding of what I teach and while I would like to think that they clearly understand everything I say and get it correct the first time that just does not happen and so the students look to other means to augment their learning. With Prolog it is not only hard to find other good resources, but also students (and especially high school students) are hesitant to seek out help of knowledgeable peers.
With regards to books, there is only one book that I would use as an introductory teaching book and that is "Prolog Programming for Artificial Intelligence (4th Edition)" by Ivan Bratko (Amazon) (WorldCat). Java or Python have several tens of books and several are suitable for an introduction. Then for advanced books, Prolog only has a handful and of that only a few are of value. To learn the true art of programming in Prolog is something that only one or two books really are of mention.
There are a few sites for learning Prolog, but many only skim the surface and of the web sites that teach Prolog most I would not recommend for a self-learner as they can leave you with more questions than answers. For more advanced topics the only web site of value I note is The Power of Prolog by Markus Triska
While there are several places to get online help with Prolog, the one I use is StackOverflow with the Prolog tag.
The key concepts to learning Prolog are not intuitive. Object-Oriented has state, and functional is stateless with pattern matching (one way). Prolog is stateless with unification (think bi-directional pattern matching). Thinking in recursion has to be natural, processing lists must be second nature, constraint problems are common, difference list, use of syntactic sugar with DCGs, the operator definitions such as xfx, xfy, xf are different than most languages, reification, SLD, logical purity, program slicing, predicates vs. functions, MGU, and other concepts not seen in other common languages.
One first has to learn unification and get it correct before moving forward. The problem here is that sometimes the class has to move forward before a student understands unification and then the rest of the course is endless confusion to the student. Also unification is symbolic and getting students to understand that abstract concept is sometimes very hard. On one test I gave to drive the point home, part of the unification test was with English letters, part with Greek letters and part with symbols like a snowman. After unification comes backtracking or backward chaining which gives Prolog non-deterministic programming. List processing is typically next and that is another topic that can lose many students. When teaching list processing I teach induction with a base case and induction step(s). Cut is another topic that loses many students and can make or break many programming solutions. The point here is that you may have to proceed slower at first and then pick up the pace or risk losing many of the students and there are many key concepts that rely on previous key concepts where only a complete understanding will suffice.
Note: I normally provide links to the keywords but here have purposefully left them out so as to give others a taste of what it means to try and understand Prolog by trying to put these ideas together by themselves. I think Prolog is great and use it weekly but I know when and where to use it appropriately.
The best concepts of Prolog are typically incorporated into other languages as libraries or calls to external systems. In particular constraint solving is very useful but systems like Z3 can be used instead for other languages.
There may be other languages that can do what Prolog can do and do more. e.g. Mercury or expand on Prolog as a proof assistant, e.g. Coq
Very few companies seek out employees who know Prolog. Universities want their graduates to get hired. Why teach a student something that won't get them hired? Also since many companies don't use Prolog, if you know Prolog and try and advocate for it in a company, you are probably going to be on the losing side. Not that I find any of this agreeable, but that is reality.
With regards to AI Prolog gives closed world answers and while that is beneficial for some AI problems, IMHO is an Achilles heal for others. As an example, when it comes to classifying pictures I would not use Prolog but a deep neural network.
As Guy Coder says, Prolog doesn't help a lot with employment. But it goes a bit farther than that. As educators we normally teach students in CS how to build things. Logic Programming languages such as Prolog have other strengths, but building systems isn't their main goal. It therefore doesn't well support the courses that follow in most of the curriculum.
Logic Programming can be extremely important in some fields, such as (duh) Logic and also in AI, but not, generally speaking, in building information systems.
Actually, Logic Programming isn't the only useful tool that is seldom used as a first language. A CS curriculum isn't likely to treat SQL as a first programming language either, as useful (and powerful) as it is.
The main thing about these languages is that they focus on the answers themselves, not the algorithms used to find the answers. They are about the what rather than the how. In CS, we build things and so the focus is mainly on the how, especially at the start.
Later on, such descriptive or declarative language can be extremely useful and there are courses that go into how they work internally, but implementing those algorithms isn't something the typical programmer often does.
In the future, this may change, but I think we are many years away from having systems so powerful that we can just, in general, describe what we want and have the system figure out how to achieve it. It is a long term goal, of course. Just so long as Skynet doesn't come along first.
Prolog promises "programming in logic", but you end up worrying about the order of your predicates, and have to be acutely aware of the order in which they are recursively (procedurally!) tried by your interpreter.
Too much confusion, even for a non-beginner.