13 votes

“What do you mean it’s plagiarism? It’s from the docs!”

So, my take on this is to sit down with the student and have roughly this talk: So, I'm a little disappointed by the lab you handed in, for two reasons. The first is that it is pushing on the edges ...
  • 31.7k
8 votes

Simple Pointer Examples in C

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 (...
  • 1,897
6 votes

Simple Pointer Examples in C

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, ...
  • 31.7k
6 votes

Examples of innocent looking faulty code for shock effect

My advice to all of these problems is the same. Your students do not know how to draw out memory. This is a basic technique that most people who have been programming for a while do mentally, but that ...
6 votes

Example for For vs While Loop (in Java)

If I'm interpreting your question correctly you'd like real life examples that translate to code. Maybe something like the following. You want to drive or ride your bike to the ice-cream shop a few ...
  • 35.1k
5 votes
Accepted

Examples of innocent looking faulty code for shock effect

It sounds like the program of study has a few bugs if 4th or 5th year students cannot reason about a loop. I taught myself programming in 9th grade by writing simple programs that printed shapes on ...
4 votes

Simple Pointer Examples in C

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

Simple Pointer Examples in C

Obviously, beginners in C will have to deal with addresses and pointers really soon. First, you owe them an explanation about addresses for ...
4 votes

Simple Pointer Examples in C

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 ...
  • 1,955
4 votes

What's a good example of a static factory method returning instances of subclasses?

I don't have a good answer to this. However here are my thoughts. Named constructors A good use for static factory, is to implement named constructors: Java, C#, C++, et al do not have named ...
4 votes

Examples of innocent looking faulty code for shock effect

I recognize the feeling of despair! However, I don't think that you want what you are asking for. The most shocking bit of code that I know to show students is the code I wrote up here. Beware, it'...
  • 31.7k
4 votes

What is a real-world (production-code) example of a function having default arguments?

I recently used default arguments to write an API method for a mail sending library: The method needs a subject, a body and a "To" recipient, "Cc" and "Bcc" are optional: ...
  • 971
4 votes

What is a real-world (production-code) example of a function having default arguments?

Probably the most basic example is Python's print function, which has keyword arguments sep and ...
  • 2,279
3 votes

What is a real-world (production-code) example of a function having default arguments?

I like TuringTux's answer quite a lot. If you're looking for a simpler example for the classroom just to illustrate, you might consider printing an array with an optional delimiter. ...
  • 31.7k
3 votes

“What do you mean it’s plagiarism? It’s from the docs!”

Not sure you can blame the learner really. If the information was obtained by RingTFM then full marks. Hacking the standard library - unconventional but shows initiative. The real problem was the ...
3 votes

An example that compares a computational with a non-computational thinking approach

I think you have a misunderstanding about something, but I can't say precisely what. You seem to really be asking for two different sorts of CT, not CT vs something else. Both math and CS require some ...
  • 35.1k
2 votes
Accepted

What's a good example of a static factory method returning instances of subclasses?

My go-to for programming patterns these days are games, because it is easy to create compelling examples. It has never occurred to me before to have a factory return its own subclass, so I apologise ...
  • 31.7k
2 votes

What's a good example of a static factory method returning instances of subclasses?

I would first ask what that hierarchy buys you overall in an application and, more important, in the student understanding. In general, I find concrete subclassing to be problematic and easily abused, ...
  • 35.1k
2 votes

Coding assignments for algorithms and data structures?

I'm not aware of any singular, central repository for assignment ideas. My sources for project ideas when my own well begin to run dry are: Textbooks. Often, a problem in a problem set will trigger ...
  • 31.7k
1 vote

Help identifying a '90s CYOA-style book with BASIC code listings

There's genuinely not enough to go on here to find the book with online searches. However, you can find a listing of every book on BASIC ever published at the Library of Congress, all organized into ...
  • 31.7k
1 vote

“What do you mean it’s plagiarism? It’s from the docs!”

I think it was in some Python tutorial I read ages ago, but at the very beginning, in bold, there was a statement (paraphrasing from memory): Whatever you do, do not copy the code. Copying code stops ...
  • 156
1 vote

Examples of innocent looking faulty code for shock effect

I, too, will give a somewhat orthogonal answer to your quest. I would suggest that you find a way to incorporate unit testing into your Java based course with Unit. You can give them tests or require ...
  • 35.1k
1 vote
Accepted

Example for For vs While Loop (in Java)

Having looked through all the answers thus far the other day, I'm not entirely satisfied with any of them (I'll try to take the time later and go through to leave comments). However, for now, I'll ...
1 vote

Example for For vs While Loop (in Java)

You would know beforehand when the for loop would terminate, this is not clear in a while loop. I basically tell my students "if ...

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