3 ms·
> ...by far the biggest cognitive problem that they have with this language is understanding what the interpreter is doing at any point in time. Prolog’s attemp
by derefr 8y ago
> ...by far the biggest cognitive problem that they have with this language is understanding what the interpreter is doing at any point in time. Prolog’s attempt at being declarative ... is the problem: how to get a computer to do something without telling it what to do?
I mean, people use SQL just fine without understanding how the DB is going to accomplish their queries.
Maybe Prolog just doesn't have the same level of tooling as SQL for deducing "what's going to happen", e.g. an equivalent to SQL's `EXPLAIN ANALYZE`?
> The traversal of a search space in which choice-points are introduced whenever multiple clauses match the current computational goal and a process of (possibly partial) variable instantiation ... and worse of all, the order in which you wrote your clauses in the program makes a difference to how it gets executed and, indeed, whether any part of the program is reachable.
Some people (more than use Prolog) use Erlang—even the parts like chained binary pattern-matching†—just fine. And some people (still more than use Prolog) use the MLs just fine, too, including functional combinators and passing around monadic bindings, despite this playing utter hell on determining "whether any part of the program is reachable."
† `foo(<<A/32,B/A,Rest/binary>>)` — an Erlang clause-head which takes a binary string, and attempts to unify the variable A with the first four bytes of it, and B with the next variable-A bytes of it, and Rest with, well, the rest of it. I.e. A is taken as a uint32 and used to calculate the bounds of a slice on B, all during the attempt to pick a clause to execute. This is common, idiomatic code.
> That this process of computation is difficult to grok is especially noticable when you try to debug a Prolog program. Computations get undone when attempts at satisfying a goal fail...
People write Solidity code for the Ethereum VM just fine. (In fact, this one is kind of hilarious; Prolog is less popular than even an arcane programming environment like the EVM—where all function calls are implicitly nested MVCC transactions that roll back any side-effects upon their Turing-machine substrate upon any trap or fault, including even rolling back the emission of logging statements and the reservation or nullification of memory.)
- jcranmer 8y agoDeclarative programming in general is notorious for being difficult to debug. SQL is the only language I can think of where this notoriety doesn't come up, and I'm honestly not sure if that's merely because I've never interacted with anyone who has had to deal with sufficiently complex queries. But the insanity that's involved with complex regular expressions, parser generators, even Python's decorator system in complex declarative projects (e.g., some build system tooling I've worked on) is commonly complained about.
- nerdponx 8y agoI've never interacted with anyone who has had to deal with sufficiently complex queries This might be a big part of it. SQL is a limited domain, with limited tools available. Doing "general purpose" programming with SQL requires advanced trickery and is implementation-dependent. Another example might be Excel, which has a declarative interface (i.e. a GUI) and a semi-declarative formula syntax.
- hodgesrm 8y agoThe standard 'debugging' problem in SQL is query optimization, namely figuring out how to make a query return in seconds instead of a week. Many engineers simply can't solve it, so a typical solution is to hand it over to a DBA and go have coffee.
- bjourne 8y agoThe difference between your Erlang example and Prolog is that Prolog "throws away" computation. The whole predicate has to match, not just the first pattern. This difference leads to very hard to predict control flow.
- derefr 8y agoTheoretically, Erlang does this as well; it just restricts the set of functions you can use in a clause-head to a language-defined set† of pure (and almost entirely O(1)‡) functions, such that you don't really worry about how much or little computation is going on during clause-head unification. † https://learnyousomeerlang.com/syntax-in-functions#guards-guards https://learnyousomeerlang.com/syntax-in-functions#guards-gu... ‡ `length(List)` is allowed in guards and is O(N), though it could be O(1) in a different VM implementation that makes different trade-offs.
- matthiasl 8y agoYour Erlang syntax is a bit off. You mean f(<<Length:32, Packet:Length/binary, Rest/binary>>) ->
- derefr 8y agoAh, sorry, yeah. I did a few good Erlang projects years ago, and am an Elixir developer now, but I never used the binary pattern matching syntax while I was writing Erlang, only needing to learn it once I was already over in Elixir-land, so I was trying to map backwards from the Elixir variation on the syntax.