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
Change variable name from 'char' to 'letter' #569
Conversation
Thanks @donnaaboise. This change would also require updating the related figure. |
I have looked around in the files that generate this lesson, and don't see how to change the figure. What am I missing? |
You are right. The figure loops_image.png is located in the fig directory but I can't find its corresponding svg file. |
Good - so at least I was looking in the right place. |
_episodes/02-loop.md
Outdated
@@ -158,8 +158,8 @@ of the loop body (e.g. `end for`); what is indented after the `for` statement be | |||
> ## What's in a name? | |||
> | |||
> | |||
> In the example above, the loop variable was given the name `letter` as a mnemonic; | |||
> We can choose any name we want for variables. We might just as easily have chosen the name | |||
> In the example above, the loop variable was given the name `letter` as a descriptive variable chosen to make the code easily understandable. However, |
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.
I suggest:
In the example above, the loop variable was given a descriptive name
letter
, making it really easy to understand the code. However, we might just as easily have chosen any other name, such aschar
,c
, or evenbanana
as long as we use the same name inside the loop:
@annefou @donnaaboise it looks like a loops_image.svg was removed here: https://github.com/swcarpentry/python-novice-inflammation/pull/393/files |
Nice! Thanks for finding this, @ldko. @donnaaboise, this is how to get this figure back to your local repo:
|
I checked out the SVG file, but really don't have any idea how to edit it. Just viewing it as a text file (after tidying it up), there is no place where I can obviously change 'char' to 'letter'. I didn't make much progress in Inkscape either. I pushed the SVG file to the repo (the untidy version - I can also push a tidy version, if that helps). Can someone let me know how to edit this file? Or maybe make the few minor changes? Thanks. |
I will take care of the figure. |
Prepared two versions (don't mind the lack of spaces in front of The first one is just an updated version of the "old" figure. In the new one I tried to improve the explanation: variable 1. Updated figure2. New versionPlease share your thoughts and ideas how to improve the figures. |
Forgot to mention: please comment on all aspects of figures: font, font size, colors, line widths, (missing) arrowheads, rounded corners of rectangles, etc. |
What we can change in the 'new version' of the figure: we can move the line from |
I'll admit that I am not fan of either of these figures, and wonder if they are even necessary. Of course, they are very nicely done, but I think they may be more confusing than helpful. For example, it might not be obvious to a beginner what the numbers mean, since no numbers are printed by the actual code, and there is no reference to an index in the code. I wonder if a second code fragment would be helpful :
This could precede the example without the indexing and might help to make the figures more clearly understood. Then the second (original) code could be presented as the "python" way of writing the loop. I also appreciate just presenting the original code. It is certainly cleaner. If the lesson emphasizes that the letters will be printed in order (this might not be obvious from the more Pythonic code), the figures might be more easily understood. |
This PR changes lines 100 -- 160. I'm OK with dropping the figure altogether as I'm not a big fan of it either but visuals usually help understand concepts. We just have to make a good visual if we're to keep it. |
Okay - then there does need to be a way to indicate that the letters are printed in order, and a figure could certainly help. I think about what can be done to tweak the current figure. For example, do we need the numbers (indices)? |
I remember they caused some confusion at at least one workshop that I taught, so no, we don't necessarily need them. We could show something like the graphics below: a horizontal strip with 6 sections and in each section we show the word 'oxygen' with a small vertical arrow pointing at one of the letters, then some clarifying text (
|
This looks great! The thing that a figure can't quite capture is the dynamic nature of the loop and the idea that the code is called several times, one iteration at at time. So I wonder if adding something like : 'first pass through loop', 'second pass through loop' and so on above each of your 6 figures would help with this. In some sense, the very first code fragment, which prints
But if they haven't seen lists, this could be confusing. |
I like your suggestion to add explanatory text. I like the |
Apologies for being late to the conversation. I have found that people transitioning from an index based language to an object oriented language often struggle with the idea of looping over objects (and not indices). I want to raise the concern that this example could enhance that confusion and is no demonstrating the loop idea of for object in list... . |
@abostroem, do you mean this example ( |
or what I proposed here |
The figure looks great! |
What if we delete the current figure (line 146 in the episode and the PNG file) in this PR and save its SVG version for the future... It looks like we again arrive at the necessity to talk about Python lists before Python |
Also, for our own reference this figure was added in 9c8b5f4 |
One big difference between index-based languages (C, Fortran) and object languages (Python, Matlab) is that in both Python and Matlab, the loop variable takes iterates through items in a list or array. Whether the code is
or the equivalent Python code, or the |
4753644
to
90848ea
Compare
The code in question does not assign the value of the string slice to a variable anymore, removing the motivation of the original request. Would it be ok to close this PR? Note: I have just opened a similar PR for a similar case at another place in the material. However, there the focus is not on slicing (but |
I propose changing the variable name used to introduce Python loops from 'char' to 'letter'. The concern is possible confusion with the use of
char
in compiled languages.