Sign in to follow this  

Functional programming in Games Industry?

This topic is 4127 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm doing a Computing with Games Technology module and in the final year we are required to pick electives. The ones recommended by the course leaders are Software Agents and Functional Programming. For the latter we will be using Haskell. My question is this... does a Functional Programming language such as Haskell have a serious place in the games industry? I know C++ is the most common language used in the games industry. I've been looking at Haskell and it is bloody hard to get to grips with even with the various online tutorials.

Share this post


Link to post
Share on other sites
Crash Bandicoot used LISP for scripting.
Jak & Dexter used LISP as the base language, and used GOAL (a Scheme-like language based on LISP) for scripting.

Share this post


Link to post
Share on other sites
> Learning a functional language will, hands down, make you a better programmer in all languages.

It certainly is more difficult than any other language I've come across.

> It can be good for scripting and AI

Ok this is interesting. I'll look into the LISP thing aswell.

Share this post


Link to post
Share on other sites
Quote:
Original post by spaceJockey123
> Learning a functional language will, hands down, make you a better programmer in all languages.

It certainly is more difficult than any other language I've come across.

Only when you're used to thinking in terms of imperative languages. [grin]

At my university, the first language we learn is ML, a functional language. Then we get Java in the semester after that.
And it almost never fails that those who have never programmed before pick up ML without too much trouble, while those who have already used C++/Java/whatever struggle to understand it.

Share this post


Link to post
Share on other sites
Quote:
Original post by Spoonbender
At my university, the first language we learn is ML, a functional language. Then we get Java in the semester after that.
And it almost never fails that those who have never programmed before pick up ML without too much trouble, while those who have already used C++/Java/whatever struggle to understand it.


I agree. Most of my students (I teach Caml Light) who already know imperative languages will try "the imperative way" and miserably fail, while the innocent will try "the functional way" (the only they know) and succeed.

Share this post


Link to post
Share on other sites
Quote:
Original post by Deyja
Learning a functional language will, hands down, make you a better programmer in all languages.

Why?

I'm learning ML, and at the moment am writing a parser for a WFF in ML for an assignment, and while I find myself understanding more about the functional programming paradigm, and about how I can write much cleaner and more elegant code for some things in ML (and most likely, by extension other functional languages), how will this help me programming in C++?

Just by helping me see more possible solutions for different problems?

PS. By the way, the site I directed you to was written by my lecturer in the subject the assignment is for.

PPS. Why is it that whenever people want to make a note of something in code (my lecturer :D ), or sometimes elsewhere, they use "NB"? It means Nota Bene, right? "Note well?" Well, why was it originally used? Do mathematicians use it a lot?

Share this post


Link to post
Share on other sites
It's just latin. Like IE, which means 'for example' in latin. Or was that EG?

Quote:
how will this help me programming in C++?


It gives you another perspective on programming. For example, when you only knew C, you probably wondered 'What do I need OOP for? How can learning it possibly make my C code better?'. Well, it can, and it did. OOP doesn't require language support; it's a design paradigm, not a syntax paradigm. The same is true for functional programming. You can do it in C++ just fine. And, if you are using the standard algorithms, you already are.

Also, C++ Template Meta Programming is functional programming.

Share this post


Link to post
Share on other sites
I seriously recommend you do take that module and get a good book that teaches you the functional paradigm properly (with haskell as the language used) like Haskell: The Craft of Functional Programming, you cannot just pick this up on a few (online) tutorials and expect to know it properly.

Also you should be aware of the fact that haskell is a purely functional language where as other functional languages like SML and lisp are impure functional language. A purely functional language is one where all expressions/functions are referentially transparent meaning no assignment, no inplace update, the result of a function is always the same with the same input, in other words no side-effects.

Don't let this put you off there are many benefits of having this restriction as you will find out and there is a method of emulating imperative features or stateful computations using monads (you'll read about it).

Another thing that makes Haskell different from many languages is that it is a nonstrict language, meaning that all expressions/functions are evalutaed expressions are evaluated lazily (lazy evalution). This allows for some very powerful/elegant techniques/patterns such as writing infinite data structures, more efficent implementations in certain places, etc, etc.

Put it this way haskell is one of the most elegant & sexiest languages you could ever learn as of current. Learning Scheme is a good complement with haskell too.

Why Functional Programming Matters
Why Haskell matters
The Evolution of a Haskell Programmer (this is something you can measure your haskell/functional knowledge by and have some laughs at the sametime)

[Edited by - snk_kid on August 20, 2006 12:31:49 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by ToohrVyk
Crash Bandicoot used LISP for scripting.
Jak & Dexter used LISP as the base language, and used GOAL (a Scheme-like language based on LISP) for scripting.


Yea, but have you seen any of the source code written in GOAL? None of the snippets I have seen (there were a few posted on a mailing list a while back) were written in a particularly functional style. The language itself was not Scheme-like in a few of those important areas in which Scheme stands apart from the other lisps (TCO and first class continuations, for example), and it had a number of low level mechanisms to subvert language safety (for example, it featured an inline assembly language). GOAL is not so much a success story for functional programming as it is a success story for LISP and it's ability to easily support several paradigms, to provide an extensible environment, and to give the programmer a suite of high-level interaction facilities (such as on-line recompilation, restartable conditions, and a very useful debugger and object inspector).

Share this post


Link to post
Share on other sites
it's a bit late for me to check out these videos so I'll check it out in the morning.

> seriously recommend you do take that module and get a good book that teaches you the functional paradigm properly (with haskell as the language used) like Haskell: The Craft of Functional Programming, you cannot just pick this up on a few (online) tutorials and expect to know it properly.

That book was actually the first thing I got to read (it's the recommended text for the module) but the way things were described to me I found quite complicated. Those online tutorials that you mentioned are what I've been looking at today - I got the links from Wikipedia. I actually have more of an understanding of the language through these tutorials... once I'm done I'll have another try at that book.

> Learning Scheme is a good complement with haskell too.

What is Learning Scheme?

Share this post


Link to post
Share on other sites
Quote:
Original post by The Reindeer Effect
Quote:
Original post by ToohrVyk
Crash Bandicoot used LISP for scripting.
Jak & Dexter used LISP as the base language, and used GOAL (a Scheme-like language based on LISP) for scripting.


Yea, but have you seen any of the source code written in GOAL? None of the snippets I have seen (there were a few posted on a mailing list a while back) were written in a particularly functional style. The language itself was not Scheme-like in a few of those important areas in which Scheme stands apart from the other lisps (TCO and first class continuations, for example), and it had a number of low level mechanisms to subvert language safety (for example, it featured an inline assembly language). GOAL is not so much a success story for functional programming as it is a success story for LISP and it's ability to easily support several paradigms, to provide an extensible environment, and to give the programmer a suite of high-level interaction facilities (such as on-line recompilation, restartable conditions, and a very useful debugger and object inspector).


They're also not using GOAL anymore.

Quote:
"In all honesty, the biggest reason we're not using GOAL for next-gen development is because we're now part of Sony. I can only imagine Sony's shock when they purchased Naughty Dog a few years back, hoping to be able to leverage some of our technology across other Sony studios, and then realized that there was no way anyone else would be able to use any of our codebase. :)

Sony wants us to be able to share code with other studios, and this works both ways - both other studios using our code and vice versa. Add this to the difficulty curve of learning a new language for new hires, lack of support from external development tools (we had our own compiler, linker, and debugger, and pretty much had to use Emacs as our IDE), etc, means that there are clearly a lot of other factors involved. Note, however, that these issues aren't really technical problems, they're social ones.

I can definitively say that the investment in GOAL was worth it for our PS2 titles, despite the initial setup time and maintenance. Our productivity gains were huge, and were more than worth the time investment. This time around, however, the circumstances aren't quite the same. If we were still an independent studio, I'm almost positive we'd be extending GOAL for the next-generation of development. As it is, we are looking into alternative approaches (custom preprocessors, assemblers, linkers, you name it) - but all of these approaches fall short in many ways of the unified language and environment we had with GOAL.

That said, if there was a serious effort on the part of the game development community to develop and standardize a language for game development, everyone could gain the benefits without suffering the drawbacks (lack of code-sharing, learning curve, etc). And if there's enough community support, it would only be a matter of time before some really high-quality commercial tools came out to work with the language."


Anyways, to echo the sentiments of others, i'd recommend taking the functional programming elective - regardless of whether or not it's being used in the game dev industry, it'll make you a better overall developer.

Share this post


Link to post
Share on other sites
Quote:
Original post by spaceJockey123
That book was actually the first thing I got to read (it's the recommended text for the module) but the way things were described to me I found quite complicated. Those online tutorials that you mentioned are what I've been looking at today - I got the links from Wikipedia. I actually have more of an understanding of the language through these tutorials... once I'm done I'll have another try at that book.


Well there are alternative books, i've heard nothing but praise for Introduction to functional programming using Haskell, 2nd edition, Richard Bird and there is always The Haskell School of Expression: Learning Functional Programming through Multimedia by Paul Hudak.

Quote:
Original post by spaceJockey123
What is Learning Scheme?


Haskell is a statically typed nonstrict purely functional language.

Scheme is a dynamically typed strict functional language (but not always purely functional). Scheme is a dialect of lisp, a simple & elegant language (once the patheness fade away from your mind). A bible book that uses scheme and is free online Structure and Interpretation of Computer Programs (SICP) and SICP video lectures

Share this post


Link to post
Share on other sites
Before anyone is going to buy one of the Haskell books, look through them in a book store or library. They aren't that great when you already can program, even if it's only imperative.

Share this post


Link to post
Share on other sites
I cannot believe nobody's mentioned Erlang yet. Functional languages have an enormous possibility for parallelization.

There are Erlang MMORPGs, online videogames, and Internet utilities coming out all the time, due to the excellent thread and network support.

With a lot of game libraries now coming out with Erlang bindings (like ESDL) the possibility to develop robust games with a functional language is here.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Deyja
It's just latin. Like IE, which means 'for example' in latin. Or was that EG?


e.g. - for example
i.e. - that is

Share this post


Link to post
Share on other sites
Myself, I am partial to Excel.

Quote:
Original post by Deyja


Also, C++ Template Meta Programming is functional programming.


And a good example of Greenspun's tenth rule :p.

Quote:
Original post by The Reindeer Effect
Quote:
Original post by ToohrVyk
Crash Bandicoot used LISP for scripting.
Jak & Dexter used LISP as the base language, and used GOAL (a Scheme-like language based on LISP) for scripting.


Yea, but have you seen any of the source code written in GOAL? None of the snippets I have seen (there were a few posted on a mailing list a while back) were written in a particularly functional style. The language itself was not Scheme-like in a few of those important areas in which Scheme stands apart from the other lisps (TCO and first class continuations, for example), and it had a number of low level mechanisms to subvert language safety (for example, it featured an inline assembly language). GOAL is not so much a success story for functional programming as it is a success story for LISP and it's ability to easily support several paradigms, to provide an extensible environment, and to give the programmer a suite of high-level interaction facilities (such as on-line recompilation, restartable conditions, and a very useful debugger and object inspector).


I have always wondered about this, thank you for confirming my suspicions.

Share this post


Link to post
Share on other sites
Quote:
Original post by Ravuya
I cannot believe nobody's mentioned Erlang yet.


Well spaceJockey123 did say the course/module is using haskell.

[Edited by - snk_kid on August 23, 2006 4:22:40 AM]

Share this post


Link to post
Share on other sites
I've looked at a few more chapters of Haskell and I must say that it's not as hard as I initially thought it would be. I've gotten some very useful feedback here and I'm definitely taking this module now but I'd like to ask some new questions?

1) Which sector in IT is particularly well known for using Haskell or functional programming?

2) Which of these other modules would go well with Functional Programming?:

Advanced Databases

Introduction to Data Mining

Artificial Intelligence

Theory of Computation

Decision Support Systems

IT Security

Software Agents

The above aren't going to be taught in Haskell. Most likely Java as not everybody was taught C++ or Haskell.

Thanks a bunch!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
SQL is the closest thing to a functional language that is in major use in business. Learning Haskell will make you a better programmer, because some of the concepts you learn will blow your mind and are actually useful, especially when thinking and reasoning about problems. It's barely used at all in practice though, except in academia where it's very popular due to it's super clean design.

Share this post


Link to post
Share on other sites
Quote:
Original post by snk_kid
Also you should be aware of the fact that haskell is a purely functional language where as other functional languages like SML and lisp are impure functional language. A purely functional language is one where all expressions/functions are referentially transparent meaning no assignment, no inplace update, the result of a function is always the same with the same input, in other words no side-effects.


So in a purely functional language, if I call the routine GetScore(), it should always return the same value throughout the lifespan of the game? What about GetPlayerPosition() and GetHealth()? So how can I write a game in a purely functional language?

Share this post


Link to post
Share on other sites

This topic is 4127 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this