forked from ESCOMP/CTSM
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Small fixes to python_dev_meeting branch #4
Merged
negin513
merged 3 commits into
negin513:python_dev_meeting
from
billsacks:python_dev_meeting
Feb 10, 2022
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First, changing variable name from
plon
toplon_float
is not a big deal and I can change this easily...But I don't understand the motivation behind changing it and I want to clarify why...
For example:
is allowed in Python because it is a dynamic programming language.
Please see: https://stackoverflow.com/questions/48224911/is-it-good-practice-to-change-the-type-of-a-variable-in-python
In fact this (dynamic typing) is one of the features of Python, so why not use it?
https://www.pythontutorial.net/advanced-python/dynamic-typing-in-python/
When the type of a variable changes it is recommended to use another name only when the old variable (with old type) is being used in the code again, which is not the case here...
Now, let's look at this function closely. It is a function that is only used in the
argparser
type:So the parser return to the user has a variable called
plon
(i.e. destination variabledes=plon
) with type float. So the user does not see/interact with string form of plon at all.... This is not a function that the user calls to change the variable for them rather it is a small helper function called by the argparse (with the method recommended by Python argparse).It is advised in Python to avoid using the types in variable names because it is potentially dangerous and reduces readability.
https://docs.quantifiedcode.com/python-anti-patterns/readability/putting_type_information_in_a_variable_name.html
On the other hand, if there are two different variables with two types needed in the code by all means, it would have made sense to create
plon_str
orplon_float
or whatever names...Please check the accepted response here:
https://stackoverflow.com/questions/25489118/same-variable-name-for-different-types-in-python
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is all good discussion. I feel like for a different language I would know the answer for certain. And in FORTRAN for example it does often make sense to have the type in a variable name. Which is why my initial read is to endorse @billsacks suggested change. However dynamic scripting languages are completely different, and python has some real interesting subtleties to how it handles typing. So I think this is another thing that we should discuss as a group. I don't think this should be an issue, but we should discuss it, so I'll add it to an upcoming CTSM software meeting.