DEV Community

Cover image for The Programming Language That Changed My Life!
Luke Garrigan
Luke Garrigan

Posted on • Updated on

The Programming Language That Changed My Life!

tl;dr Prolog gave me a whole new perspective. Let me know programming languages that altered how you attack a problem!

Backstory

Introduction to the language

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.

Salvation

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.

Ivan Bratko 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.

What is Prolog?

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.

What's so special about Prolog?

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.

Finally

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/

Top comments (70)

Collapse
 
humrochagf profile image
Humberto Rocha

Awesome post, I had contact with Prolog at my Computer Science course, I struggled a lot with it. Maybe it's time to go back to it with this book that you recommend to give it another try.

For me every programming language that I experienced changed my life in some aspect.

  • C made me care a lot to resource management.
  • Assembly to understand even more how things work barebone. And also to be graceful for the existence of compilers and interpreters 😄
  • Java to understand the classic design patterns
  • Python to discover my passion for coding, the community, open-source, and to make me express myself with code better.
  • JavaScript and TypeScript helped me so much to understand events and how async work
  • Shell was the gateway to server task automation
  • Now elm developing my passion for functional programming

Each language exposed me to different ways of seeing things ☺

Collapse
 
edyzakaria profile image
edyzakaria • Edited

Very agree with you. Learnt foxpro and visual foxpro to understand more on data processing.

Learnt BASIC to know about structured thinking and modularity.

I don't have much time to study more. Now i want to learn python.

I glad i read this post on prolog, it challenged my mind and i appreciate this comment, it gives me insight on how the other programming languages bring impacts to you, at least for python. 😁🙏

Collapse
 
lukegarrigan profile image
Luke Garrigan

Completely agree. It seems me and you have had very similar learning paths!

Collapse
 
twitmyreview profile image
Priyab Dash

Great spirit we should always try to learn something new from a programming language.

Collapse
 
choroba profile image
E. Choroba • Edited

Moreover, there's a language with syntax similar to Prolog, so learning Prolog might make it easier for you to learn the other one, too. Its name is Erlang and it's still used in production in many businesses.

fac(0)            -> 1;
fac(N) when N > 0 -> N * fac(N - 1).
Enter fullscreen mode Exit fullscreen mode
Collapse
 
xtofl profile image
xtofl

Erlang (and OTP!) is nice indeed.

But the paradigm is different than Prolog's: in functional programming languages, you'll end up with a function you can call.

In Prolog - a declarative language - you'll end up with a bunch of predicates that can be solved. A system of (logical) equations that you can generate solutions for.

Collapse
 
humzakhan profile image
Humza K. • Edited

For anyone interested in knowing the business case for Erlang, WhatsApp uses it extensively. Might make a good case study!

Collapse
 
ssimontis profile image
Scott Simontis

It also powers newer versions of Chef Server.

Thread Thread
 
exadra37 profile image
Paulo Renato

Well as per this tweet Erlang powers more than 90% of Internet, once its in Cisco routers ;)

And now you have also Elixir, that runs on the same virtual machine, the BEAM.

Thread Thread
 
ssimontis profile image
Scott Simontis

Elixir is very cool, if I only had more time I'd be digging into it more!

Thread Thread
 
exadra37 profile image
Paulo Renato

Elixir is very cool, if I only had more time I'd be digging into it more!

I am playing now with it, and I am loving Live View :)

It seems that you work in embed systems, so you must already know the Nerves Project?

Thread Thread
 
ssimontis profile image
Scott Simontis

I have indeed! While I do have a few Raspberry Pis, I would like to see if I can get it running on some other boards...NXP makes some ARM Cortex A7 microcontrollers that should have enough memory to run this, and the Nvidia Jetson is another candidate. It will be quite an adventure porting it to a new platform, but I will definitely learn a lot!

Did not know about live view, very cool! I haven't played around with the web framework at all, but it looks really cool.

Thread Thread
 
exadra37 profile image
Paulo Renato

NXP makes some ARM Cortex A7 microcontrollers that should have enough memory to run this

In the words of Joe Armstrong, anything have enough memory to run Erlang/Elixir/Nerves, and this his because Erlang was made 30 years ago, and on that time computer where not having the processing power of this cheap boards.

I need to start playing with this boards to, must be a lot of fun ;)

Did not know about live view, very cool! I haven't played around with the web framework at all, but it looks really cool.

It's a big thing to replace Single Page Apps in a lot of use cases.

Collapse
 
lukegarrigan profile image
Luke Garrigan

ooh lovely, sounds like a weekend challenge!

Collapse
 
nuculabs_dev profile image
Nucu Labs

There's also Elixir which another language that runs on the Erlang VM, a bit similar to Prolog. But, If you wanna learn Erlang checkout out this book: learnyousomeerlang.com/content

Thread Thread
 
mt3o profile image
mt3o • Edited

Elixirs syntax is little nicer than Erlangs. Both of these are interoperable, they work on the same virtual machine called BEAM. And what they excel - are concurrency and resilience. They (elixir and erlang) are awesome candidates for languages to learn in the age of microservices.
One of the bigger recognizable companies that use Elixir is Discord. And Ericsson uses Erlang, but they are not as sexy ;)

Discord guys have a blog on Medium and it's pretty interesting.

Thread Thread
 
assertnotnull profile image
Patrice Gauthier

Clarifications here though I'm a noob at Elixir. Elixir extends Erlang because you can invoke Erlang functions. Erlang was developed by Ericsson and is used for running the cellphone towers insuring uptime which also I think makes it great for microservices.

Collapse
 
cubiclebuddha profile image
Cubicle Buddha

Honestly, I crap on Javascript a lot (sorry!), but it was the first language that gave me the freedom to explore and the autonomy to have fun with software... and it’s that freedom and fun that has kept me invested as a developer all those years!!! 🥰😍

Collapse
 
lukegarrigan profile image
Luke Garrigan

Haha love this, we all crap on Javascript but we all seem to use it 😂 and secretly love it really!

Collapse
 
mjamsek profile image
Miha Jamsek

I had the privilege of being taught prolog by prof. Bratko. He had a knack for explaining problems so that everyone understood them, no matter the diffuculty.

Collapse
 
lukegarrigan profile image
Luke Garrigan

Oh wow that’s amazing! I envy you, his book completely saved me. What a guy.

Collapse
 
gypsydave5 profile image
David Wickes • Edited

Lisps. All of them. Scheme changed how I write JavaScript (and any language with functions), Common Lisp changed the way I think about programming - literally. I see more languages that read themselves instead of machines that do stuff. It was weird. It still is.

Collapse
 
deciduously profile image
Ben Lovy

This is why I can't keep my eye off projects like Nim and Julia. They somehow managed to ALGOLize lisp-style metaprogramming.

Collapse
 
combinatorylogic profile image
combinatorylogic

Yes, these two are doing it right, and is a very unfortunate myth that you need S-expressions in order to do an AST-level metaprogramming comfortably.

I even demonstrated it with a C syntax, just for giggles: github.com/combinatorylogic/clike

Thread Thread
 
gypsydave5 profile image
David Wickes

You have my attention 😄

Thread Thread
 
combinatorylogic profile image
combinatorylogic

Feel free to browse that project and everything else there, pretty much all the stuff I'm working on is related to static metaprogramming one way or another. Also, take a look at the generated docs and a small tutorial

Collapse
 
610yesnolovely profile image
Harvey Thompson • Edited

Lisp! Emacs!

I still am totally surprised when I explain "but you can totally rewrite the editor while it's running" and most Software Engineers just blink at you as if you said "THE MOON IS MADE OF COWS" or something similarly weird and non-sensical.

Collapse
 
leewarrickjr profile image
Lee Warrick

Python tuples and sets made immutability and typescript enums make a lot more sense to me.

Good post! It's good for experienced coders to remember what it's like to be totally lost when learning. We take a lot for granted working in similar languages so often

Collapse
 
andreasjakof profile image
Andreas Jakof

I "learned" Prolog in school. We were about it for about half a year in our CS course. And I was fascinated with the language and I did not have the same issues as you had, but that may be, because I was not yet firmly into imperative programming.

On the other hand, after some more years, when I was firmly in the grasp of IP and I was learning C# 4.0, it was lambdas and Linq2SQL, that were very hard on my brain.

Now I really like them and when I was dabbling a bit into F#, my first thought was just "Oh ... everything is a lambda here".

Collapse
 
riazyali profile image
riaz-y-ali

Very interesting post. When I started my classss for computer sciences back in 1988, for few weeks I wasn't even comfortable touching the computer. Eventually the same field changed my life and I was considered a very good developer. Then came the change of era from procedural languages to OOP with GUI based interfaces to write software in VB, I lost it there and could not handle OOP concepts with such a programming interface. Anyway, ky career never required me to ever worry about writing code anymore. But I guess once a programmer always a programmer. I developed that itch lately for writing software and I realized I am way behind and all of this is completely new to me. Lately I have started reading again and took Python as first one to get myself comfortable. Reason was that while it has OOP concepts, it also has a procedural language style. Not sure if all this would bring some change in my life or not (_)

Collapse
 
lukegarrigan profile image
Luke Garrigan

Thank you for your comment. I have had the same thought about moving from a programming job into a management role, I think I'd really miss coding!

Collapse
 
riazyali profile image
riaz-y-ali

At the age of about 50 where I have seen great success in my career working in senior management roles for fortune 100 companies, I still feel that I took up management roles very early in life.

Collapse
 
antonmelnyk profile image
Anton Melnyk • Edited

My first and foremost language was Ruby. Probably if not Ruby I wouldn't even bother learning programming but I was so captivated and inspired by Ruby code, its elegance and expressiveness coupled with interesting "everything is an object" model that I stick to it. Then I discovered Rails, web development and things got rolled further!

Collapse
 
shayneoneill profile image
shayneoneill

Its worth noting that Prolog and SQL actually have a LOT in common. Both are declarative languages structured around tables of fact tuples and relationships between them. And then you give it a specification and it returns a set of tuples that match the specification. Prolog of course does a whole lot more (and it perhaps does it an injustice to make the comparison), but if you really boil down to it, the two are very similar. It'd be nice if makers of new databases had another look at prolog. If you wanna go 'past' SQL, maybe Prolog is in fact the future!

Collapse
 
nlharri profile image
László Harri Németh

I studied Prolog in 2003 in the university course Declarative programming. Before that I didn’t even hear about this kind of different programming paradigm. I had good experiences with Java, C and C++.
The professors and PhD students who led the course of Declarative programming wrote a quite detailed book about the language and how the Prolog interpreters work. But I struggled with it a lot in the first weeks. We had small homeworks and a final closing homework - we needed to solve a quite complicated puzzle with Prolog. Those were challenging. But in the end it completely changed the way I was thinking about solving problems with programming.
There was another language taught during the course of Declarative programming: SML (Standard Meta Language). It’s a functional programming language.

Collapse
 
erikiva profile image
Natalia Vidal

I had to study Prolog for my Expert systems class and once I got my head around it, pretty much the way you described, I loved it and ended up using it for my MSc project. An NLP system to learn Spanish that corrected grammar, it was super fun. I keep thinking about trying something else with it.

Collapse
 
lukegarrigan profile image
Luke Garrigan

That project sounds awesome! Every now and then I go to ic.unicamp.br/~meidanis/courses/mc... to get back up to speed with Prolog as I love the language so much 😃

Collapse
 
jpivarski profile image
Jim Pivarski

The best thing about learning a radically different language is going back to the language you "have to" use (job or other constraints) and finding that you can translate what you've learned into the old syntax.

For me, this was writing Python "as if" it were a functional language—becoming very aware of mutable state and limiting it, making better use of list comprehensions, and reasoning about types even though the language doesn't enforce types.

Languages open us up to new ideas, but once we have them, we can take them back to the mainstream. I don't know if that's possible with something as different as Prolog, but I'd like to see it!

Collapse
 
lukegarrigan profile image
Luke Garrigan

The best thing about learning a radically different language is going back to the language you "have to" use (job or other constraints) and finding that you can translate what you've learned into the old syntax.

YES, couldn't have put this any better.

Collapse
 
sd_devto profile image
SD Dev.to • Edited

Followed. And now you got me wanting to take a closer look at Prolog.

Edit: I enjoy Python programming. I don't have anything insightful to say right off the bat, except that Python, at least to me, more closely mirrors human logical control-flow (my introduction to programming was COBOL, then I really cut my teeth on C#).

Collapse
 
lukegarrigan profile image
Luke Garrigan

Thank you, do it! I can't recommend it enough.

Collapse
 
amosbaker profile image
amosbaker

Prolog was interesting but I always had difficulty seeing it as something that could solve everyday problems. Haskell melted my brain a bit, all the things I thought I knew about functional programming were secretly just whispers in the dark.

Collapse
 
combinatorylogic profile image
combinatorylogic • Edited

Prolog can help a lot with solving everyday problems. Just keep in mind that you can embed Prolog into pretty much any language (with a different degree of clumsiness, of course). See Clojure core.logic or MiniKanren for multiple Scheme implementations for example.

A standalone Prolog is a weird beast with few real world applications. An embedded Prolog is a power tool applicable everywhere.

For example, I often use elements of Prolog to implement code analysis passes and optimisations in compilers, and this way it's often an order of magnitude shorter than any ad hoc solution. I use Prolog to encode decision making systems and to explain their decisions (or generate a code from them). I use Prolog with a CLP(FD) to do all sorts of constraint solving problems, from making time tables to scheduling multi-cycle operations in a high level hardware synthesis.

Once you start thinking in Prolog, all problems start to look like nails suitable for this hammer.

Collapse
 
normabkrug profile image
normabkrug

good share.

Some comments may only be visible to logged-in visitors. Sign in to view all comments.