|
|
|
|
|
by pka
3371 days ago
|
|
I think the point still stands: FP is different. None of the things you listed are particularly hard in an FP context. Classes/traits and parametric polymorphism will allow you to do these things just fine (Haskell code): class RectIterable map where
iterateRect :: map -> (Point -> a) -> Rectangle -> [a]
// define map data structures
data TileMap = ...
data HexMap = ...
// make them instances of the RectIterable class
instance RectIterable TileMap where
iterateRect = ...
instance RectIterable HexMap where
iterateRect = ...
> Object oriented programming ... is good for UII don't know, but React begs to differ. A pure function (state -> UI) is basically one of the best UI programming paradigms we've come up with so far, the other probably being FRP. |
|
React is good for certain classes of UI, granted. I use another FRP-style library (not React) to render UI in my current game, and it works well -- except that it doesn't mesh well with me trying to control it from an OO game, but I've created an interface that works.
But imagine creating Adobe Photoshop, Maya, or Microsoft Word entirely in React, and tell me again that FP would be the ideal choice.
For any particular dialog that pops up? Absolutely.
For the entire app? You'd end up with a "god object" that would make the app unmaintainable. OO gives you compartmentalization that you don't get with FP.
FP is great for problems up to a certain complexity. After that it falls apart. Thing is, 98% of apps don't come close to that level of complexity, so there are lots of people who never even work on an app that won't work well with FP.
In the RectIterable example you gave, I'm afraid I don't know enough Haskell to comment on it intelligently.
Is "instance" adding an interface to TileMap/HexMap so that either can be passed in as a parameter that requires a RectIterable? Can other interfaces be added that way to TileMap/HexMap?
In my editor, can I say something like myTileMap.iterateRect after doing this, or do I need to know that iterateRect exists and remember exactly what it's called?
The last point is salient: Discoverability is a huge part of the UI of a programming language, and memorizing all of the exact function names that are appropriate for a data structure is not fun.