Schwern is talking about how to make code easier to read. Some simple things can make your code much more comprehensible, just like addingspacesbetweenwordsmakesiteasiertoreadnaturallanguage.
Lexical encapsulation – basically, making sure that everything related to the current lines of code are visible on the same page (editor window). Lexical scope is does this for you, so subroutines (which create a new scope) are useful for more than just code reuse. They also help readability.
This is not news to me. Back in the 1980s when I taught introduction to programming at UF I instituted an iron-clad rule: no procedure or function could be more than 25 lines of code long. If any of them even had a 26th line, you lost a third of the score for the assignment. Have a 31st line? Lose two-thirds.
What a lot of complaining that led to! And what a bunch of terribly illogical code decomposition I saw. But brand new programmers needed that discipline, and by the end of the course their code was much cleaner, easier to read, and (not incidentally) much more likely to work right. The best programmer I know was a student back then, and told me it was probably the single most useful thing I ever taught.
No links in this post. Sorry, but the conference network is so bad I can’t even search and open pages to find the right links. WordPress.com handles this really well, saving my content pretty much continuously even though slowly.