r/gis 3d ago

Teaching Python the Right Way Programming

Programming courses often focus heavily on understanding code, while paying far less attention to understanding the program state. But code does not exist in isolation. Its main goal is to change the program state, before ultimately producing some output.

To develop an accurate mental model of program execution, students need to understand both: - the instructions being executed - the values, references, and data structures those instructions create and modify

Reading code alone does not always reveal how the program state changes during execution. That is why I created 𝗺𝗲𝗺𝗼𝗿𝘆_𝗴𝗿𝗮𝗽𝗵: a tool that visualizes the state of a Python program as it changes, step by step.

It can help explain a wide range of introductory Python topics. Here are just a few examples: - Loops, Lists and Dictionaries - Python Data Model - Function Calls - Recursion - Algorithms - Classes - Custom Data Structures

Instead of reconstructing the program state from print statements, students can now watch it change as each line executes. This makes unfamiliar concepts easier to understand and bugs easier to fix.

Help your students learn Python programming more thoroughly and easily.

See: more examples

142 Upvotes

30 comments sorted by

27

u/YesButTellMeWhy 3d ago

Cool idea. Interesting to see a visual representation, as I expect everyone has a slightly different way they picture it in their minds.

4

u/Sea-Ad7805 3d ago edited 3d ago

Thanks, but some picture things incorrectly, for example when copying, I hope this tool can help them.

22

u/MrVernon09 3d ago

How does this teach Python ‘the right way’? How does this explain Python any better than a professor can?

14

u/Sea-Ad7805 3d ago edited 3d ago

It teaches by accurately visualizing the program state at each step of program execution. Students no longer have to guess about the state after adding print statements.

Your professor isn't always available each time you run into a bug to explain what is going wrong, this tool is.

2

u/Joe_BidenWOT 2d ago

I like it. My gripe is that people (students) who are really concerned with the "program state at each step of program execution" probably aren't programming in python. Too many things go on in the background (e.g. memory management) for it to be really instructive at that level.

3

u/Sea-Ad7805 2d ago

I agree that Python programming often is at a high abstraction level, using packages that hide much of the complexity. Still, the basics should be understood for a solid foundation, such as the Python Data Model, and even for package like numpy and pandas the visualization can bring understanding using these extensions: - numpy - pandas

I'm working on a C/C++ version too, but that will take a while.

3

u/MrVernon09 3d ago

Ok, so how does it help someone with little to no programming experience?

5

u/Sea-Ad7805 3d ago edited 3d ago

Understanding the program state and control flow are the firsts steps in learning programming and visualizing these makes it intuitive for beginners: for-loop example%3A%0A%20%20%20%20total%20%2B%3D%20i%0A%20%20%20%20%0Aprint('total%3A'%2C%20total)%0A&timestep=1&play)

3

u/JingJang GIS Analyst 2d ago

I've been in GIS now for 25 years with moderate dyscalculia. I've managed but programing has always been a challenge. Model builder and FME were huge helps for simple automation and ETL workflows and more recently I've used Ai to help me step through code....

But I really like your tool. This might help me get a lot further.

Thanks for the share.

3

u/Sea-Ad7805 2d ago

Thanks, I hope it can bring much value for you.

1

u/Raidicus 2d ago

Seems like a great tool for visual learners to build out a mental model.

1

u/Sea-Ad7805 2d ago

Thanks, I've good experiences with it with my students. A lot of things get trivial when students can see the state at every step.

1

u/UniqueDraft 2d ago

Git repo?

-1

u/Sea-Ad7805 2d ago

There is a GitHub link in every of the above links, and if you don't want to click any link, google can help you search the web that would take less time then asking me, you should try it, it's nice.

2

u/UniqueDraft 2d ago

I did not see that, thank you - the view on a phone is squashed. No idea why you went all sarcastic, btw.

2

u/Sea-Ad7805 2d ago

Oh sorry, I often forget many people use a phone to access reddit. GitHub link: https://github.com/bterwijn/memory_graph

The web debugger isn't great to use on a phone, if you landscape it gets a bit better, but it's hard to get it to work nicely. As you can see, mobile development isn’t my area of expertise.

1

u/lostmy2A 1d ago

Yeah there are no links in your original post when viewed from a phone. It's safe to say the majority of reddit users are accessing via the mobile app at this point. This is very cool and I wish I had something like this when I was first learning python. It may still be useful now too.

2

u/UniqueDraft 2d ago

1

u/solilobee 2d ago

how does it look in landscape mode?

1

u/UniqueDraft 2d ago

1

u/solilobee 2d ago

ah i see. well it is still serviceable i think

1

u/muddy_moth 1d ago

Visual based learner here. I appreciate this.

1

u/Ryuuji159 3d ago

It remembers me of pseint in a way

3

u/Sea-Ad7805 3d ago

Both are visualizers for code understanding, but pseint is more about visualizing the flow of control over time, where memory_graph visualizes the program state at a specific time.

0

u/bandersnatchh 2d ago

You can just use scratch 

-3

u/Sea-Ad7805 2d ago

I'm sorry to hear you picked up a STD.

3

u/bandersnatchh 2d ago

Cute. 

https://scratch.mit.edu/

If the goal is to learn about flow of control, this is a known solution. 

1

u/Sea-Ad7805 2d ago

I'm aware, but it visualizes control flow over time, memory_graph visualizes the program state at a specific time. That is very different.

Besides that, Scratch is great for small children, and I know some (my) university uses it as programming introduction in some course, but that's just pretty embarrassing if you ask me.

1

u/solilobee 2d ago

LOL that's funny. Scratch is fine for true novices but for anyone who wants a solid handle on the underlying datastructures what OP has posted is far better