TL;DR
Prolog programmers often face significant challenges from outdated coding practices, such as global state, impure output, and low-level constructs. This article highlights the dangers and recommends best practices for writing cleaner, more reliable code.
Prolog programmers frequently encounter serious issues stemming from outdated coding practices, which can lead to incorrect solutions, unpredictable behavior, and difficult debugging, according to recent discussions on Hacker News.
These issues include reliance on global state modifications via predicates like assertz/1 and retract/1, which create implicit dependencies and can cause unpredictable failures if not managed carefully. Additionally, using impure output methods, such as printing directly to the terminal within predicates, hampers testing and reduces code reusability. Many programmers also stick to low-level constructs like arithmetic predicates (is/2, =:=/2), despite the availability of more declarative, constraint-based alternatives that simplify understanding and teaching.
One common example of problematic code is the ‘horror factorial’ program, which uses cut (!) and low-level arithmetic, resulting in limited generality and errors during most general queries. Experts recommend adopting pure, monotonic constructs, such as CLP(FD) constraints, to produce more reliable and flexible programs, and to avoid outdated features that complicate debugging and maintenance.
Why It Matters
This matters because reliance on outdated or impure practices can cause incorrect program outputs, make debugging difficult, and hinder code reuse. For industries and educational contexts that depend on Prolog, adopting best practices enhances code correctness, maintainability, and the ability to reason about programs declaratively.

Competitive Programming 4 – Book 1: The Lower Bound of Programming Contests in the 2020s
As an affiliate, we earn on qualifying purchases.
As an affiliate, we earn on qualifying purchases.
Background
Prolog’s evolution over the past two decades has introduced powerful declarative features such as constraints and improved language constructs. Despite this, many programmers continue to use low-level predicates and impure techniques, often due to familiarity or lack of awareness. The ‘horror factorial’ example exemplifies how outdated practices lead to limited generality and errors, highlighting the importance of embracing modern, declarative approaches.
“It is ill-directed rebellion to cling to outdated features, for life is not lived backwards nor tarries in yesterday.”
— Anonymous Prolog expert on Hacker News
“Using declarative constraints like dif/2 and CLP(FD) can significantly improve the correctness and clarity of your programs.”
— Prolog community advocate

Analysis and Visualization Tools for Constraint Programming: Constraint Debugging (Lecture Notes in Computer Science, 1870)
As an affiliate, we earn on qualifying purchases.
As an affiliate, we earn on qualifying purchases.
What Remains Unclear
Details about how widespread these outdated practices remain in industry and education are still emerging. It is also unclear how quickly the community will adopt newer features or phase out reliance on low-level predicates.

Natural Language Processing with Prolog: A Practical Guide to Building Intelligent Linguistic Systems Using Logic Programming
As an affiliate, we earn on qualifying purchases.
As an affiliate, we earn on qualifying purchases.
What’s Next
Next steps include increased awareness through community discussions, educational efforts to promote declarative programming, and updates to Prolog tutorials emphasizing modern best practices. Monitoring the adoption of constraint logic programming features will be key to assessing progress.
Prolog code refactoring software
As an affiliate, we earn on qualifying purchases.
As an affiliate, we earn on qualifying purchases.
Key Questions
What are the main dangers of using global state in Prolog?
Using predicates like assertz/1 and retract/1 can create implicit dependencies, leading to unpredictable program behavior, difficult debugging, and maintenance challenges.
Why is impure output problematic in Prolog?
Printing directly to the terminal within predicates prevents easy testing, reduces code reusability, and hampers reasoning about program correctness.
What are the benefits of using declarative constraints instead of low-level arithmetic?
Declarative constraints simplify understanding, improve correctness, and make programs more general and easier to debug.
Is reliance on outdated features still common among Prolog programmers?
While some still use low-level constructs and impure techniques, there is a growing movement towards modern, declarative programming practices, though adoption varies.