Hot answers tagged

22

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


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


14

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


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


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


9

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


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

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

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 dont know how to test, they dont know how to check for memory leaks, they have no concept of capsulating". And you say "group assignments". Taken together, it looks like this course is "introductory" ...


7

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


6

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


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


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

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


5

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


5

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: #include <stdio.h> int main() { int a = 15; int b = 30; ...


5

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


4

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


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

I would use more visual examples that target conceptual knowledge first. I would do a TON of memory diagrams with code tracing. Then, introduce the idea of pointers as memory addresses like you do in your example. I am a big fan of Nick Parlante's pointer materials. I know they are vintage at this point, but I haven't found anything better at explaining ...


4

2 -3 hours?? That's a really tight timeline to cover: header files, compile, link and build tools stack semantics and RAII (including stack unwinding during exceptions) references and how they are not like Java references pointers and how they are not like Java references smart pointers for when you have to use the heap templates including template ...


4

I would do it unplugged. Give then a sorted stack of cards, get them to find a number. Repeat with an unsorted list. Ensure that there are gaps, not a sequence, but sorted. I got caught out with this, pupils could find a card in a sequence in $O(1)$.


3

Two important concepts that seem absent from the list, and that I often find are barely developed in even fairly advanced students are testing and debugging. I would suggest some brief introduction along the following lines: Unit test and integration test; test scaffolding; test-first strategy; exhaustive test vs. (targeted) random test vs. testing manually ...


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

It is useful to create a macro to compute the maximum operation. The advantages of a macro over a function are: performance (which we all know is important to C programmers, although they can use an inline function) polymorphism (C won't allow you to have a single or multiple functions named max for different numeric types) The implementation turns out to ...


3

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


2

Obviously, beginners in C will have to deal with addresses and pointers really soon. First, you owe them an explanation about adresses 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 start. Second, pointers ...


2

I don't actually think it is necessary to show the differences (or the similarities). Treat Java as a new thing rather than trying to connect the new thing to the old (for these students only). Instead teach Java as a stand alone complete language. My preference would be to teach it from a high level rather than a low level, stressing abstractions via ...


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