tl;dr Prolog gave me a whole new perspective. Let me know programming languages that altered how you attack a problem!
I was in my second year of University studying Computer Science. I'd caught wind that the programming language for the Artificial Intelligence module wasn't a language we'd covered so far in the degree. I was excited, I thought I'd already gotten a decent grip on C, C++, Python, and Java so I was ready for anything. 😬
"Your first assignment will be to create an AI using Prolog".
What the fu*k is a Prolog were my precise thoughts. I thought I was pretty clued up on all the programming languages out there. Why are we learning a programming language I've never even heard of?
I went home, did some googling to try to find out what this Prolog thing was.
"Prolog is a logic programming language associated with artificial intelligence and computational linguistics". Right, AI, that's probably why we're learning it, or is it because the language was made in Marseille, France, and my Lecturer is French? 🤣
The following week we had our first introduction to the language, I quickly realised that no matter how well I knew C, C++, Python or Java it was not going to help me in understanding Prolog. It took me no time at all to grow hatred towards the language. It just doesn't. make. sense.
I went through countless tutorials, tried tonnes of example problems, took apart people's solutions to problems line by line, it just wasn't going in. I would take apart some code and trick myself into thinking I understood how it worked but when it actually came to coding in Prolog myself, my brain stopped.
I'd had enough of struggling with Prolog. After I'd exhausted all possible avenues on the internet to learn it I'd decided to actually listen to my Lecturer and get the recommended book.
Prolog Programming For Artificial Intelligence - Ivan Bratko. This book changed everything. I pretty much devoured the book in a day. I was hooked, the book had me wanting more. I went back to the coding problems I'd struggled on just a day before and could think of 20 different ways to solve it, I began to LOVE the language. In class, I went from the student who condemned everything about the qwerky language to Prologs biggest advocate.
Prolog is a logic programming language. You define relations which are known as Facts and Rules. You then query your knowledge base and it returns the output based on those facts and rules. Solutions are typically written by recursion, the program calls itself until some objective has been satisfied, which is often referred to as the base case or final state. Backtracking is another important feature of the language: when a subgoal is not satisfied prolog backtracks meaning it traces its steps backwards to the previous goal and tries to satisfy it.
Prolog is one of those very rare languages where I'd say that a non-programmer would likely have as good as or if not better experience understanding it than a programmer. See us developers are so accustomed to imperative programming, telling the compiler what we want to happen, step by step. When we're forced to think declaratively (Writing code that describes what we want, our desired result but not necessarily how to get it) it hits our brains for six, well, mine at least.
Prolog gave me a whole new way of looking at a problem, it made me ask different questions. Rather than asking what is the next step, I think of the desired state and the processes involved to get to that state.
If you have a programming problem and you were tasked to solve it in 3 different languages be it Java, C#, C++. It is very likely that you would solve the problem pretty much exactly the same in each, taking the same steps to manipulate the input to get the desired output. Yes, I get you'd probably use different constructs of each language but likely the general approach would be the same. However, if you learn Prolog you can ask yourself "How would I solve this in Prolog". And although attempting to map your Prolog solution to that of an imperative solution might not necessarily be the best approach, it opens avenues for alternate possibilities and expands conceivable results.
This blog was really supposed to be a #discuss as I am mainly interested in hearing how learning new languages altered how you think about solving a problem. I know that learning Functional programming languages has profound impacts on some peoples outlook so I'd love to hear from you!
Follow me on twitter if you don't want to miss out on absolutely brilliant programming insight: 🤣 @luke_garrigan
Thank you, if you like my rambling check out my personal blogging site at https://codeheir.com/