Another reason: it's not entirely clear that nested functions are valuable. More than twenty years ago, I used large-scale programming and maintenance with (VAX) Pascal. We had a lot of old code that heavily used nested functions. At first I thought it was great (compared to the K & RC that I worked with before) and started doing it myself. After some time, I decided that it was a disaster, and stopped.
The problem was that the function could have a large number of variables in the area, counting the variables of all the functions in which it was nested. (There were ten nesting levels in some old code, five were fairly common, and until I changed my mind, I myself coded some of the latter). Variables in the nesting stack can have the same name, so that "internal" functions local variables can mask variables with the same name in more "external" functions. A local variable of a function that is completely closed to it in C-like languages can be changed by calling a nested function. The set of possible combinations of this jazz was almost endless, and a nightmare to understand when you read the code.
So, I started calling this programming construct “semi-global variables” instead of “nested functions” and telling other people working on the code that the only thing worse than a global variable was a semi-global variable, and please don't create more. I would forbid it from language, if I could. Unfortunately, there was no such compiler ...
Kafka Aug 12 '13 at 21:12 2013-08-12 21:12
source share