Hot answers tagged

25

I think that the rationale is so you don't have to introduce arrays and array notation on day 1. Typically, arrays enter into the picture at roughly the same time as loops, which would take place a few weeks or months later, depending on the pacing of your course. That said, if you want to start with command line programs, it's not a huge problem to do so. ...


17

Because everything around C language education is just utterly awful. That's really all there is to it. scanf should not be taught, but it is. It's rarely useful, and you can discover it on your own if you need it. gets should not be taught, but it is. It's not even part of the language any more for the past eight years. I say this as one of the folks (...


14

Because, traditionally, programs iterate over data. See JSP. Admittedly, prompting the user for data is weird, however we're talking about beginners here, having them try to remember what the different fields of data they have to enter isn't the point of the exercise, and is likely to make them view interacting with computers as needlessly complicated. As a ...


12

From my own experience tutoring young CS students, user input is actually a tricky concept. If it were not for user input, the results of any program could be pre-compiled into nothing but its output. You get one lesson from getting all the input right at the beginning, with argc/argv, but from that point on, its just the computer churning. You get a ...


11

I think an important aspect to any best-practices list is the rationale behind it. It is entirely too common for a programmer to, for example, insist that gotos and global variables are evil and then proceed to use exceptions and singletons to create the exact same problems that got those features proscribed in the first place. So I suggest that when ...


11

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


11

The question is actually more complex than it might appear, and really the answer can depend on the context. For example, at what age are the students when they are first taught to program? Is this in Primary School, High School or part of an undergraduate programme? The answer might be different in each case. It also depends on the purpose of teaching the ...


10

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 ...


10

Actually, the similarities between C++ and Java are fairly shallow and the differences are very deep. The syntax of both is derived from C, but the underlying ideas are very different. The biggest difference is that an "object" in C++ is built on the stack, like a struct, not on the heap. It takes additional work and a lot of understanding to become ...


8

I introduce C macros as a convenient way of using a single source file that can be used both when debugging code in development and for final delivery, without having to edit and and edit out test/debug code. I am doing it, in particular, in the context of using the compiler development tools flex and bison, but it would be equally valid when using just C. ...


8

I would teach the use of arrays and array indices first (with pictures of a long row of physical mailboxes, or school lockers, etc.) Then later explain that all of a computer's and/or C program's (process) memory can be thought of as one big array with a pointer being a form of index (locker number) into that (virtual) memory array. You can then draw a ...


8

If you want to teach students programming concepts along with web-development (HTML/CSS/JS) you should consider lacing programming examples or lessons with examples of HTML/CSS/JS or similar concepts in both. You could also have HTML/CSS/JS as an extra credit assignment or something the class can do if they're ahead of schedule. This will keep the class ...


8

Too much, too fast "First semester". If I parse correctly, you say 60% students are new to programming. You say "The following points knock them out: they don't know how to test, they don't know how to check for memory leaks, they have no concept of encapsulating". And you say "group assignments". Taken together, it looks like this course is "introductory"...


8

This might be controversial, but I would make a point to explain that goto is not always considered harmful (and explain that the context of Dijkstra's "Go To Statement Considered Harmful" was about using available control structures). In C, there aren't very good control structures for releasing resources; in the absence of them, goto works well, and ...


8

I think you are taking a good approach with your boot camp. I'd only suggest a warm up exercise/mini-project in which students get some practice, perhaps writing in groups (pair-programming, perhaps). One useful sort of project is called a fixer-upper. There is a pedagogical pattern by that name, actually. Give the students a program that you have written. ...


7

Note: I was under the impression that this question was by a faculty asking for advice on best practices for teaching a course on C. Instead it's a question by a proactive student that is disappointed with the department's approach and wants to help educate his peers on best practices. I believe that my answer is wrongly targeted but I'm leaving it here as ...


7

Trying to learn many things at once: A language, an operating system, creating command line tools, compilation, etc. goes against cognitive load theory. That is why so many students fail. Keep it simple teach one thing at a time. You will do it in less time to can then teach the other things, with time to spare. As a tutor I have taught a student, to create ...


6

Lint I would not program in C without a lint tool e.g. gcc -Wall or pclint/flex-lint, unfortunately the latter two are proprietary. However you need to show that error/warning messages are your friend. There are not an accident. Someone spent time writing them, to help you. Read them, and fix the underlying problem. Often I have seen people finding ways to ...


6

Your list is a bit narrow in one sense. I assume it is well matched to your specific course, but probably doesn't represent "best practice" in general. For example, valgrind is limited to linux, which suits you better than me. But the idea of including memory testing, for example, is a good idea no matter the specific tool. Similarly for git. There are ...


6

I think it depends on what the goals for the course are. You are teaching an intro programming course, so what are the students expected to know when they finish? Data types and structures, loops, functions, syntax, etc? If so you don't need to teach web development skills as part of this since arguably HTML, CSS, etc. are not really "programming" in the ...


6

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 ...


6

What you have there is an excellent start, and is completely appropriate. I would go next into a puzzle to try to get them hooked. I would type the following code in front of them on your projector, and ask them to pair with a neighbor to try to figure out what will happen next. (Note, for this to work properly, you must turn off stack security in gcc, ...


6

First, it is not "well accepted" that processing sorted array is more efficient. It depends on what you do. If you spend your time inserting, for instance, then sorted arrays are not necessarily a good choice. You are better off inserting at the end (say if you have resizable arrays such as Vector<X> or ArrayList<X> in Java), and then sort ...


6

Ultimately they need to understand both ways. Which you do first seems to be a matter of preference - or maybe just following the textbook. They need to understand at some point that 'main' in C is an interface with the OS. But, since you can't teach everything at once, you have do pick the order of instruction. But teaching command line params later can ...


6

I haven't delved into the details, but if a language doesn't define its own implementation (few do) then the implementation will vary depending on the architecture for which it is compiled. It will also vary over time as research provides hints and clues about efficiency (both compile time and run time efficiency). So, one stack protocol might be appropriate ...


5

First off, if your students are truly mastering pointers on their first course, hats off to you. That's quite a lot of material to pack into a semester. Structs involve a mess of abstractions not present in anything you mentioned before in your course. What you are doing involves: user-defined types instances, dot-notation, which is syntactically ...


5

Python is a fine language for learning algorithmic thinking and problem solving (see e.g. Downey's "Think Python" (Green Tea Press, 2nd edition 2016)). Python has an enormous ecosystem, including all the range of packages for simple tasks up to heavyweight systems like SciPy for all sorts of scientific computing, NumPy for numerical computation (...


5

I started teaching Python at NCSSM in 2004. Here are some reasons I chose it. It is direct and simple, and there is not a whole ton of boilerplate to deal with at the beginning. Hello, World looks like this print("Hello, World") We all know what it looks like in Java (enclosing class needed) and C. Delimitation occurs via whitespace. ...


4

Yours is a fine first lesson, although it does not show the value of pointers. I would suggest also demonstrating how pointers can be used to implement a swap function. Ask the students (or step them through) what this code does: void swap(int x, int y) { int temp = x; x = y; y = temp; } int main() { int a = 1; int b = 2; printf("...


4

Obviously, beginners in C will have to deal with addresses and pointers really soon. First, you owe them an explanation about addresses for int aNumber; scanf ("%d", & aNumber); // an address printf("%s", aNumber); // a value which will appear in your first examples. So the "address of" operator is known from the ...


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