Outline Our project Welcome to the functional paradigm of Haskell Game programming in Haskell Alexander Berntsen Stian A. Ellingsen September 18, 2013 Alexander Berntsen, Stian A. Ellingsen Game programming in Haskell
Outline Our project Welcome to the functional paradigm of Haskell Our project Current game programming paradigms Solving those problems Welcome to the functional paradigm of Haskell Declarative programming Haskell Functional reactive programming Alexander Berntsen, Stian A. Ellingsen Game programming in Haskell
Outline Current game programming paradigms Our project Solving those problems Welcome to the functional paradigm of Haskell Object-Oriented Programming ◮ In OOP we try to represent our game world with object models ◮ Objects are usually instances of classes that interact with each other ◮ Objects have methods through which they perform said interaction f o r ( std : : vector < E n t i t i e s ∗ > :: c o n s t i t e r a t o r ent = e n t i t i e s . begin ( ) ; ent != e n t i t i e s . end ( ) ; ( ∗ ent) − > handle ( event ) , ++ent ) ; Alexander Berntsen, Stian A. Ellingsen Game programming in Haskell
Outline Current game programming paradigms Our project Solving those problems Welcome to the functional paradigm of Haskell Component-Entity Systems ◮ components (single purpose bits of state) ◮ entities (unique ids) ◮ systems (single purpose functions that take a set of entities with specific component(s) and update them) ( defn r e n d e r e r [ r e n d e r a b l e s ] ( doseq [ e r e n d e r a b l e s ] ( l e t [ rend ( as e : r e n d e r a b l e ) ] (( rend : fn ) e ) ) ) ) Alexander Berntsen, Stian A. Ellingsen Game programming in Haskell
Outline Current game programming paradigms Our project Solving those problems Welcome to the functional paradigm of Haskell Some of the problems with these paradigms ◮ no rigorous definitions ◮ used as a herding mechanism to keep mediocre programmers occupied (which may lead to mediocre programs) ◮ heavy use of state makes refactoring a nightmare ◮ lots of boilerplate code ◮ tight coupling ◮ bloated core code Alexander Berntsen, Stian A. Ellingsen Game programming in Haskell
Outline Current game programming paradigms Our project Solving those problems Welcome to the functional paradigm of Haskell We think that ◮ functional purity may eliminate these problems ◮ pure functional programming can be used efficiently for game programming Alexander Berntsen, Stian A. Ellingsen Game programming in Haskell
Outline Current game programming paradigms Our project Solving those problems Welcome to the functional paradigm of Haskell What we will try to figure out ◮ how to do a by nature heavily stateful computation (games) in a pure paradigm (Haskell) ◮ whether this results in a higher quality of source code ◮ what types of games are most compatible with PFP Alexander Berntsen, Stian A. Ellingsen Game programming in Haskell
Outline Current game programming paradigms Our project Solving those problems Welcome to the functional paradigm of Haskell By doing this ◮ analyse Haskell games’ source code (“frag”, “Nikki and the Robots”) ◮ analyse Haskell game libraries (“Hipmunk”, “SDL”) ◮ analyse other heavily state-reliant Haskell projects (“xmonad”, “AMuZed and ZooM”, “Yi”) ◮ try to apply what we learn through this Alexander Berntsen, Stian A. Ellingsen Game programming in Haskell
Outline Declarative programming Our project Haskell Welcome to the functional paradigm of Haskell Functional reactive programming The imperative way is confusing and low-level a = 2 Alexander Berntsen, Stian A. Ellingsen Game programming in Haskell
Outline Declarative programming Our project Haskell Welcome to the functional paradigm of Haskell Functional reactive programming The imperative way is confusing and low-level a = 2 a += 1 Alexander Berntsen, Stian A. Ellingsen Game programming in Haskell
Outline Declarative programming Our project Haskell Welcome to the functional paradigm of Haskell Functional reactive programming The imperative way is confusing and low-level a = 2 # wtf ? why are you changing your # mind about what ’ a ’ i s ? a += 1 Alexander Berntsen, Stian A. Ellingsen Game programming in Haskell
Outline Declarative programming Our project Haskell Welcome to the functional paradigm of Haskell Functional reactive programming The imperative way is confusing and low-level a = 2 # wtf ? why are you changing your # mind about what ’ a ’ i s ? a += 1 Alexander Berntsen, Stian A. Ellingsen Game programming in Haskell
Outline Declarative programming Our project Haskell Welcome to the functional paradigm of Haskell Functional reactive programming / ∗ P r i n t ” h e l l o ” 3 times ∗ / main () { i ; int for ( i = 0; i < 3; ++i ) p r i n t f ( ”%s ” , i != 3 ? ” h e l l o ” : ” h e l l o \ n” ) ; } Alexander Berntsen, Stian A. Ellingsen Game programming in Haskell
Outline Declarative programming Our project Haskell Welcome to the functional paradigm of Haskell Functional reactive programming / ∗ ∗ = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = ∗ Filename : l o l . c ∗ D e s c r i p t i o n : This program p r i n t s ” h e l l o h e l l o h e l l o ” ∗ Version : 1.0 ∗ Created : 17/09/13 11:59:11 ∗ R e v i s i o n : none ∗ Compiler : gcc ∗ Author : Foo Bar ( foo@bar . com ) , ∗ O r g a n i z a t i o n : Fubaz , Inc . ∗ = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = ∗ / #i n c l u d e < s t d i o . h > #i f d e f GNUC # d e f i n e UNUSED( x ) UNUSED # # x a t t r i b u t e ( ( u n u s e d )) #e l s e # d e f i n e UNUSED( x ) UNUSED # # x #e n d i f #i f d e f GNUC # d e f i n e UNUSED FUNCTION( x ) a t t r i b u t e ( ( u n u s e d ) ) UNUSED # # x #e l s e d e f i n e UNUSED FUNCTION( x ) UNUSED # # x # #e n d i f main ( i n t ∗ UNUSED( argc ) , char UNUSED( argv ) ) { i n t const i ; i n t char msg [ 6 ] = ” h e l l o ” ; ( i = 0; i < 3 ; ++i ) { f o r p r i n t f ( ”%s ” , msg ) ; } p r i n t f ( ” \ n” ) ; } Alexander Berntsen, Stian A. Ellingsen Game programming in Haskell
Outline Declarative programming Our project Haskell Welcome to the functional paradigm of Haskell Functional reactive programming So we describe what we want, instead of how to achieve it ” h e l l o ” Alexander Berntsen, Stian A. Ellingsen Game programming in Haskell
Outline Declarative programming Our project Haskell Welcome to the functional paradigm of Haskell Functional reactive programming So we describe what we want, instead of how to achieve it r e p l i c a t e 3 ” h e l l o ” Alexander Berntsen, Stian A. Ellingsen Game programming in Haskell
Outline Declarative programming Our project Haskell Welcome to the functional paradigm of Haskell Functional reactive programming So we describe what we want, instead of how to achieve it unwords $ r e p l i c a t e 3 ” h e l l o ” Alexander Berntsen, Stian A. Ellingsen Game programming in Haskell
Outline Declarative programming Our project Haskell Welcome to the functional paradigm of Haskell Functional reactive programming Which often leads to . . . ◮ looser coupling ◮ a more high-level approach ◮ parallellisation and optimisation out of the box ◮ rapid implementation, freeing up development time Alexander Berntsen, Stian A. Ellingsen Game programming in Haskell
Outline Declarative programming Our project Haskell Welcome to the functional paradigm of Haskell Functional reactive programming Which means . . . ◮ less bloated code ◮ less code, period (LOC) ◮ fewer bugs/errors ◮ faster debugging cycles ◮ source code maintainability and reusability Alexander Berntsen, Stian A. Ellingsen Game programming in Haskell
Outline Declarative programming Our project Haskell Welcome to the functional paradigm of Haskell Functional reactive programming Which makes imperative programming look like this in comparison OBTW THIS PROGRAM PRINTS HELLO HELLO HELLO TLDR HAI 1.2 CAN HAS STDIO? IM IN YR LOOP UPPIN YR VAR BOTH SAEM VAR AN 3 , O RLY? YA RLY, GTFO NO WAI, VAR, WTF? OMG 2 VISIBLE ”HELLO” GTFO OMGWTF VISIBLE ”HELLO ”! OIC OIC IM OUTTA YR LOOP KTHXBYE Alexander Berntsen, Stian A. Ellingsen Game programming in Haskell
Outline Declarative programming Our project Haskell Welcome to the functional paradigm of Haskell Functional reactive programming So there’s this thing called Haskell Alexander Berntsen, Stian A. Ellingsen Game programming in Haskell
Recommend
More recommend