bterwijn

joined 8 months ago
[–] bterwijn@programming.dev 2 points 1 month ago (1 children)

Copying a list with a million elements every time you make a small change is not fun. Sure, you can optimize a bit behind the scenes, but that still gives a lot of overhead.

[–] bterwijn@programming.dev 5 points 1 month ago* (last edited 1 month ago) (3 children)

It's definitely not the same. Similarly for a class you can define the __add__ dunder method for a + b and separately the __iadd__ dunder method for a += b. The first creates a new object, the latter changes/mutates the existing object a. For immutable types it is the same though.

 

An exercise to help build the right mental model for Python data.

The “Solution” link visualizes execution and reveals what’s actually happening using 𝗺𝗲𝗺𝗼𝗿𝘆_𝗴𝗿𝗮𝗽𝗵: https://github.com/bterwijn/memory_graph

6
submitted 4 months ago* (last edited 4 months ago) by bterwijn@programming.dev to c/python@programming.dev
 

Data structures like Trie can in Python be easier understood and debugged after visualization using the memory_graph package.

A Trie is a tree of dictionaries and can be used for things like word completion.

[–] bterwijn@programming.dev 2 points 5 months ago

Nice one, see the "Solution" link for correct answer.

[–] bterwijn@programming.dev 5 points 5 months ago

Yes I understand your point, but I'm trying to reach out so people are aware and can use it in Python education. I feel it can really help beginners understand tricky concepts with ease, bit it's hard to reach a bigger audience these days. Sorry for the repetition, I'll guess I should cut back a bit.

 

Data structures become much easier to understand when students can see the structure of their data visualized using memory_graph. A data structure is no longer an abstract idea but concrete, clear and debuggable. Here’s a live demo of a Linear Linked List: https://memory-graph.com/#codeurl=https%3A%2F%2Fraw.githubusercontent.com%2Fbterwijn%2Fmemory_graph%2Frefs%2Fheads%2Fmain%2Fsrc%2Flinked_list_lin.py&breakpoints=27&continues=1&timestep=0.2&play=

[–] bterwijn@programming.dev 1 points 5 months ago

Different languages make different choices. The disadvantage of Haskell is that if you want to change one value in a collection of a million values that it either makes a full copy or tries to optimize by sharing values behind the scene, both resulting in significant overhead. Most people already understand that pure functional programming languages don't deliver except in very specific circumstances: Haskell TIOBE rating 0.32%, https://www.tiobe.com/tiobe-index/

[–] bterwijn@programming.dev 2 points 5 months ago (1 children)

Incorrect sorry, check the "Solution" link for the correct answer.

14
submitted 5 months ago* (last edited 5 months ago) by bterwijn@programming.dev to c/python@programming.dev
 

An exercise to help build the right mental model for Python data. The “Solution” link uses memory_graph to visualize execution and reveals what’s actually happening:

 

Understanding and debugging Python data structures gets easier with memory_graph visualization. Here's a Multiway Tree example. A Multiway Tree is similar to a Binary Tree but has an arbitrary number of children making the tree less deep and more efficient.

 

An exercise to help build the right mental model for Python data. The “Solution” link uses memory_graph to visualize execution and reveals what’s actually happening:

[–] bterwijn@programming.dev 3 points 6 months ago (2 children)

__add__ is called with + and __iadd__ is called with +=, and there is a difference: https://www.reddit.com/r/PythonLearning/comments/1nw08wu/right_mental_model_for_python_data/

[–] bterwijn@programming.dev 1 points 6 months ago

Yes a you get for free to set the tone, the others are more interesting.

 

An exercise to help build the right mental model for Python data. The “Solution” link uses memory_graph to visualize execution and reveals what’s actually happening:

5
submitted 6 months ago* (last edited 6 months ago) by bterwijn@programming.dev to c/python@programming.dev
 

Teaching and learning Python bitwise operators gets much easier after showing the binary representations of integers using memory_graph: bitwise operators in Memory Graph Web Debugger

Understanding of the inverse ~ operator is helped by showing the two’s complement representation.

[–] bterwijn@programming.dev 1 points 7 months ago

The whole point is to practice Python Data Model concepts, it's not a best-way-to-code example, so feel free to hate.

[–] bterwijn@programming.dev 1 points 7 months ago

You are right, in landscape mode it's better, but still not ideal. It's a project I don't have time for now. On the other hand, did you run Python code, in an IDE where the debugger visualizes the whole program state, on your Phone before?

 

An exercise to help build the right mental model for Python data. The “Solution” link uses memory_graph to visualize execution and reveals what’s actually happening:

 

Some struggle with recursion, but as package invocation_tree visualizes the Python call tree in real time, it gets easy to understand what is going on and to debug any remaining issues.

See this one-click Quick Sort demo in the Invocation Tree Web Debugger.

 

Better understand the Python Data Model or Data Structures by memory_graph visualization with just one click:

 

See the Solution and Explanation.

view more: next ›