got net?

Kevin Hazzard's Brain Spigot

About the author

Welcome to Kevin Hazzard's blog.
E-mail me Send mail

Recent comments

Authors

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2009

Why Learning F# Is So Difficult

[mp3:Why Learning FSharp Is So Difficult.mp3] 

My third installment in the Learning F# Series is coming out in the next day or two. While I was writing it, I had some time to reflect on why learning F# is so hard for an object-oriented programmer like me. So I decided to write some of those thoughts into the third installment. After reading it in context, though, I decided that my observations would be better stated as a separate article, outside of the tutorial altogether. If you are tracking my multi-part F# series, you don't have to read this to stay on track. But if you want to understand why F# and functional programming in general seems so hard to you, you may find this piece interesting.

Gestalt psychologists believe learning new things happens best when you already have a strong basis for the new information. That sounds obvious enough to be silly, doesn't it? Let's break it down a bit, though. The idea is that because most learning involves problem solving and because problem solving requires recognition, all learning must transitively be based first on recognizing the nature of the problems we face. In other words, the prototypes that we've developed throughout our lives become the glasses through which we see the world. More importantly, those prototypes must exist in the right combination and strength relative to the nature of the problems we face to become useful in solving them. When faced with a problem for which we have all the necessary prerequisites, an amazing thing happens which Gestalt psychologists call emergence. The rest of us call this phenomenon the proverbial a-ha moment that we've all experienced in learning new things.

Emergence has a peculiar quality that's worth understanding when you're about to study something new like the F# language. You see, emergence supposes that when the human mind discerns a thing, it happens as a single event in one discrete moment in time. Here's an example that may clarify my point. Suppose that someone handed you a picture of something you should recognize. You would never realize your recognition with this sort of pattern:

"Hmmm, what is this? I see an eye so this must be a living creature of some sort.
There's a long tube descending to the ground from the point between those eyes.
Could that be a snout? It's in the right place to be a nose but its odd looking, for sure.
And those big panels on the sides of what must be the face are absurdly large.
As strange as it may seem, they've got to be the creature's ears.
Those enormous curved white things protruding from the face couldn't be teeth, could they?
Its massive body seems to be supported by four thick pillars that must be the legs.
Oh, I see it now! That's a picture of an elephant!"

Think about it. In your adult life, if you've ever encountered the image of an elephant, you didn't reason through the recognition process in that way. You can't even admit that you followed those steps so quickly that it seemed instantaneous. No, in fact your recognition was instantaneous and no deductive process was required at all. The prototypes from your youth were already properly connected in your mind to help you recognize the image presented to you singularly and instantaneously as an elephant.

The pattern of your recognizing the elephant as a singularity is, in fact, where Gestalt psychology gets its name, by the way. The German word gestalt has the meaning "being more than the sum of a thing's parts." The elephant is certainly made up of parts but in the mind's eye, it's a single entity. In this same way, we go about our lives, instantly and singularly recognizing objects and ideas thousands of times each day. Some are visual, some are aural and some are purely cognitive. These points of recognition happen so often and so naturally in the course of an average day that we don't even realize that we're doing it. That instantaneous recognition process is emergence.

Now think for a moment about how a toddler, who may have no exposure to pachyderms would react to the presentation of a photo of an elephant. The thought pattern in the toddler's mind wouldn't be much different from the line of reasoning outlined above. Try to imagine that you're a child with cognitive prototypes for other mammals like cats, dogs, cows and humans in your mind. But no elephants yet. Now try to imagine your first encounter with an elephant. Go back to the paragraph above where I proposed a line of reasoning for the recognition process. In this case, there is no way for emergence to occur in the toddler's mind because he hasn't the prototypes necessary to finish the work. So he must follow a pattern of discovery that is slower and more deliberate than the emergence experience. And the last step of the discovery process cannot be completed for the child without some assistance.

When an adult (or another educated peer) teaches the child by confirming hints about the trunk and the tusks and the thick legs of the elephant, a new prototype will be created that will become a new singularity in the child's mind, ready for future chances at emergence. For the remainder of that child's life, the gestalt of elephant-ness, i.e. the entire elephant as a singular concept with parts bearing distinct features, will emerge instantaneously every time he encounters a new instance of an elephant.

So, what in the world does Gestalt Psychology and emergence have to do with learning F#? A lot, I think. If you've always used imperative programming languages like C++, Java, Visual Basic and C#, you might find functional programming as strange as our toddler finds his first encounter with an elephant. It may be that you don't have the prototypes necessary to learn F#, in which case, you may find yourself falling back to the discovery model that our toddler used to build his pachydermal prototype. Admittedly, the discovery mode of learning is much more arduous than learning that relies heavily on prototypes. Discovery learning often goes much slower, too.

Looking at F# code for the first time, you'll almost certainly ask, "What in the world is that thing?" And just as the toddler might use an eye in a photograph as a starting point, you may find yourself struggling to find a starting point in F# source code to discern the logic that you've been told flows from it. Finding that eye is possible, though. In the remainder of my Learning F# Series, I'm going to attempt to give you that starting point that will help you identify other parts that eventually will lead you to understanding the body of functional programming. My advice is to stick with it. Get outside of your comfort zone and do some real discovery. You'll be happy you did.


Categories: F#
Posted by kevin on Monday, August 18, 2008 6:00 AM
Permalink | Comments (9) | Post RSSRSS comment feed

Comments

Matt United States

Monday, August 18, 2008 9:22 PM

Matt

Wow, that's fantastic.  I'd never really thought about it that way.  I've been trying to become proficient in F# in my spare time over the last few months and keep having this feeling that functional programming is something so completely unlike anything I've ever done before that I actually have to rewire my brain to get in the right mode.  When I do finally get in that mode, I become very productive.  I just need to practice more -- it's like riding a bike.  The cool thing is learning F# has helped me write better C# Smile


Kevin Hazzard, MVP United States

Monday, August 18, 2008 9:38 PM

Kevin Hazzard, MVP

Rewire the brain. I love it. That's what kids do every day. And I think you're right, Matt. F# makes you rewire yourself. My Python code is better. My JavaScript is better. My C# is better. Thanks for the feedback.

steve United Kingdom

Tuesday, August 19, 2008 4:54 AM

steve

There's more to it than just wanting to learn F# (or anything else for that matter), you have to have some real (for you) task on which to apply it -- you have to do (and do something meaningful) to learn.

I find it interesting to contrast F# and Erlang, the two languages I've been learning over the past year.  Erlang is a comparatively Spartan language that very clearly sits in a space where I work, so while my code is still very definitely "LOL, n00b" level, I could get something proof-of-concept level that did real work in a first couple of days coding.  F# is proving a much steeper learning curve, possibly because it has been starved of easy practical applications by the competition (as well as being a much richer language -- I still don't grok the Language Oriented features, for example).

Despite that, doing something either or both of them does score "Raganwald points" by showing better ways to write the daily C# grind.

Kevin Hazzard, MVP United States

Tuesday, August 19, 2008 7:07 AM

Kevin Hazzard, MVP

@steve, you make an interesting distinction that I believe is quite true and notable. My supposition is that falling back to discovery mode learning helps us to build new prototypes which show up in other walks of life. As you say, learning Erlang or F# may improve the daily C# grind. And it does, on average. But the requirement for the new learning to be real and applicable is another hurdle that adults must overcome.

Children don't have that kind of obstacle to learning. They use play and fantasy as the means to create circumstance. It's unfortunate that we adults don't do that so well. Imagine what we could learn if we could let go of reality and open up our minds the way children do. But, it's not meant to be, I suppose. The problems we are solving are complex enough that they require more structure and discipline. And we haven't the luxury of time, either.

For my other readers who may not know, Reginald Braithwaite, aka Raganwald, is a leader in the software development space whom you should add to your blogroll now.

http://weblog.raganwald.com

He's one of my favorites, too, Steve. Always looking for ways to score points on that scale. Smile

Endre Canada

Wednesday, August 20, 2008 11:06 AM

Endre

Excellent article. Actually I think the explanation applies to learning anything that we can't connect with our previous experience (in this case functional against imperative programming). And yes, please explain us the elephantSmile

Ralf Westphal Germany

Wednesday, August 20, 2008 3:31 PM

Ralf Westphal

Interesting thoughts, Kevin. They remind me of picture puzzles like http://home.vrweb.de/~gandalf/mind/Vexier1_2.gif. With them even an adult can watch his reasoning process while trying to discover what´s depicted. But once you´ve discovered it it´s very hard to let go of the awareness and become an unknowing observer again.

The same with OOP and functional programming. Once "you got it" it´s natural, "it becomes you". But before that moment you´re groping around to find a hold for your current knowledge.

So I´d say the hard part for you is to pick up us readers exactly where we are: What´s our programming experience? What´s our problem background? The first question is pretty easy to answer: imperative, procedural, and object oriented programing. But what about the second? Also our programming experience is a layer on top of a world view. We developed our programming skills not in a vaccum but precicely to solve particular problems. And we found that OOP was a fitting tool.

Our success with OOP in solving the problems we´re confronted by thus kinda stands in the way of learning a functional programming language, I guess. So you should first show us where our current knowledge gives us a hard time. Then we´re motivated to learn new ways for solving the problems we understand but can only cumbersomely solve with our current tools of the trade.

Looking forward to your F# posts.

-Ralf
www.ralfw.de

logicalmind United States

Friday, August 22, 2008 4:21 PM

logicalmind

Good blog post. I too have spent some time recently learning C#. Luckily for me, I forced myself to learn LISP many years ago. So learning F# was a bit faster for me than my imperative-only brethren. If you are a visual learner and want to learn functional programming in general, there is no better place to start than with the SICP videos freely available here:
groups.csail.mit.edu/.../

These use Scheme/Lisp but they are very relevant to functional programming. Once you learn the functional concepts, all functional languages will come to you much more quickly.

logicalmind United States

Friday, August 22, 2008 4:26 PM

logicalmind

Doh! I meant "...some time recently learning F#" Sorry for the confusion.

Rapid Prototyping United States

Thursday, October 23, 2008 10:22 AM

Rapid Prototyping

Prototyping is good by F#.. its like C# too ryt?

Comments are closed