9 ms·
I am curious if you used a visual debugger for prolog? (or for a procedural language) printing things to the console is the poor man debugger.
by simion314 8y ago
I am curious if you used a visual debugger for prolog? (or for a procedural language) printing things to the console is the poor man debugger.
- tabtab 8y agoA big problem with visual debuggers is that they are too blunt of an instrument. Often I wish to examine specific things under specific conditions and thus use conditionals to narrow down what's being explored instead of bajillion breakpoints and/or log records. Debuggers could add conditional expressions, but then they'd be re-inventing WRITE statements anyhow. As far as the nearby statement that maybe I didn't learn dissection correctly, that may indeed be the case, but was also my original point: perhaps the real problem is that nobody knows how to TEACH functional/logical programming right, and that's why they have not caught on in the mainstream despite being around several decades. I'd love to "get" the benefits, but it just won't click. Sometimes you have to teach programmers how to think, not just what to think.
- tom_mellior 8y ago> Debuggers could add conditional expressions, but then they'd be re-inventing WRITE statements anyhow. SWI-Prolog's debugger can be invoked conditionally whenever you want from inside your running application. I've used it many times, and the code is simply: (Condition -> gtrace ; true) It's true that you could stick a write there, but you would have to think about what pieces of data you will need. Your mileage may vary. I've found this style a lot more useful than "traditional" debuggers where you set breakpoints beforehand and hope you hit them, as you say. > As far as the nearby statement that maybe I didn't learn dissection correctly, that may indeed be the case The point was more specifically that you didn't learn Prolog properly (or at all) and don't realize that it forces you to dissect your code. As I said, in Prolog you cannot nest loops. You cannot nest loops. It's hard to write a big non-dissected piece of code if you cannot nest loops. > perhaps the real problem is that nobody knows how to TEACH functional/logical programming right I agree with regards to logic programming. We need better free tutorials. I don't particularly like the linked one, it feels like it doesn't start at a beginner's level. I would be interested if anyone who didn't know any Prolog before has managed to learn Prolog from it.
- pjmlp 8y agoI learned logic programming before learning Prolog. We got our introduction to it via the Tarkis' World book (90's edition). https://ggweb.gradegrinder.net/tarskisworld https://ggweb.gradegrinder.net/tarskisworld
- tabtab 8y agoRe: "but you would have to think about what pieces of data you will need." -- But with procedural you don't have to think much; the parts are right there to selectively examine. Re: "in Prolog you cannot nest loops...It's hard to write a big non-dissected piece of code if you cannot nest loops." -- But nesting is good for modularity. It's sometimes called "step-wise refinement", which is a brilliant abstraction that is usually easy and natural to comprehend. Nesting is how we have been splitting up society since the dawn of civilization: countries, states, counties, cities, etc. (or equiv.) Similar for big militaries. (Maybe this is a meta form of Conway's law? Either way Conway was on to something.)
- triska 8y agoRegarding your last sentence: Yes, I can confirm that this has happened, to a reasonable extent of "learned" in the sense that people went on to write programs using this material. However, I do not know how common this is, since I almost exclusively get feedback from those who found the material suitable. There were definitely complete beginners among them. For instance, here is a discussion that happened a few months ago, where it appears that also beginners comment positively: https://www.reddit.com/r/programming/comments/7pbkfv/great_free_book_on_modern_prolog_with_indepth/ https://www.reddit.com/r/programming/comments/7pbkfv/great_f... More recently, two university instructors started to use this book in courses that assume no previous knowledge about the language: Andrej Bauer in his specialist elective course Principles of Programming Languages at the University of Ljubljana: https://ucilnica.fri.uni-lj.si/course/view.php?id=67 https://ucilnica.fri.uni-lj.si/course/view.php?id=67 Norbert Zeh in his Principles of Programming Languages lectures at Dalhousie University in Canada: https://web.cs.dal.ca/~nzeh/Teaching/3136/index.html https://web.cs.dal.ca/~nzeh/Teaching/3136/index.html Much of my current work is aimed towards making the teleteaching environment GUPU available in a free Prolog system: https://www.complang.tuwien.ac.at/ulrich/gupu/ https://www.complang.tuwien.ac.at/ulrich/gupu/ This will help a lot to teach Prolog to beginners in a scalable way. On a rather personal, and maybe controversial, note: I regard the self-taught Prolog master as prevalent as for example the self-taught piano, chess or Zen master. In my experience, learning Prolog properly requires dedicated guidance, and it would be highly unusual to achieve mastery without it.
- simion314 8y agoYour Console.log will not help you in a recursive function
- tabtab 8y agoIf you have the right tracking variables, it's great for the job: "console.write(currentNodeID, parentNodeID, depthLevel, nodeVisitCount);" And one can wrap that into a conditional if they don't want to echo the entire journey. It's usually good to create such tracking variables in non-trivial systems anyhow. Bleep happens.
- tabtab 8y agoCorrection: should be "nodesVisitedCount". Also note that output formatting was sacrificed for brevity of the example.
- dozzie 8y ago> printing things to the console is the poor man debugger. You may want to try working with network before making this statement, when you cannot step through a function because of timeouts. Or maybe even looking at tracing debuggers, like strace, ltrace, or Erlang's gdb, which all do little more than "printing things to the console". Logging (and logging-like tools) is a very important way of debugging services, you know.
- simion314 8y agoSure, if you do not have the debugger you use the logging, but you will miss the main features of a debugger like see the entire call stack, all the variables and parameters at each call stack level, you can evaluate expressions in that context. I use logging to log problems that would happen on a user machine or server where I can't open the debugger and see it. When an error happens on a server or a customer machine and I can't use the debugger I have to guess the problematic section and put lots of logging and try to reproduce, then add more logging and so on until I find the problem. Debugger are much better but I notice my other colleagues do not use them and prefer the console.log or similar
- tabtab 8y agoEach do better under certain situations. One is a hammer and another a tweezer. Different debugging jobs/steps need different tools. But the real question is whether the hammer/tweezer kit that comes with Prolog is better than the hammer/tweezer kit of other paradigms/languages. In my personal opinion and observation, the hierarchical step-wise refinement approach is quicker for most developers to grasp, learn, and debug. Maybe if those of us who don't see the grokkability benefits try it for 50 years, it will finally click. But you better hope to be in management by then because the programming field doesn't like "old people". I'm just the messenger.
- simion314 8y agoProlog is ideal for some kind of problems, good programmers should know what logic programming is and what problems are perfect for logic programming, then if in real life you hit such a problem you can chose prolog or a library that does logic programming.