Turning Comments into Action

How I designed PPE to transform inline comments into live debug messages — with insights from teaching, systems thinking, and AST transformation.🛠️💬

When I write Python code, I often rely on inline comments to annotate the reasoning behind each line. They’re helpful for readers and future maintainers — but in the moment of debugging, they do… absolutely nothing.

Like many developers, I’ve spent countless hours sprinkling print() statements throughout functions just to understand which part of the logic is running, and where it breaks. It’s tedious, especially when you’re iterating quickly — you end up adding debug prints, removing them before commits, and repeating the cycle every time something goes wrong.

I thought: what if the comments I already wrote could do more? what if they could actually speak at runtime?

That idea became PPE – PrePrintExec, a lightweight debugging tool that prints your comments just before the line they describe executes. Think of it as making your documentation come alive — a bridge between human reasoning and machine behavior.

🧠 The Design Challenge

Of course, Python doesn’t make this easy. By the time your code reaches the AST (Abstract Syntax Tree), all comments are stripped away. So, PPE doesn’t just “convert comments to prints” — it surgically reattaches the original source lines to each AST node using line numbers, then builds an instrumented version of the function that prints the meaningful comment string right before executing the original statement.

I wrapped this all into a clean Python decorator (@ppe_debug) so that developers don’t need to pass code as strings, patch source files, or use fragile runtime hacks. It’s non-intrusive, readable, and simple to toggle on or off.

📚 A Teaching Tool, Too

Beyond debugging, I also see PPE as a powerful tool for programming education. As someone who’s been a (Head) TA for multiple systems and C/C++ courses, I’ve spent years developing interactive visualizations and teaching techniques that make code more intuitive to students. PPE brings that same philosophy to Python: showing students what each line is doing as it happens, using the instructor’s own comments. It turns passive code into an active walkthrough.

Whether it’s tracing logic in a recursive function or understanding state changes in loops, PPE can make code execution more transparent — without changing the code itself.

🚀 Try It Out

You can find the source and install instructions here: 👉 PyPI: ppe-debug

Or check out the GitHub repo if you’re curious about the internals.

Alex Jiakai XU
Alex Jiakai XU
Computer Science Student

My research interests include computer systems, programming languages, software designing, and cyberspace security.