'Functional vs OO' :coding a GUI

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.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #8134

    slenkar
    Participant

    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?

    #8142

    papgar
    Participant

    Do you mean functional with dynamic code via lambdas or do you mean functional as in calling a function?

    #8144

    impixi
    Participant

    I was going to ask the same question…

    Functional: https://en.wikipedia.org/wiki/Functional_programming
    Procedural: https://en.wikipedia.org/wiki/Procedural_programming

    Functional 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.

    #8149

    slenkar
    Participant

    Functional as in Lisp etc.

    It’s getting popular so I’ve always wondered how things are done that way.

    #8153

    cocon
    Participant

    There 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-gui

    #8164

    slenkar
    Participant

    Thanks.

    , 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.

    #8170

    cocon
    Participant

    Functional 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.

    #8171

    abakobo
    Participant

    Search 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.

    #8175

    cocon
    Participant

    This 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. 🙂

    #8176

    slenkar
    Participant

    Thanks,  I have used Javascript promises, which seem to be the same as the

    dothis().thenthis()

    example you gave

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.