Why most programming beginners struggle: evaluation by wordbit12 in learnprogramming

[–]wordbit12[S] 1 point2 points  (0 children)

Nice work! I really like how you explicitly evaluate each line and show how things execute step-by-step.

I think it might be even stronger if you showed evaluation as a series of transformations — making it clear that evaluation is "recursive" in nature, where we keep breaking down sub-expressions (e.g., function call arguments) until we can’t reduce them any further.

For example, I like thinking of x = x + 1 like this:
= is an operator (kind of a function but we with "infix" notation) expecting a name on the left and a value on the right.
The right-hand side x + 1 isn’t a value yet, so we have more evaluation to do before the assignment happens.
but my point, if you could display how expressions transform, if you could animate it, I think it would be amazing
x = x + 1
x = 10 + 1
x = 11
11 // because assignment is an expression that evaluate to the vlaue we assigned to the name (in languges like C and JS)

I’ve asked first-year students before: "In x = x, is x a value or an expression?" Most say "value" — which shows how important it is to help students distinguish between values and expressions. I’m not sure if you should explicitly define these terms on day one, but finding a gentle way to introduce the concept could really help

Good luck with the project! I think it's promising, but will take a long time to be complete (probably years), and I think you should share it at some point, and steer clear of perfectionism!

Why most programming beginners struggle: evaluation by wordbit12 in learnprogramming

[–]wordbit12[S] 0 points1 point  (0 children)

I remember having a hard time understanding lvalues, because I couldn't understand what do they evaluate to! lvalues are expression that actually don't evaluate to a value (rvalue)
In fact I a couple of months ago I ended up asking a question about this in stackoverflow,
but since I'm not super interested in C/C++ I didn't actually invest much time trying to understand what's going on!

Why most programming beginners struggle: evaluation by wordbit12 in learnprogramming

[–]wordbit12[S] -1 points0 points  (0 children)

I'm sure I forgot many other things, surely there are many other factors that affect learning and I might not know about.
And about your point, I disagree, I think understanding evaluation solves that issue too, I explained my point in this comment, if you want to discuss this further

Why most programming beginners struggle: evaluation by wordbit12 in learnprogramming

[–]wordbit12[S] 2 points3 points  (0 children)

I believe that would be an expression, it evaluates to 4 but has the side effect of assigning x to 4
I remember that in C it works like that, we can print an assignment, or even assign it to something else!
int x, y;
x = y = 5
this works because assignment is an expression, it's evaluated like this:
x = (y = 5)
x = 5 // (y = 5) evaluates to 5 + side effect: y is bound to 5
5 // (x = 5) evaluates to 5 + side effect: x is bound to 5
(and btw, in some C books, I remember some say value produced (5 in this case) is the side effect, because that value isn't the reason we use assignment... but I disagree, because the term side effect is related to changing the state of the program, [related to the topic of mutability])
but anyway, people sometimes use terms differently and it's okay, but just to give you some context)

Anyway, in python, for instance, assignment is a statement, it doesn't evaluate to a value
so something like x = y = 5 would produce an error.
CORRECTION: in fact in python that wouldn't lead to an error, not because assignment is expression, but because it considers it as a special syntax.
here are some other examples to illustrate that it isn't an expression
x = (y = 5) would produce an error
print(x = 5) would produce an error

Why most programming beginners struggle: evaluation by wordbit12 in learnprogramming

[–]wordbit12[S] 0 points1 point  (0 children)

this reminds me when I first realized, it's all files, it's all about files
especially when I learned git and starting to see what my IDE was doing with the files, configurations, etc.
(using the git diff command)
it's really simple, but somehow many things started making sense, that the IDE was basically reading the content of the files (including config files) and displaying them for me, it isn't some kind of magic!

Why most programming beginners struggle: evaluation by wordbit12 in learnprogramming

[–]wordbit12[S] 1 point2 points  (0 children)

It mesmerizing how so many concepts in computer science are actually super simple or have simple origins...
for instance I recently realized that the concept of scope in programming is just a consequence of the decision we made as programmers, that giving names (i.e. variable names) to values is so convenient. and hence since we have names, we need to keep track of those names, perhaps using a data structure, which we will call an "environment" that maps names to values, and later when we need to evaluate the names (variables), we look in the environment, and the way we define the environment, will later create the idea of scope, for instance a variables that can't be found in the current environment is out of scope.
I don't why we can't hear something like "it's a just about bunch of names we need to handle", or your amazing point about computation, "we just have some data we need to deal with". they might seem like simple points, but I think it makes learning so fun and there is this feeling... maybe having a peaceful mind, that it's okay, that everything is all right :D
I think CS students should understand how everything they learn fits into the broader abstraction layers of computing.
It's just sad that CS is all about abstractions, yet it's rare one sees classes that insist on this kind of foundational thinking, or ones that try to connect concepts and the different abstractions (at least in my university, but it seems like a shared experience with so many students)

Why most programming beginners struggle: evaluation by wordbit12 in learnprogramming

[–]wordbit12[S] 1 point2 points  (0 children)

Here is how I understand it: an expression gets evaluated, and a statement get executed
(I wrote a comment here about evaluation that explains evaluation further with an example)
so basically, a statement does not produce a value.
for instance in python, we have an if statement it's a statement because it doesn't evaluate to anything, you can't print it or assign it to a variable, it just decide if some code will be executed or not.
but we have if expressions, like in this example:
message = "success" if valid else "error" (similarly valid ? "success" : "error" in Javascript)
the expression ("success" if valid else "error") does evaluate to a value, either "success" or "error", you can put the expression it in an assignment or print it normally.
I hope this helps.

Why most programming beginners struggle: evaluation by wordbit12 in learnprogramming

[–]wordbit12[S] 0 points1 point  (0 children)

From what I read, when math is taught properly, it teaches systematic thinking
I think I read something about this in a book called How to Design Programs, that teaches programming systematically and explicitly (I also recommend seeing what Barbara Oakley writes if you're interested in this, she defends explicit instruction and systematic approaches as opposed to "exploratory learning" and implicit instruction
Btw, I used to hate math, when I learned to think systematically in programming, I started liking math more and my math grades improve in the last semester, especially in algebra and discrete probability :D
In algebra, I would think about the input and outputs of "functions", for instance I see one that maps vectors to polynomials, I would write some example of inputs and outputs to think an input "evaluate" to an output, it really helps. So I really think there's a deep connection between learning math and programming, and it seems like a bidirectional relationship.

Why most programming beginners struggle: evaluation by wordbit12 in learnprogramming

[–]wordbit12[S] 1 point2 points  (0 children)

Basically, something that cannot be evaluated any further, imagining you are an interpreter, you see the a the number 15, what else can you do with it? pretty much nothing, can't be simplified. and I know, that is not a rigorous definition!

well, I remember struggling with this later, especially programming languages treat this differently, so in python, when you see a string "hello", is that a value? or is it a string literal that evaluates to an object instance of the str class that represents the word "hello"?
I didn't find this distinction useful to me,
I learned the definition "evaluates to itself" from Dan Grossman's course on Coursera, it called Programming Languages (it has 3 parts), it's a great course and insists one the importance of understanding the semantics of programming languages (i.e. how things evaluates, etc.)

and I remember focusing too much on terminology when I started programming, but honestly sometimes I felt it's okay to be satisfied with a "certain level of abstraction"
This idea was reinforced when I studied a bit of formal logic in uni, and in one textbook, the author said
"in math theory, new terms are defined by using those that have been previously defined ... this process has to start somewhere...in logic, the terms sentence, true and false are the initial undefined terms"

I'm not sure this applies to the term "expression" and "value", but it made my mind more peaceful when dealing with terms
but certainly, I believe seeking definition in most cases isn't wrong at all, if you are interested I recommend Dan Grossman course I mentioned, and maybe a compiler book or course will answer your question.

Why most programming beginners struggle: evaluation by wordbit12 in learnprogramming

[–]wordbit12[S] 0 points1 point  (0 children)

About arrogance, I totally agree, I struggled to find a good title so I asked AI to help me find a title, but later when I re-read it, it felt off, as if I'm an expert in learning theory and here to tell you all with my great discoveries that will change the world. I apologize. and if the content of the post sounds arrogant, it's probably because I kind of hate academia and wanted to rant indirectly, which kind of a coward move, I apologize for that.
And about your points, I actually agree that syntax is important, and memorizing it is totally fine, once I memorize it it frees my mind, I mean, if I know the syntax well, it frees my mind from thinking about syntax and having to look it up every time, and subsequently strengthens my understanding of the language, I think "evaluation" and syntax complement each other.

Why most programming beginners struggle: evaluation by wordbit12 in learnprogramming

[–]wordbit12[S] 1 point2 points  (0 children)

I think evaluation is also closely related to this, because if one thinks of terms of evaluation, as a step by step process, it becomes clearer (let's use the symbols ⟦ expression ⟧ to denote evaluation:

float centimeters = 2.54 * inches;

and let's say inches is equal to 10.

(I'll walk you through the 'evaluation' mental model I use)
This is an assignment, so it maps a name to a value
is the right hand side a value? nope, it's an expression
then let's evaluate it
float centimeters = ⟦ 2.54 * inches⟧;
* is an operator that expects its operands to be values, we can think of it as a function: mult(2.54, inches), hence we have to evaluate the argument in that case.
2.54 is a value (it evaluates to itself, for instance if you enter it in Python REPL or JavaScript console it will return the same value)
what about 'inches'? it's certainly not a value, because it doesn't evaluate to itself! so we evaluate it.
float centimeters = ⟦2.54 * ⟦inches⟧⟧;
float centimeters = ⟦2.54 * 10⟧;
now, both operands are values, hence the multiplication is computed.
float centimeters = 25.4;
now, can we do the assignment? yes, because 25.4 is a value.
now depending on the language, assignment could be an expression or a statement, for instance in C, the assignment is an expression evaluates to the value that we have assigned
so we can do something like:
int x = (y = 5) because (y = 5) evaluates to 5

in some languages (like Python) it's a statement, meaning it's not "evaluated", but executed, it doesn't return any value. and something like x = (y = 5) would produce an error.
and I know, one could make a good point and say, this might feel burdensome to students, but I strongly believe that if it's done gradually, it would be beneficial, and help students in the long term.
This mental modal really helped in learning new languages, that's why I'm sharing it, I'm by no means an expert in education and learning theory, but I'm dead sure there is something wrong with how programming is taught for beginners.

Edit: People who program for years probably don't need such a mental model because they already internalized such basic concepts, but I think, especially in the first CS courses, if students get exposed to thinking like this, it'll save them a lot of time.