Re:John Carmack on Inlined Code
by legutierr on Friday September 26, 2014 @05:03PM
(#8374837)
How do you do this in Python? Or is this just an approach you can take in C/C++?
[ Parent
| on HN ]
You should be able to do domething similar to the C example in most other languages with sane, lexical, variable scoping. Unfortunately, Python doesn't really play nice with nested scopes/functions so you are a bit out of luck here.
All comprehensions get their own scope in Python 3.
You could define local functions inside your larger sequential function, and then call immediately. Not 100% the same, but in terms of reading-code-in-order, it would have the effect, and it would create the same scope restrictions as the listed code.
Re:John Carmack on Inlined Code
by delluminatus on Friday September 26, 2014 @05:17PM
(#8374920)
You can't do it in Python, but it's not limited to C/C++ either; this is usually called "block scoping" and it's present in C/C++, C#, I think Ruby, Java, etc.