Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

In a paragraph...

Name: Anonymous 2011-12-27 8:14

or two, describe to me why you love functional programming and lisp/scheme/haskell so damn much /prog. You guys seem to be convinced that it's a superior way to program when conceptually it seems rather limited in comparison to imperative programming.

Name: Anonymous 2011-12-27 17:39

Here's an argument for imperative style...

Let's say I'm writing a game. Say... an RPG. In this game I have multiple characters to manage, we'll say at the moment that the main characters (mage, warrior, thief) are in a battle with three goblins and an ogre. Although a purely functional language would have no problem calculating the damage I deal to the Ogre, or the XP I receive from killing it, it would be quite confused when I told it to level up the Warrior. "What do you mean you want to permanently increment it's level by one?" it might ask. That would of course, be changing the status of something, creating side effects. Or, perhaps it found a way to achieve this in some other way. Now it comes time to update the stats (attack, defense, speed) of the Warrior. The imperative programmer takes the warrior's base stats and level, calculates the new stats, and re-updates them. The functional programmer, too scared of changing the state of the warrior, decides instead that he'll write a function for calculating the stats, but will instead call it whenever he needs the stats, instead of making it so he can make O(1) calls to Warrior.Attack whenever it is needed.

Functional programmers hate the idea of procedures, functions with side effects. They hate the idea of changing the state of things. They think everything can be done with functions, which take something in and spit the same thing out every time. Perhaps they are unaware of the idea that computers can be used for more complex applications than advanced math. Pure functions can be fine for calculating primes, or finding the arc cosine of some value... but what about changing the state of some window from full screen to minimized?

The truth is your CPU does not think functionally, it thinks imperatively. If computers were not meant to change state, they would not have had the ability to change state. But they do, and millions of applications rely on that ability.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List