Structure in Coding, Essays, and Narratives

A tutor helps Alana debug code for Harvard's CS50 and draws parallels between programming structure and essay structure. Planning on paper before coding, using tools like GPT for error messages, and understanding loops and conditionals as building blocks all apply to both. The same forest-and-trees thinking works for code, essays, and stories.
Chapters
Good morning, Alana. How are you doing?
Good. How are you?
I'm well. How was school last week?
It was awesome. I had as much fun as always.
What were you reading in Socratic?
We read a couple of things. I think in the beginning of the week we read If by Rudyard Kipling, and then a little later in the week we read an article called "Don't Exclude AI-Generated Art from Copyright." That's just the title, but that was really interesting. And then we also read "Keeping Quiet" by Pablo Neruda and "Ode to the Cat," also by Pablo Neruda.
Fantastic. Did you look at the Spanish versions of the Pablo Neruda poems or just English versions?
We didn't. We just did the English versions, but I did notice that it said translated by someone. So that's a good idea.
Yeah. And do you think your Spanish is good enough to read simple poetry like that in Spanish?
I think so. I think I could understand most of it.
Yeah, I would encourage you to check out Neruda in Spanish. I think Neruda's poetry is very beautiful, but I think it's even more beautiful in Spanish. And then how about Harvard CS50? How is that?
That's going pretty good. I started working on the other projects for week 1. It's taking me a little while because I'm trying to do a lot of it on my own. Or not a lot. I'm trying to figure out the first few steps on my own. Another factor is that I accidentally lost most of my code, so I had to rewrite it.
How did you lose it? What happened? What caused you to lose it?
I think I shut down my computer without saving it. Or because I'm writing it in a different space than Visual Studio Code, just because it's easier to run and test. It actually gives you more specific errors or easier to understand errors. I'm not sure that's a thing, but I perceive it as easier to understand. That's going pretty good.
Good. And then when you say, um, it's hard to figure this out on your own, how do you, how do you figure out a hard problem on your own? What do you do? Like, um, look things up on the internet? Do you use GPT? Do you reread it? Do you just kind of try different things? How do you work on the hard problems?
Um, well, I mean, I think it depends on what the problem is, but if it's like a code problem then, and it's giving— or first, if I don't understand the error that it's giving me, I look up the error because I'm not like— I don't know the language of errors, so I need to— I need— I would need to look that up. If it's just a code problem that I could probably understand, then I just try and go through it a lot and try different, um, just try different things. I actually haven't used GPT for anything yet. I feel like I should, but I don't have an account yet.
Yeah, I think it's worth trying. I usually, I Google, but sometimes I use GPT for certain kinds of things. GPT is, I would say, better than Googling. So it's certainly worth having around. So you should set up an account. You know, just with the error messages, my sense is that once you— maybe there's so many error messages you'll never know all of them, but my bet is that most of the time it's a relatively small set. Of similar error messages. Is that accurate?
Um, there were a few that I had no idea what they meant. Um, they were just there and I didn't know how to solve them without using Google or without knowing what they were. Um, I think a few I was able to kind of figure out on my own and figure out what the statements mean.
Got it. And then aside from error messages, would you say figuring out kind of how to structure the code so it solves the problem you're trying to solve, is that relatively easy or is that challenging?
I think it's kind of challenging. It's just for— if we're talking about this one project that I'm doing, I've been trying to lay it out and not all of the things are working. So I've been trying to just restructure it. I think I'm thinking of just doing it on paper before I actually implement it.
You know, I was actually going to suggest that. Have you ever done it on paper before you do it in code?
I've done a few algorithms on paper, but I haven't actually done this one on paper.
What I like about working on paper like that is I find it easier to kind of see the overall visual structure of something, you know, and you know, you can move things around on paper and you can erase it. And yeah, for some reason I find it sometimes easier to see structure on paper than in the code itself. Does that make sense?
Yes.
Is that the kind of things, the kind of situations where you've worked on paper before you go to the code?
Yeah, I think last time I worked on paper, I wasn't necessarily writing out the code. It was just kind of— it was the structure that I wanted to put it in.
Got it.
I think I was doing— it wasn't the same project, but I just had to write down different things I needed to cover.
Yeah. Do you— are you writing essays for Karen in her humanities class?
Not the writing that we're doing right now. Usually our little snippets of opinions or ideas. That we can later make into bigger essays. Yeah, depending.
So the reason I asked about essays after writing about writing on code on papers, in a funny way, I think that there's something similar to essay structure and code structure. Does that sound bizarre, or can you see some similarities?
Um, I mean, at first it does sound a bit bizarre, but I mean, I think it could. I know essays have some sort of structure to them, and so does code.
And one way I think about an essay is there's a thesis. Have you ever heard of a thesis for an essay?
Yes.
Do you have a sense for what it is?
Not in the moment. I think we did a few last year, but the actual definition has escaped me.
No problem. Very simple way I think of it is kind of saying what you're going to say. So, I'm going to show in this essay that, you know, Neruda, whatever, or Kipling, whatever. That is, you have something you're going to say, and then often you have supporting paragraphs that in a way prove what you were going to say, and then you have a conclusion where you say what you just proved. Does that sound familiar at all?
Yes.
And I would call it a structure. So thesis, supporting paragraph, supporting paragraph, supporting paragraph, conclusion, um, is kind of a structure, very simple essay structure. Um, with code structure, can you give me a description of some code structure you've used?
Sure. For example, if I just need— I guess this is really simple, but for this project I have to go through, or I'm asking the— or it's a project called Cash. It's basically just asking the user for some amount of change. For now I'm just doing under 100 and then working out the number of each coin that you have to give them. So I think I'm going through this for each coin, starting with the largest and going down to pennies. So I'm— I was thinking of just using a for loop, or just to repeat a set of code to see if the number, whatever, that the user gave me is equal to 25 cents. And if it's equal to 25, then I'd plus 1 to my variable quarter that I have, and then end the break— end the for loop. And then that for if it's at over 25, and then, um, just again and again until we can't do anymore, or unless— yeah, until number is less than, um, 25. And then I do that for dimes, and then nickels, and then pennies. And then I'd ultimately print all that out. I'm just having some trouble, I guess, visualizing the actual code that needs to take place. So I'm working on that now.
No, that, that's very helpful. So what I'm hearing is, I like when you talk about a for loop structure. That is, you know, you've got a problem to solve and you think that the best way to solve it, or at least your hypothesis for now, is that the best way to solve this is to have these 4 different loops. Each of which kind of tests for a different coin. Is that accurate?
Yes.
Cool. So that, that's a pretty clear example for me of what the coding structure is for your cache program. And even though the essay structure of thesis, supporting, supporting, supporting, conclusion is different, they're both kind of a high-level version of the kind of big steps you take. You know, you're not getting into the, the little what's going on inside the loop or what's going on inside the supporting paragraph. You're kind of getting a high-level overall structure. Does that make sense?
Yes.
I would also say Freytag's Pyramid— bless you— is a high-level structure where there's kind of, you know, you kind of introduce it and then there's the kind of buildup and then there's the climax and then there's the end. Would you agree or does it make sense that that's also kind of structure?
Yeah, there's the structure, and I already said that, that you have to follow for free text experiment.
Yeah, so what's interesting to me is I think that as you solve, as your mind solves more complex projects, you know, going back then, I think you'll focus more on structure. And so going back to, you know, error messages, error messages are kind of very detailed. That's at the level of why didn't this function give me the right outcome, right? So those, that kind of problem, basically you just Google it or GPT it or something and figure out what the error message is. But the structure is kind of more of a big picture thing where your mind is organizing high-level ideas. Does that make sense?
Yes, it does.
So as you do other codes, it's, you know, when will I use these kind of loops? Will, when will I use these kind of if-then statements? When will I use these kind of algorithms? And then in the case of essays, you know, what is my thesis statement? It could be two parts instead of just this is what I'm going to say, support, support, support, conclusion. You might have a thesis at some point that says, suppose you were to compare Kipling and Naruto. They're very, very different. And at first, would you agree Kipling and Naruto are very different?
Yes.
So I don't know, maybe you could have a thesis statement that says For— well, let's play with this. If you were to write a poem— I'm not in a poem— an essay comparing Kipling and Neruda, how would you compare them? If you had a thesis that said Neruda's like this, Kipling's like this, can you think of any generalizations about those two poets that seems accurate? What can you say about those two respective poets?
I don't think I've read both of them enough to categorize them equally, but I mean, every— I feel like every poet has their own style. So I think I'd say that one of the points is that, I mean, their poems are obviously different, but how they structure them, again, structure, how they sort of organize them, I think is a bit different.
Fair enough. Can you make a statement about— How Kipling structures versus how Neruda structures?
I noticed that Neruda, or I mean, especially in his ode to object poems, the lines are very short and there are a lot of lines. And then in Kipling's, I mean, I don't think I can say that his structure is either short or long, but it's not the same as Naruto's.
Do you think there's a different impact the way Naruto structures his poems versus the way Kipling structures their poems? As a reader, do you feel a different impact because of the different structures?
Um, I don't necessarily, but I think there is some sort of vibe and feeling to how poets structure their poems. I think having shorter lines kind of has you focus on each line more than having longer ones. I don't think I've read enough Kipling to say that his lines or stanzas are necessarily longer than Naruto's, but, um, I've just noticed that Naruto's are typically a bit shorter.
Would you say they each have the same emotional impact, or is there something different about Kipling's emotional impact versus Naruto's emotional impact?
Well, I think it— if you're talking about emotions and emotional impact, And I think that would have to depend on the actual poem. So I think, I mean, they're both obviously very different writers. I'm not sure on that part.
Okay. No problem. And I haven't read the poems, the particular poems you're talking about. But where I was going with all of this was I could imagine an essay you might write, which might say something about, you know, Neruda's poetry or the poems we read by Neruda had impact X, emotional impact X. The poems we read by Kipling had emotional impact Y. And then, and then kind of your paragraphs, you'd have to have some paragraphs explaining why you thought Neruda, with Neruda's structure, led to certain impact. Then you'd have another set of paragraphs that, and you can think of almost these as not quite loops, but Um, you'd have— your essay would have a thesis statement about Neruda and Kipling, and then you'd have a section explaining why you thought Neruda was like this, and another section why you thought Kipling was like this, and then another section comparing the two, and then a conclusion. Does that make sense?
Yes.
And the Neruda section might have, you know, its own, uh, several thesis and several paragraphs. And so, uh, just again, like, you know, in code, You can have loops within loops, or if-then statements within if-then statements, or loops within if-then statements. You see, you have these kind of components, and you can make it as complicated as you please. Fair enough?
Yes.
Likewise with essays, you could have, you know, oh, I'm going to have a thesis about Neruda, and I'm going to have a thesis about Neruda's emotions, and then a thesis about Neruda's language or structure, you know, and then likewise with Kipling. And so you can also have all this complexity in terms of essay structure that even though the tools are different, it's not exactly like loops and if-then statements, you know, there, there are kind of all these modules. One way I might think of it is kind of, uh, structural modules either in essay writing or in code writing. Does that make sense?
Yes.
Um, and then going back to Freytag's Pyramid, when you were writing your essay, your story, I remember you had kind of mini climaxes, uh, you know, on your way, your kind of jagged way up to the big one. Is that accurate?
Yes.
So I, I think even with kind of fiction and pretext pyramid, you can kind of have modules, uh, and maybe you have one module where, uh, there's more character development, and another module where there's maybe a bigger climax, and another module where the resolution takes longer, um, Does this all make sense?
Yes.
Cool. So I don't want to belabor the point, but I think it's useful for you to be aware of the different ways in which you're thinking at a level of abstract structure. And I say abstract because, well, first, do you know what I mean by abstract structure?
Not fully.
Okay, no problem. So concrete structure is The particular for-loop structure you're using to solve this cache aspect, that's very concrete. With your most recent novel, the particular Freytag pyramid you used in that Abigail novel is concrete. It's that one. If you wrote an essay on Kipling, it would be that structure. By abstract, I mean what is similar across 10 different programs you write or 10 different novels you write or 10 different essays you write. And so again, they'll be different at the level of detail. The way in which you use loops and if-then structures will be different in every— and other function calls, other algorithms will be different in every program, but all of them use certain kind of modules rearranged in different ways. Fair enough?
Yes.
Likewise with stories, your stories will have different, you know, events, character events, different, uh, you know, you'll use Freytag Pyramid in different way, but all your stories probably will have something that's kind of like a big Freytag Pyramid with some little ones along the way. Fair enough?
Yeah.
And your essays will all have a thesis with supporting paragraphs with all sorts of complications of subtheses and sub-supporting paragraphs and mini-conclusions that you'll use similar modules but in different ways. Fair enough?
Yes.
Okay. Is all this pretty complicated?
I'd say at a certain point, I think it gets a bit confusing, but I think I see it pretty clear.
No problem. It is confusing. Um, but I, I think it's helpful as you, um, again, there— have you ever heard the expression, I can't see the forest for the trees?
Yes.
What does that mean?
I think, um, you're trying to see the hypothetical forest as the entire thing, and you're trying to see into it and I lost you.
Can you hear me? Oh, you're muted. You said hypothetical forest and I lost you. Please repeat.
Or I think— I'm not exactly sure. They're talking about this hypothetical forest that could be related to really anything. You— it was, you can't see the forest for the trees, correct?
Yeah.
Well, I think that person who's saying that is kind of— I think they mean like you can't actually stop and see the beauty of the trees in the forest and its significance in things.
Yeah, there you go. There are a number of ways to interpret it, but I think part of it is you kind of have to pull out to see the big picture of the forest. And if you're focused on looking at the individual trees, you don't always see the big picture of the forest. And so even though, of course, the forest is made up of trees, if you're focused on the trees, you don't see the forest. Or if you're focused on the forest, you may not see the trees. Does that make sense?
Yes.
Do you see how that analogy might hold to our discussion about abstract structures?
I think so.
You want to give a hypothesis about how it relates?
Well, you're trying to see— you're focused on any one thing in the forest, but really you want to see the whole picture. I think in our code example, you're focused on one thing, but you might need to take a look at the big picture. Actually focus on that.
And very much so. And I would add, Suno, if you're focused on an error code, that's kind of this one particular tree, or maybe even bark on this tree. The error code is very, very specific. But if you're organizing the structure of your code on a piece of paper, that's kind of backing up and look, what does a forest look like? Does that analogy work for you?
Yes.
Okay. So this is a lot. I'm in some ways I'm trying to help you develop the habit of thinking abstractly, of going back and forth between forest and trees. Does it make sense?
Yes.
Because I think it's really useful to be aware, oh, sometimes I have to go down to the trees, oh, sometimes I have to back up to the forest, and just be really agile about going back and forth between detail and big picture, detail and big picture. The big picture is structure. Makes sense?
Yes.
All right, in which case, uh, what are you going to do today to have a wonderful day?
We are going to a friend's birthday party at the beach. We're gonna go surf with them and have fun.
Sounds so cool. You live such a great life. Do you live a great life?
Yes.
All right, well, be safe at the beach and have a blast, okay?
All right, thank you.
Bye-bye. You're welcome.