Do People Prefer "Natural" code?

10/08/2019
by   Casey Casalnuovo, et al.
0

Natural code is known to be very repetitive (much more so than natural language corpora); furthermore, this repetitiveness persists, even after accounting for the simpler syntax of code. However, programming languages are very expressive, allowing a great many different ways (all clear and unambiguous) to express even very simple computations. So why is natural code repetitive? We hypothesize that the reasons for this lie in fact that code is bimodal: it is executed by machines, but also read by humans. This bimodality, we argue, leads developers to write code in certain preferred ways that would be familiar to code readers. To test this theory, we 1) model familiarity using a language model estimated over a large training corpus and 2) run an experiment applying several meaning preserving transformations to Java and Python expressions in a distinct test corpus to see if forms more familiar to readers (as predicted by the language models) are in fact the ones actually written. We find that these transformations generally produce program structures that are less common in practice, supporting the theory that the high repetitiveness in code is a matter of deliberate preference. Finally, 3) we use a human subject study to show alignment between language model score and human preference for the first time in code, providing support for using this measure to improve code.

READ FULL TEXT

page 1

page 2

page 3

page 4

research
06/06/2018

Studying the Difference Between Natural and Programming Language Corpora

Code corpora, as observed in large software systems, are now known to be...
research
12/13/2021

Language Models are not Models of Language

Natural Language Processing (NLP) has become one of the leading applicat...
research
07/14/2017

Incremental Parametric Syntax for Multi-Language Transformation

We present a new approach for building source-to-source transformations ...
research
11/24/2016

Learning Python Code Suggestion with a Sparse Pointer Network

To enhance developer productivity, all modern integrated development env...
research
05/04/2022

Low-Code Programming Models

Traditionally, computer programming has been the prerogative of professi...
research
05/26/2019

Programming with Applicative-like expressions

The fact that Applicative type class allows one to express simple parser...
research
09/11/2022

Eiger: Auditable, executable, flexible legal regulations

Despite recent advances in communication and automation, regulations are...

Please sign up or login with your details

Forgot password? Click here to reset