Mental models of programs [was A few notes on choosing between Go and D for a quick project]

Russel Winder via Digitalmars-d digitalmars-d at
Thu Mar 19 01:17:28 PDT 2015

On Wed, 2015-03-18 at 13:27 +0000, CraigDillabaugh via Digitalmars-d wrote:
> There is quite possibly something too that, and as I imagine
> with more functional experience it will come easier to me.
> However, I still think imperative code is generally easier to
> reason about because (usually) each line of code is performing
> a single task, whereas with functional coding the goal seems
> to be to cram as many operations as possible into a single line
> (I know that isn't the real reason, it just seems that way at
> times).  Trying to 'unroll' everything in your head can be a
> challenge.  Throw in a lambda function or two with
> the mess of braces/symbols and then you have a real puzzler.

Each imperative statement may (or may not) be easier to understand, 
but the problem is putting them together in combination. The issue 
here is creating chunks on which you put a label for reasoning with. 
Everything is about the abstractions you reason with. A person who is 
familiar only with C-style programming (as per OPs code fragment) has 
built up various abstractions, but they are nonetheless at a very low 
level and so many have to be combined.

Someone who has learned the internal iteration abstraction and higher-
order functions is actually working at a higher level of abstraction 
and generally needs to combine fewer things to achieve the overall 
goal. Cramming operations on a line is nothing to do with the 
abstractions, that is to do with some people playing code golf.

If you find yourself reading declarative style code and having to 
unroll to imperative equivalent to understand, it just means you have 
not yet internalized the declarative abstraction yet into your mental 
model and personal programming language.

There is a lot of work on all this sort of stuff in the psychology of 
programming research literature. We can speculate all we like here 
based on personal experience and anecdotal evidence, they do 
experiments and have real data. Of course if you see any experimenting 
on first and second year undergraduates of computer science, ignore 
the results. I am talking about those who experiment with practicing 
programmers, people with real experience and expertise.

Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder at
41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel at
London SW11 1EN, UK   w:  skype: russel_winder
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: This is a digitally signed message part
URL: <>

More information about the Digitalmars-d mailing list