Revisiting the Use of Underscore Prefixes in Marimo. #2152
Replies: 1 comment 3 replies
-
Thanks for the thoughtful discussion post. We've indeed put a lot of thought into this. Our recommendation is to avoid using local (underscore-prefixed) variables as much as possible; they are a crutch to help you migrate Jupyter notebooks. Python does have natural scoping mechanisms — functions and classes. If you look at our example code, you should hopefully find that we use private variables very sparingly, and instead encapsulate logic in functions. Indeed, our documentation discourages the use of local variables:
Using functions has the bonus of making your code more readable, more modular, and more re-usable. There was another proposal, in #1477, to make it possible to reuse variable names in multiple cells so long as multiply defined variables are always defined before they are read. While possible for us to implement, it's somewhat complex (both for the user to understand and for us to implement) so we haven't supported this yet. |
Beta Was this translation helpful? Give feedback.
-
This is a cont'd topic of #2124 (comment).
While I understand the current design decision regarding the use of underscore prefixes to signify private variables within cells, I'd like to open a discussion about potentially reconsidering this approach. Here are some points for consideration:
Code Readability: The frequent use of underscore prefixes can make the code less readable, especially in notebooks with many cells. This might impact the overall user experience and code comprehension.
Export Aesthetics: When exporting a notebook to a script using
marimo export script notebook.py > script.py
, the underscore prefixes are retained. This can make the exported code look less elegant and potentially less pythonic.Alternative Approaches: Could we explore other ways to manage cell-specific variables without relying on underscore prefixes? For example:
Consistency with Python Conventions: While underscores are used in Python to indicate private variables, they're typically used sparingly. The current approach in Marimo might be seen as overusing this convention.
User Customization: Could we consider adding an option for users to disable or customize this feature based on their preferences or specific use cases?
I appreciate the thoughtful design decisions that have gone into Marimo, and I understand that this particular choice was made consciously. However, I believe that revisiting this aspect could potentially enhance the user experience and code clarity in Marimo notebooks.
I'm interested in hearing the community's thoughts on this matter and whether others have experienced similar concerns or have additional suggestions for addressing this design aspect.
Regards,
Zhao
Beta Was this translation helpful? Give feedback.
All reactions