- 15 Posts
- 27 Comments
bterwijn@programming.devOPto
Python@programming.dev•Difference between 'instance', 'class', and 'static' method visually explained
11·1 month agoAnother common naming convention in C++ is using an underscore as prefix for member variables: int _memberVariable{123};
bterwijn@programming.devto
Python@programming.dev•List comprehensions vs generator expressions
3·1 month agoI like to use this example with my students: https://github.com/bterwijn/memory_graph#lazy-evaluation
bterwijn@programming.devOPto
Python@programming.dev•Python's Data Model Explained through Visualization
2·4 months agoCopying 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.devOPto
Python@programming.dev•Python's Data Model Explained through Visualization
5·4 months agoIt’s definitely not the same. Similarly for a class you can define the
__add__dunder method fora + band separately the__iadd__dunder method fora += b. The first creates a new object, the latter changes/mutates the existing objecta. For immutable types it is the same though.
Nice one, see the “Solution” link for correct answer.
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.
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/
Incorrect sorry, check the “Solution” link for the correct answer.
__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/
Yes
ayou get for free to set the tone, the others are more interesting.
bterwijn@programming.devOPto
Python@programming.dev•Right Mental Model for Python Data
1·10 months agoNice one.
bterwijn@programming.devOPto
Python@programming.dev•Right Mental Model for Python Data
1·10 months agoThe 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.devOPto
Python@programming.dev•Right Mental Model for Python Data
1·10 months agoYou 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?
bterwijn@programming.devOPto
Python@programming.dev•Right Mental Model for Python Data
11·10 months agoC is incorrect,sorry. See the “Solution” link for the correct answer.
Actually running the code? I got to the stage where only AI can help me understand anything ;-)
Thanks for your feedback, much appriciated.
I agree that an
exercise14.rstwould be nice, but to save time I’ve let the code speak for itself now together with the visualizaion. I’ll probably revisit and better document the exercises later.At the Explanation link I try to give a general explanation about Pyrhon mutability (and copy later on), I agree some readers might find it hard to relate that to a specific exercise, but I don’t want to write a specific explanation for each exercise.
Thanks for reporting, should be fixed now.
You can just write your code and then press “Get URL” to get the link: https://memory-graph.com/#code=def+fun(a+%3D+[])%3A ++++a+%2B%3D+[1] ++++return+a fun() print(fun())+%23+[1%2C+1]
DuckDuckGo problem, thanks for reporting.
Same thing in Python, double underscore prefix triggers “name mangling”. There are issues that can pop up when using it if not aware.