News for hackers. Stuff that matters.
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++?
Re:John Carmack on Inlined Code by ufo on Friday September 26, 2014 @05:13PM (#8374896)
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.
Re:John Carmack on Inlined Code by eru on Sunday September 28, 2014 @09:30PM (#8381369)
All comprehensions get their own scope in Python 3.
Re:John Carmack on Inlined Code by lhc- on Friday September 26, 2014 @05:27PM (#8374976)
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.