4
Science & Society The Language of Programming: A Cognitive Perspective Evelina Fedorenko, 1,2,3, * ,@ Anna Ivanova, 1 Riva Dhamala, 4 and Marina Umaschi Bers 4, * ,@ Computer programming is becom- ing essential across elds. Tradi- tionally grouped with science, technology, engineering, and math- ematics (STEM) disciplines, pro- gramming also bears parallels to natural languages. These parallels may translate into overlapping pro- cessing mechanisms. Investigating the cognitive basis of programming is important for understanding the human mind and could transform education practices. The Growing Importance of Computer Programming In the automated economy, computer pro- gramming is becoming an essential skill across diverse elds and disciplines. As a re- sult, countries across the world are explor- ing the inclusion of computer science (CS) as mandatory in the school curriculum. For example, the US government launched the Computer Science for Allinitiative in 2016 to introduce programming at all educational levels. Similar initiatives are taking place across Europe, Asia, and South America. The growing importance of CS education underscores the urgency in characterizing the cognitive mechanisms and the corre- sponding brain circuits that support the acquisition and use of computer program- ming skills (Box 1). This basic knowledge is needed to guide the design of curricula, assessments, and educational policies re- garding when and how to introduce CS in schools and to inform the implementation of teaching strategies and disciplinary integration. Furthermore, an understanding of the cognitive and neural basis of programming can contribute to the general enterprise of deciphering the architecture of the human mind. Computer programming is a cogni- tive invention, like arithmetic and writing. How are such emergent skills acquired? Presumably, they rely on phylogenetically older mechanisms, many of which we share with other animals, but which mech- anisms? And how do these mechanisms and new domains of knowledge interact with the evolutionarily older and ontoge- netically earlier-emerging ones? Programming as Problem Solving Traditionally, many researchers have con- strued programming in terms of problem solving, dividing it into distinct steps: prob- lem comprehension, design, coding, and debugging/maintenance [1]. As a result, when describing the cognitive underpin- nings of programming, researchers have often focused on the early stages of pro- gram planning and the ability to break down a problem into discrete units (later dubbed computational thinking[2]). Stud- ies that have probed the process of coding itself have often resorted to evaluating overall cognitive load [3]. Thus, empirical research has lagged behind in exploring the relationship between mechanisms that underlie programming and other cognitive skills, in particular language ability. Despite an abundance of metaphoric descriptions linking computer and natural languages, such as the use of the terms syntaxand semantics[4], the problem-solving ap- proach has continued to dominate the dis- course in the eld of CS education and sometimes eclipsed research exploring other cognitive mechanisms potentially in- volved (see the supplemental information online for a more detailed overview). Beyond STEM: An Alternative Construal of CS Despite the lack of rich and detailed char- acterization of the cognitive bases of com- puter programming, educators have long made assumptions about the relationship between programming and other cognitive skills. These assumptions have shaped the treatment of CS in schools across the world as mathematically/problem-solving oriented, and, when integrated in the cur- ricula, CS has been grouped with STEM disciplines [5]. However, some have argued for an alternative construal of program- ming an approach that has become known as coding as literacy[6]. The key idea is this: when you learn a programming language, you acquire a symbolic system that can be used to creatively express yourself and communicate with others. The process of teaching programming can therefore be informed by pedagogies for developing linguistic uency. The term programming languagesal- ready implies parallels to natural language. However, to rigorously evaluate the nature and extent of potential overlap in the cog- nitive and neural mechanisms that support computer versus natural language pro- cessing, it is critical to delineate the core components of each process and formulate specic hypotheses about the representations and computations that underlie them. Here, we propose a frame- work for generating such hypotheses. With respect to knowledge representa- tions, both computer and natural lan- guages rely on a set of building blocks(words and phrases in natural language, functions and variables in computer lan- guages) and a set of constraints for how these building blocks can combine to cre- ate new, complex meanings. Studies dat- ing back to the 1970s have noted this parallel, as evidenced by the occasional ref- erence to the semantics and syntax of pro- gramming languages [4], but few have investigated this distinction experimentally (see the supplemental information online). Whereas the technical meanings of these terms in linguistics and CS differ, their usage highlights that both natural and pro- gramming languages rely on meaningful and structured representations. Trends in Cognitive Sciences, July 2019, Vol. 23, No. 7 525 Trends in Cognitive Sciences

The Language of Programming: A Cognitive Perspective

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

Page 1: The Language of Programming: A Cognitive Perspective

Trends in Cognitive Sciences

Science & Society

The Language ofProgramming: ACognitive PerspectiveEvelina Fedorenko,1,2,3,*,@

Anna Ivanova,1 Riva Dhamala,4

and Marina Umaschi Bers4,*,@

Computer programming is becom-ing essential across fields. Tradi-tionally grouped with science,technology, engineering, andmath-ematics (STEM) disciplines, pro-gramming also bears parallels tonatural languages. These parallelsmay translate into overlapping pro-cessing mechanisms. Investigatingthe cognitive basis of programmingis important for understanding thehuman mind and could transformeducation practices.

The Growing Importance ofComputer ProgrammingIn the automated economy, computer pro-gramming is becoming an essential skillacross diverse fields and disciplines. As a re-sult, countries across the world are explor-ing the inclusion of computer science (CS)as mandatory in the school curriculum. Forexample, the US government launched the‘Computer Science for All’ initiative in 2016to introduce programming at all educationallevels. Similar initiatives are taking placeacross Europe, Asia, and South America.

The growing importance of CS educationunderscores the urgency in characterizingthe cognitive mechanisms and the corre-sponding brain circuits that support theacquisition and use of computer program-ming skills (Box 1). This basic knowledgeis needed to guide the design of curricula,assessments, and educational policies re-garding when and how to introduce CS inschools and to inform the implementationof teaching strategies and disciplinaryintegration.

Furthermore, an understanding of thecognitive and neural basis of programmingcan contribute to the general enterprise ofdeciphering the architecture of the humanmind. Computer programming is a cogni-tive invention, like arithmetic and writing.How are such emergent skills acquired?Presumably, they rely on phylogeneticallyolder mechanisms, many of which weshare with other animals, but which mech-anisms? And how do these mechanismsand new domains of knowledge interactwith the evolutionarily older and ontoge-netically earlier-emerging ones?

Programming as Problem SolvingTraditionally, many researchers have con-strued programming in terms of problemsolving, dividing it into distinct steps: prob-lem comprehension, design, coding, anddebugging/maintenance [1]. As a result,when describing the cognitive underpin-nings of programming, researchers haveoften focused on the early stages of pro-gram planning and the ability to breakdown a problem into discrete units (laterdubbed ‘computational thinking’ [2]). Stud-ies that have probed the process of codingitself have often resorted to evaluatingoverall cognitive load [3]. Thus, empiricalresearch has lagged behind in exploringthe relationship between mechanisms thatunderlie programming and other cognitiveskills, in particular language ability. Despitean abundance of metaphoric descriptionslinking computer and natural languages,such as the use of the terms ‘syntax’ and‘semantics’ [4], the problem-solving ap-proach has continued to dominate the dis-course in the field of CS education andsometimes eclipsed research exploringother cognitive mechanisms potentially in-volved (see the supplemental informationonline for a more detailed overview).

Beyond STEM: An AlternativeConstrual of CSDespite the lack of rich and detailed char-acterization of the cognitive bases of com-puter programming, educators have long

Tr

made assumptions about the relationshipbetween programming and other cognitiveskills. These assumptions have shaped thetreatment of CS in schools across theworld as mathematically/problem-solvingoriented, and, when integrated in the cur-ricula, CS has been grouped with STEMdisciplines [5]. However, some have arguedfor an alternative construal of program-ming – an approach that has becomeknown as ‘coding as literacy’ [6]. The keyidea is this: when you learn a programminglanguage, you acquire a symbolic systemthat can be used to creatively expressyourself and communicate with others.The process of teaching programmingcan therefore be informed by pedagogiesfor developing linguistic fluency.

The term ‘programming languages’ al-ready implies parallels to natural language.However, to rigorously evaluate the natureand extent of potential overlap in the cog-nitive and neural mechanisms that supportcomputer versus natural language pro-cessing, it is critical to delineate thecore components of each process andformulate specific hypotheses about therepresentations and computations thatunderlie them. Here, we propose a frame-work for generating such hypotheses.

With respect to knowledge representa-tions, both computer and natural lan-guages rely on a set of ‘building blocks’(words and phrases in natural language,functions and variables in computer lan-guages) and a set of constraints for howthese building blocks can combine to cre-ate new, complex meanings. Studies dat-ing back to the 1970s have noted thisparallel, as evidenced by the occasional ref-erence to the semantics and syntax of pro-gramming languages [4], but few haveinvestigated this distinction experimentally(see the supplemental information online).Whereas the technical meanings of theseterms in linguistics and CS differ, theirusage highlights that both natural and pro-gramming languages rely on meaningfuland structured representations.

ends in Cognitive Sciences, July 2019, Vol. 23, No. 7 525

Page 2: The Language of Programming: A Cognitive Perspective

Box 1. Why Now? The Urgency of Understanding the Cognitive Underpinnings of ComputerProgramming

Given the growing demand for programming skills, educators have been increasing efforts to make CS classesavailable to students. The question of whether CS should be grouped with STEM or with languages hassparked countless debates, with some citing Dijkstra who claimed that ‘mastery of one’s native tongue’ iskey to competent programming [14] and Papert’s early vision of ‘learning to program as a second language’[15] and others pointing to the decades-long tradition of viewing programming as principled problem solving.Lawmakers have alsoweighed in on the issue. In 33 US states, CS fulfills a mathematics or science requirement,with Texas and Oklahoma providing an option to count it as a foreign language (https://code.org/promote).At the federal level, legislators have proposed an initiative to award grants to schools that count CS toward eithera mathematics/science or a foreign language requirement.

There is a marked lack of scientific research that would support any of those initiatives. Although programmingmay, to some extent, recruit both STEM and language skills, no studies of programming have so far examinedthe exact division of labor between these cognitive domains. As new educational policies are introduced, un-derstanding the cognitive underpinnings of programming can help to guide those decisions.

Trends in Cognitive Sciences

With respect to computations, a multistepprocessing pipeline appears to underlieboth the comprehension and the genera-tion of linguistic/code units (Figure 1). Incomprehension, we start with perceptualinput and are trying to infer the intendedmeaning of an utterance or to decipherwhat a piece of code is trying to achieve.In doing so, we initially engage in somebasic perceptual processing (auditory/vi-sual in natural languages and typically visualin computer languages) and then attemptto recognize the building blocks and the re-lationships among them. For longer narra-tives and extended pieces of code, weneed to not only understand each utter-ance/line but also to infer an overall high-order structure of the text/program.

In generating linguistic utterances or code,we start with an idea. This idea can be asimple one and require a single sentenceor line of code or it can be highly complexand require a whole extended narrative ormultipart program. For simpler ideas orsubcomponents of complex ideas, weneed to figure out the specific buildingblocks to use and to organize them in a par-ticular way to express the target idea. Formore complex ideas, we first need to deter-mine the overall structure of the narrative orprogram. Once we have a specific plan forwhat we want to say, or what a piece ofcode would look like, we engage in actualmotor implementation by saying/writing anutterance or typing up code statements. It

526 Trends in Cognitive Sciences, July 2019, Vol. 23, No. 7

is worth noting, however, that in generatingboth linguistic texts and computer code,top-down planning may be supplementedwith more bottom-up strategies where cer-tain fragments of the text/code are pro-duced first or borrowed from previouslygenerated text/code, and then the overallstructure is built around those.

During these comprehension/generationprocesses, we also engage in other, plau-sibly similar, mental computations. For ex-ample, we can recognize errors – others’or our own – and figure out how to fixthem [1]. When processing sequences ofwords and commands, we plausibly en-gage in predictive processing: as we getmore input, we construct an increasinglyricher representation of the unfoldingidea, which in turn constrains what mightcome next. Further, during the generationof utterances or code, creative thinkingcomes into play, affecting the very natureof the ideas one is trying to express aswell as how those ideas are convertedinto sentences/code. Finally, we mayneed to consider the intent of the pro-ducer or the state of mind of our targetaudience – abilities that draw on ourmentalizing (Theory of Mind) capacities(although mentalizing about the computeritself might be maladaptive; see the sup-plemental information online).

It is also worth noting that the vast majorityof programming languages directly rely on

programmers’ knowledge of natural lan-guages (specifically, English). Keywords,variable names, function names, andapplication programming interfacesfollow naming conventions that indicatetheir function; it has been shown that‘unintuitive’ naming increases cognitiveload [7] and hinders program comprehen-sion [8]. The importance of natural lan-guage semantics is further highlighted bythe fact that non-native English speakersoften struggle to learn English-based pro-gramming languages [9]. Further, com-puter code is usually accompanied bycomments and, for larger pieces of soft-ware, documentation, which serve to scaf-fold program comprehension. Thus, theprocess of working with code necessarilyinvolves tight integration of computer andnatural language knowledge.

The machine learning community has al-ready begun to exploit structural similari-ties between code and natural languageby applying natural language processingtechniques to analyze code [10]. Develop-mental psychology researchers have alsobegun to explore those parallels. A casestudy [11] demonstrated that knowing aprogramming language can facilitate theacquisition of reading ability. Pilot studieswith preschoolers and kindergartenershave also shown that programming canfacilitate language processing, as youngchildren’s sequencing abilities significantlyimproved after they received coding inter-ventions [12]. Neuroimaging studies ofprogramming, although in their infancy, hintat potential overlap between language-and code-processing brain regions [13].Such findings, along with the theoreticalframework presented above, call for di-rect investigations of cognitive and neuraloverlap between language and codeprocessing.

Concluding RemarksThe growing importance of computer pro-gramming underscores a need to conductrigorous research probing the cognitive

Page 3: The Language of Programming: A Cognitive Perspective

TrendsTrends inin CognitiveCognitive SciencesSciences

Figure 1. HypothesizedParallels betweenNatural Language (Red) and Computer Programming (Blue) at Different Processing Stages. Both sets of cognitiveprocesses rely on the combinatorial nature of their inputs and outputs, which comprise phonemes/letters that make up words/identifiers, which combine into sentences/statements, giving rise to paragraphs and functions, and finally yield texts/utterances/programs (cf. the supplemental information online for possible differences).

Trends in Cognitive Sciences

architecture that underlies programmingabilities. We have highlighted potentialparallels between programming andnatural languages. Although the compari-son is not perfect and some mentalcomputations are likely to differ (see thesupplemental information online),future empirical studies should considerthe hypothesis that programmingdraws on some of the same resources asnatural language processing, in additionto the traditional proposal wherebyprogramming shares computations withmathematics, logic, and problem solving.

If this hypothesis finds empirical support,we need to reconceptualize the way CSis taught, especially in early childhood,when children are learning to read andwrite. CS learners might also benefit fromtechniques employed in foreign languageclassrooms, such as constant exposureto the language and learning by doing.Making progress in deciphering thecognitive and neural bases of computerprogramming may therefore yield funda-mental insights about how to optimally de-sign curricula, policy, and educationalinterventions, as well as new programming

Tr

languages for children that might draw onpictorial and not only textual interfaces [15].

Author ContributionsE.F. and M.U.B. developed the idea for the manu-

script. E.F., A.I., and M.U.B. wrote the manuscript,

with critical input from R.D. A.I. created the figure.

AcknowledgmentsThis work was supported by an NSF EAGER award

(FAIN 1744809, ‘The cognitive and neural mecha-

nisms of computer programming in young children:

storytelling or solving puzzles?’) to M.U.B. and E.F.

We also thank three anonymous reviewers for their

helpful comments and suggestions.

ends in Cognitive Sciences, July 2019, Vol. 23, No. 7 527

Page 4: The Language of Programming: A Cognitive Perspective

human diets, particularly the roots, fruits,and nuts of plants. Plant materials areused to construct a diverse array of arti-

Trends in Cognitive Sciences

Supplemental InformationSupplemental information associated with this article

can be found online at https://doi.org/10.1016/j.tics.

2019.04.010.

Forum

How Plants Shapethe Mind

facts and shelters. Plant chemicals areused to facilitate hunting and fishing, aswell as in rituals and medicines. However,despite all of these benefits, plants can in-flict serious costs. Plants have evolved animpressive set of defenses to protectagainst damage from herbivores [2]. Allplants produce toxic chemical defenses,

1Brain and Cognitive Sciences Department, MassachusettsInstitute of Technology, Cambridge, MA, USA2McGovern Insitute for Brain Research, Massachusetts Instituteof Technology, Cambridge, MA, USA3Psychiatry Department, Massachusetts General Hospital, Boston,MA, USA4Eliot-Pearson Deparmtent of Child Study and HumanDevelopment, Tufts University, Medford, MA, USA

Annie E. Wertz1,*

Plants are easy to overlook in mod-ern environments, but were a fun-damental part of human life overevolutionary time. Recent workwith infants suggests that theadaptive problems humans facedwith respect to plants have lefttheir mark on the human mind.

Plants Are A(n Adaptive) ProblemIn many societies, plants are no longer aconspicuous part of human life. Plantsare a part of the scenery outside and avail-able for purchase, already packaged andprocessed, in grocery stores and gardencenters. This limited contact with plantsmay seem perfectly normal, but acrossthe entirety of human history it is quite un-usual. Taking as a starting point the emer-gence of the genus Homo, humans spent99% of our evolutionary history ashunter–gatherers. In a hunter–gathererworld, there were no such shops wherethe necessities of life could be easily ac-quired. Instead, our ancestors had tomake a living by effectively utilizing the nat-ural environment. Plants were an essentialpart of this process.

The archeological record and studies ofmodern hunter–gatherer and hunter–horti-culturalist populations show that humansrelied on plants in a variety of ways [1].Plants are an important component of

some of which can be harmful or evenfatal to humans when ingested. Someplants also have mechanical defenses,such as thorns or stinging hairs, that cancause serious skin injury and in somecases systemic effects.

The problem is: how do humans figure outwhich plants are food (or otherwise useful)and which ones are fatal? This turns out tobe a very difficult task. There are myriadplant species and herbivores that feed onthem. The result of these complex coevo-lutionary relationships is that, from ahuman perspective, there are no morpho-logical features common to all edible ortoxic plants, even in the scale of the envi-ronments humans typically encounterwithout modern means of travel. Therefore,using general rules such as ‘Avoid plantswith white flowers’ or ‘Purple fruits are edi-ble’ simply would not work. In the formercase, one would miss out on pears, andin the latter one would end up eating deadlynightshade. Importantly, the presence ofdifficult-to-detect and potentially fatal toxinsmakes learning about plants through trialand error sampling very costly. The bestoutcome for this process involves largeamounts of wasted time and repeatedexposure to noxious plant defenses. Theworst-case scenario is death. These kindsof circumstances select for the evolutionof social learning mechanisms [3].

The recurrent adaptive problems our spe-cies encountered over evolutionary timehave shaped the human mind [4] and it iswell known that plant defenses have struc-tured the physiology and behavior of many

*Correspondence:[email protected] (E. Fedorenko) [email protected] (M.U. Bers).@1Twitter: @ev_fedorenko (E. Fedorenko) and @marinabers(M.U. Bers).

https://doi.org/10.1016/j.tics.2019.04.010

© 2019 Elsevier Ltd. All rights reserved.

References1. Dalbey, J. and Linn, M.C. (1985) The demands and re-

quirements of computer programming: a literaturereview. J. Educ. Comput. Res. 1, 253–274

2. Wing, J.M. (2006) Computational thinking. Commun. ACM49, 33–35

3. Nakagawa, T. et al. (2014) Quantifying programmers’mental workload during program comprehensionbased on cerebral blood flow measurement: a con-trolled experiment. In Companion Proceedings of the36th International Conference on Software Engineering(ICSE2014), pp. 448–451, ACM

4. Shneiderman, B. and Mayer, R.E. (1975) Towards a Cogni-tive Model of Programmer Behavior, Indiana University

5. Guzdial, M. and Morrison, B. (2016) Growing computer sci-ence education into a STEM education discipline.Commun.ACM 59, 31–33

6. Bers, M.U. (2019) Coding as another language: why com-puter science in early childhood should not be STEM. InExploring Key Issues in Early Childhood and Technol-ogy: Evolving Perspectives and Innovative Approaches(Donohue, C., ed.), Routledge

7. Fakhoury, S. et al. (2018) The effect of poor source codelexicon and readability on developers’ cognitive load. InProceedings of the International Conference on ProgramComprehension (ICPC), pp. 286–296, IEEE

8. Lawrie, D. et al. (2006) What’s in a name? A study of iden-tifiers. In Proceedings of the International Conference onProgram Comprehension (ICPC), pp. 3–12, IEEE

9. Guo, P.J. (2018) Non-Native English Speakers LearningComputer Programming: Barriers, Desires, and DesignOpportunities. In Proceedings of the 2018 CHI Confer-ence on Human Factors in Computing Systems, pp.396, ACM

10. Allamanis, M. et al. (2018) A survey of machine learning forbig code and naturalness. ACM Comput. Surv. 51, 81

11. Peppler, K.A. and Warschauer, M. (2011) Uncovering liter-acies, disrupting stereotypes: examining the (dis)abilities of achild learning to computer program and read. Int. J. Learn.Media 3, 15–41

12. Kazakoff, E.R. and Bers, M.U. (2014) Put your robot in, putyour robot out: sequencing through programming robotsin early childhood. J. Educ. Comput. Res. 50, 553–573

13. Siegmund, J. et al. (2014) Understanding source code withfunctional magnetic resonance imaging. In Companion Pro-ceedings of the 36th International Conference on SoftwareEngineering (ICSE2014), pp. 378–389, ACM

528 Trends in Cognitive Sciences, July 2019, Vol. 23, No. 7

14. Dijkstra, E.W. (1982) How do we tell truths that might hurt?In Selected Writings on Computing: A Personal Perspec-tive, pp. 129–131, Springer

15. Papert, S. (1980) Mindstorms: Children, Computers andPowerful Ideas, Basic Books