About Monkey 2 › Forums › Monkey 2 Programming Help › 'Functional vs OO' :coding a GUI
This topic contains 9 replies, has 5 voices, and was last updated by 
 slenkar 1 year, 11 months ago.
- 
		AuthorPosts
 - 
		
			
				
May 8, 2017 at 11:15 am #8134
OO is nicely suited to making a gui,
for example a button,
A button would inherit the function of knowing when it is clicked from its parent, a generic gui element
then the button has its own ‘clicked’ method which handles what happens when the button is clicked.
You can also extend button , so you can have an ‘up’ button which moves the player up, extended from the ‘button’ class.
How would all of this be done in a functional language?
May 9, 2017 at 1:39 am #8142Do you mean functional with dynamic code via lambdas or do you mean functional as in calling a function?
May 9, 2017 at 5:43 am #8144I was going to ask the same question…
Functional: https://en.wikipedia.org/wiki/Functional_programming
Procedural: https://en.wikipedia.org/wiki/Procedural_programmingFunctional programming, as in lisp, clojure, etc
Procedural programming, as in old style basic, pascal, c, etc.There are different GUI implementation strategies for both styles, though IIRC it’s rather difficult to do in a purely functional manner.
May 9, 2017 at 2:35 pm #8149Functional as in Lisp etc.
It’s getting popular so I’ve always wondered how things are done that way.
May 11, 2017 at 1:37 am #8153There could be lots of projects out there that will give you an idea, for example I will mention this one:
https://github.com/ailisp/simple-guiMay 11, 2017 at 10:43 am #8164Thanks.
, it’s not very readable I wonder if it is written like when someone writes in a way that is difficult to read in C.But it’s unnecessary.
May 12, 2017 at 5:10 am #8170Functional programming is a different school of thought. For example in imperative programming languages you would consider an approach like “Firstly_DoThis”, “Secondly_DoThat” and so on, you put each statement after another where they would be executed sequentially. In functional programming languages you would consider doing something like this “GiveMeTheResult(ButFirstCalculateThis(GetSomeDataFromHere(), GetSomeDataFromSomewhereElse())).
The basic idea with this concept is that programs are considered to be consisted out of expressions (as “math expressions”) rather than sequential steps. This is why in lisp you see so many parentheses. In other functional programming languages as in F# or Scala the concept of “piping” have emerged to reduce the amount of parentheses.
May 12, 2017 at 7:41 am #8171Search for “functional reactive programming”.
But my opinion on this is that functional is not really relevant for direct I/O stuffs. For the FP lovers only. Nearly all GUI toolkits are imperative.
May 12, 2017 at 10:39 am #8175This is somehow related to the nature of the problem, for example GUIs are based completely on event driven architecture. Another case where FP doesn’t fit is resource management (memory, network, hardware) where simply the paradigm collapses. I remember once doing some OpenGL with F# for fun and the code was totally imperative.
May 12, 2017 at 5:27 pm #8176Thanks, I have used Javascript promises, which seem to be the same as the
dothis().thenthis()
example you gave
 - 
		AuthorPosts
 
You must be logged in to reply to this topic.