Hot answers tagged

11

As a tool for differentiation, writing out code by hand is absolutely worthwhile. I taught this year in a classroom with whiteboard top desks, and students loved a) getting to writing on their desks (even being encouraged to) while b) learning syntax through multiple modalities. What might catch a student's eye or get instilled in her memory through ...


8

You overestimate complexity of 0-based indexing a lot. There is nothing complex in 0-based indexing. On the other side, pointers are relatively complex thing. I don't think it has any sense to introduce pointers earlier, than at the time when pupil would be ready to fully feel their usefulness and use them in practice. Especially in languages like C, where ...


8

This is a great explanation of why 0-indexing exists. As someone who barely knows what a pointer is, your explanation made perfect sense. If you wanted to dumb it down a little you could phrase it as: When you create an array, the variable you assign that array to is actually a pointer to the first element. Lets create an array num. When you want to ...


8

Going with real-world things which they should be familiar with are best, even if it is completely outside of education. As you have applied the tag for adult education, I'm going to presume it is outside of normal university/college courses. A bit of creativity and looking around can develop many an idea as long as you get outside the box. The cafeteria ...


6

I think having kids write code by hand can be incredibly worthwhile, but be careful of how you assess it. I wouldn't take points off for mistakes that would be easily caught by a compiler such as a missing semicolon or mixing up length and size. I also wouldn't take points off for mistakes students might make when writing code by hand that show they know ...


5

I think this is a structure of knowledge problem. I suspect the disconnect is that you have organized your knowledge in a way your students haven't. You understand that strings, lists, dicts, and deques are all something called containers. You also understand that all containers can be accessed with []. Therefore, it's straightforward to consider that [] ...


4

If the student is asking such questions, then we're already off to a great start. You have meta-cognitive learners! Now, I must caution you to be reasonable about your expectations. You write that "these students usually repeatedly struggle with this every time a new construct is introduced, as they fail to see how certain concepts from one part of the ...


4

Draw ongoing attention to the potentially confusing point by banning cardinal descriptions of an element's position. Avoid referring to the "first element" or "second element" and talk only about "element at index 0" or "at index 1." Insist that your students speak only of indices and not of position in a sequence. If you ever use cardinal numbers in human ...


4

Is there a better way? Consider using an authentic activity that both exercises and motivates the learning. For example, often the author of code has difficulty finding and repairing errors in the code. You can ask learners to help identify and fix errors in code, provided by you, that is "close" but not quite correct. The presence of some errors may be ...


4

Boldly Go... First, I'll just say yes, it is a good idea to introduce things (let students see them) before they have to deal with them in detail. There is actually a Pedagogical Pattern, See Before Hear, that suggests that it is a good idea to let students see things before you even lecture on them. This isn't true about just syntax. The essence of the ...


4

The literary arts are full of structured strings. The main problem there is finding ones which have sufficiently interesting structure. E.g. play ::= act+ act ::= scene+ scene ::= (stage-direction | line)+ stage-direction ::= "Enter" actor+ | "Exit" actor+ ... Gypsy Spellweaver helpfully points out that this can be elaborated to incorporate even more ...


4

Mathematical expressions or natural language are good candidates for these. e.g. from http://matt.might.net/articles/grammars-bnf-ebnf/ <expr> ::= <term> "+" <expr> | <term> <term> ::= <factor> "*" <term> | <factor> <factor> ::= "(" <expr> ")" | <const> ...


3

I would start by showing them a few natural language examples, where changing one letter in a sentence completely changes the meaning, perhaps into nonsense. Most computer languages respond similarly to almost any syntax change. Then show students program lines with correct and incorrect syntax (of typical mistakes, perhaps taken from previous sessions of ...


3

I have not seen research, but this is my practice. I teach print before, teaching how to implement print. I teach use of classes, before implementation of classes. I teach import (in python), before teaching how to make modules. I just tell them “import turtle tells python how to be a turtle.” I see it like, learning to read, before learning to write.


3

Don't imagine that this problem is rare or that it is caused because the students don't "get it." Often they get it all too well. It is common in learning a new thing to base your understanding on what you already know about other things. This is just the sort of error I made myself as a beginning programmer, basing Fortran stuff on what I already knew about ...


3

As always with javascript, show the right&wrong: Show them, using the exact piece of code from your example, but add another line: var greeting = "Hello "; var first_name = prompt("What's your first name?"); var last_name = prompt("What's your last name?"); var reply = greeting+" "+last_name+", "+first_name; console.log("reply"); console.log(reply); ...


3

I am not advocating teaching pointers to explain 0-indexing (see mine and others answers on your other question for how to do that). However if we have good reason to teach pointers, here is a tip that helped me when I was learning. I have also shared these ideas with other pupils, and they started to make progress. I find code involving pointers confusing: ...


3

The ?: operator is not syntactic sugar (OK in most languages it is, and no guarantees/checks are made). It is a different construct. if predicate then action1 else action2 is procedural predicate ? value1 : value1 or value1 if predicate else value2 is functional The first does something, the second evaluates to something. The value is that the functional ...


3

After reading the answers here I'm left thinking... What about doing classroom code review? That is, have the students take the assignment they've completed, print it out, hand it to someone else, then have the students review the code they now have in front of them. When everything thinks they're done, have them switch papers yet again, getting a third ...


3

Seems like an objective test early in the year over syntax is a really good way to run off rookies. If your kids write enough code, they'll pick up the syntax. After forgetting a semicolon for the 20th time, you start to remember. Trace enough code with = vs == and you'll figure out what's going on. It's the same way experienced coders pick up new ...


2

I think that you could achieve your intended goal more easily simply by waiting. People naturally learn from their mistakes and I think that the wrong equals or no semicolon at the end of a line will stop fairly quickly. As for written assessments, I think that it is next to useless to have a written syntax quiz to catch typographical errors and simple ...


2

While I agree with this answer that the conditional expression is more than just sugar, I think the following consideration is important in many languages: While the student can be led to always writing with a consistent and clear style that avoids tricks and obfuscations, he/she will also need to be able to read code of others who take less care. So, ...


2

Generally I feel one element should be core when it comes to this and that is readability. From my own experience when I was just starting off with programming I'd always explicitly define my scopes. That is to say every if opens with a condition, followed by an encapsulated (series of) statement(s). The point for me back then was to get rid of ambiguity ...


2

Well, my first thought is an analogy. Lots of things follow patterns, right? English is a massive, complicated, crazy language, that often disobeys its own rules. (Python is much nicer.) But it, like most languages, has certain patterns. Like tenses, for instance - I drank some milk earlier tonight, but I'll drink some water tomorrow, and I'm drinking juice ...


2

This is a surprisingly complex question. In many languages one can distinguish between commands and expressions. A command is something that changes the state of the computation. An expression is something that returns a value, but doesn't change the state. This is actually a good mental model even in languages that can confuse the two ideas in small or ...


2

tl;dr Make the mapping between the software and the hardware explicit at the start and then show the code, rather than the other way round. Draw pictures. Give them a mental overall image, not just detail. Detail with no context is hard to follow, and hard to learn. In many ways this question is like another here in that you have a complex system that must ...


2

Let me try to give a more interesting example, that can't be expressed as a set of simple regular expressions. BNF, properly speaking, is about the structure of a thing, such as a language. As such, the parts have relationships to one another. So, in computer languages "if" and "while" are tokens (word symbols, keywords), and tokens can be defined by regular ...


1

People create categories as needed to manage complexity. A language designer has defined syntactic & semantic things--including categories of things--relevant to their purposes & so can anyone--specific or fuzzy. It's unhelpful & misconceived to expect that somehow categories are out there to be uncovered or that everything must be in a category ...


1

There are two things you can do (among others). Fixer Upper: Having students finish or repair a program that you create is a useful early exercise. In particular, you can give them a program larger than they would be expected to write themselves. It needs to have excellent design/coding. But you have either removed or carefully broken a few parts before ...


Only top voted, non community-wiki answers of a minimum length are eligible