Should I teach that 1 kB = 1024 bytes or 1000 bytes? Which conversion should I teach to my undergrad students? That 1 kB is 1024 bytes (binary) as everyone learned back in the nineties or the recent industry-led "friendly" conversion that says that 1 kB is in fact 1000 bytes (decimal)?

My immediate feeling goes toward the binary conversion, but when IEC says otherwise and major OSs decide for the decimal conversion (Mac OS X ≥ 10.6 and Ubuntu ≥ 10.10 now use the SI prefixes exclusively to refer to powers of 1000) I'm not so sure anymore.

You should teach both, and you probably want to use the binary unit. When you are talking about the difference, it may be helpful to tell them about how to tell the difference when reading them:

The SI kilo- is k:
$1\ \text{kB (kilobyte)} = 10^{3}\ \text{bytes} = 1000\ \text{bytes}$

While the binary kibi- is Ki:
$1\ \text{KiB (kibibyte)} = 2^{10}\ \text{bytes} = 1024\ \text{bytes}$

I notice that you used KB in your question to refer to both sizes; perhaps you should also point out that KB could be interpreted as either of these prefixes (though Wikipedia suggests it is most often used in place of KiB). In your position, I would suggest clarifying which one you mean if you use this notation.

(While you're going over confusing units, a related difference in writing units is that lowercase b is bits, uppercase B is bytes; an eightfold difference is much more significant than 2.4%.)

In my 26 years as a professional software engineer I have never encountered KB to mean anything other than 1024.

Teach them whatever definitions you like and make sure that they know that 1024 is the only useful one.


How to help students avoid being distracted by bells and whistles I teach Windows Forms programming, and now ASP.Net (essentially the same thing, except you view it in a browser) and I am dismayed that students seem to spend an enormous amount of time straining at gnats, trying to get picky details of the appearance correct. This involves them attempting to do extra things, like adding backgrounds, and putting images in to buttons and carefully positioning and sizing everything. This eats up masses of time and energy and they constantly ask me for help with details that I know nothing about, like obscure subtleties of CSS and so on.

Is there some way to get students to focus on the point of a lesson, which is to understand programming concepts, and not just stare in fascination at the colors and shapes on the screen?

(I learned programming in a command-line environment, without Windows or web browsers, so I am at a loss as to why all of this is so interesting to the students. My attempts to add even small enhancements to appearance for my demonstrations are such a time-sink that I tend to drop them in favor of getting something to work. For example, try to change the color of a Jumbotron.)

This is a very common problem. Students tend to focus on the stuff they can see, which can be to your benefit (visual programs are more engaging than command line applications), but like you've discovered, it can also be very distracting.

I think a lot of the problem can be prevented by adding a disclaimer at the top of assignments. Something like this:

  Please note that I am not grading you based on what your program looks like. It can be tempting to obsess over the look and feel, but try to resist that urge! Graphic design is an important field, but this course focuses on [insert focus here]. If you want to explore topics like graphics and design, please do so only after you've finished the main assignment. You also might want to check out [insert graphics course here] after you finish this course.

You might also include guidelines on what's "in scope" for an assignment and what's outside the scope. Something like this:

  Although this assignment includes visual elements, please note that I'm only grading you on your core logic, not what it looks like.

  The following are in scope for this assignment:

  Changes to server-side files.
  Showing the correct components on the client side.
  Getting input from the client to the server.

  The following are not in scope:

  The look and feel of the client side.
  CSS changes.
  Layout or style changes.

  If you're interested in exploring the out-of-scope topics, make sure you do so after completing the in-scope topics.

Or maybe something as simple as this:

  Make sure the basic functionality works before working on the look and feel of your program! Remember: it's better to have an ugly program that works correctly than it is to have a beautiful program that doesn't work.

You might also explain the concept of minimum viable products. It might also be useful to mention feature creep and bike shedding.

A lot of this just comes down to communicating your expectations.

Answer because I am not registered to make a comment (and am not going to so please do not implore) Yes, we did actually teach months of fundamentals, beginning with Console mode programs, before reaching Windows Forms and then ASP.Net (Web Forms).

I agree with the recent answer that says that people want (even unconsciously) to distinguish themselves. Fair enough. But there are more programmatic changes that can be made, instead of only colors and sizes on the screen. Just getting the bare Bootstrap to render properly is actually difficult, and an achievement in itself. In the "real world" (hopefully not like the "real world" that Morpheus showed Neo) someone else will probably be doing the visual design, and programmers have their hands full just getting that to render correctly, on everything from a phone to a wall-sized screen, using only Bootstrap (or whatever).

But, having been a programming student for decades, a Teaching Assistant grading the code of novices, and a professional programmer working with colleagues, I can assert positively that everyone's code will look very different, and two programmers will write quite different solutions, even if they function and look identical.

As a simple example, you would think that Morse Code going out over radio would be the most machine-like and identical thing, but it is not. Every human being sending Morse Code with a hand key will sound recognizably different (speaking from long experience). Even different semi-automatic keys of the exact same design will sound different, and further, many electronic means of generating 'perfect' code will sound recognizably different! I have participated in contests and known from just a couple letters that I had already contacted someone that I could hear again later on, so different was the sound.

There are lots of ways to distinguish oneself, and to me as an Instructor, the style of students' code, their idioms, how clear and understandable it is... are all as obvious and unique as the nose on your face. No need for applying makeup to your screens.


How can I improve my understanding in Computer Science? I am new to Computer Sciences, working as machine learning engineer. I only know the basics of programming.

How can I improve my technical comprehension so that I will be able solve different problems in Computer domain?

Currently I have difficulty understanding technical blogs. The terms and jargon confuse me. Even after searching for those jargon in Google, I feel I don't reach anywhere.

For instance I was given a problem of image processing yesterday by the seniors in my company. I had no idea how to go about it. When I read about it words like 'parsing', structure comprehension were thrown at me. I would like to know whether it is the lack of computer background that's the problem or comprehension or something else. How am I to deal it?

Abstract definitions are a deep rabbit hole. To illustrate the point:

First attempt

Imagine a non-English speaker trying to read the dictionary. First word: Aardvark. A nocturnal badger-sized burrowing mammal of Africa, ...
Wait, what does nocturnal mean? Done, occurring, or active at night.
Wait, what does occurring mean? ...

And this is the core of the issue: you end up with an ever-growing web of definitions composed of words whose definitions you don't understand. You've already had to look up more than three words and you're still not quire sure what an aardvark (the first word) is!

Second attempt

Let's try again. You're learning English because you want to work as a chef cook in an English speaking zone. You're going to be a pasta chef, so how about you look up the translation of dishes you know how to make. Afterwards, look up the translation of the ingredients you use to make these dishes.

Why was the second attempt so much more succesful? Simply put, because you were looking up the words that belong to a concrete concept you already know and understand.

  When I read about it words like 'parsing'

When you look up what parsing is, you will get some vague and generalized definition. The dictionary isn't much help here, even when looking at the computing definition. Google tells me:

  [COMPUTING] analyse (a string or text) into logical syntactic components.

This definition won't help you if you've never done any parsing before, or you haven't even thought about doing the act of parsing (even if you didn't know that it's called parsing).

So let's approach this from the other way: You are writing an application, and the users expect to be able to upload an excel file so that the data from the file can be saved in your application('s database).
How do you do that? Well, you will have to open up the file, look at the content of the file, and then add this data to your database.

Now you know that, it will make more sense what parsing is: parsing is making sense of the content you receive.
This can take on many forms, not just the reading of excel files. For example, when you ask Siri (or Alexa, or the Google Assistant) a question, it parses your sentence in order to understand what it means. When your web browser receives HTML from the web server, it parses the HTML in order to figure out what it needs to show to the user. When you load a savegame in a videogame, the game parses the save file to know what your last saved game state was.

So how do you learn computer science concepts?

The general rule is to approach it from a practical side. First, you try to accomplish something. When you struggle accomplishing it, or you want to read up on doing it even better; you will be able to look at the documentation and will already understand its inherent goal or what it adds.

For example, I am horrible at trying to understand new frameworks by reading the documentation or even seeing it presented. I learn much quicker by trying to use this, obviously failing because I don't know how to do things, and then look up how to do [simple thing, e.g. make the text bigger] in this framework.

By using this practical approach, my search for information is a directed search (like the chef looking for the translation of a dish he knows), as opposed to an abstract search (learning random words in the hopes that you'll want to use them in the future).

I'm not saying abstract searches can't be interesting. We've all spent some times clickbrowsing through Wikipedia or TV Tropes to find interesting things. But the abstract nature of computer science makes it hard to innately understand something you didn't know about before.

The best science teachers I've had always employed a similar strategy. At the beginning of the class, they pose a seemingly simple question, but the students are unable to actually find the answer. And only when they're curious about the answer to this question, the teacher starts to explain how to find the answer.

Other resources

The above answer is written in regards to your desire to self-learn. Of course, there are better ways of learning CS through courses and lectures. These courses are specifically designed to introduce concepts to you in a way that you understand them.
When self-learning, it's hard to know where to start and to separate the simple topics from the complex ones.

This is part of your issue. E.g. "parsing" is by no means a beginner topic. But if you had already learned the basics of file manipulation, collection (and preferably some OOP), the concept of parsing would've been a lot easier to understand from the get to. This is where guided courses help to, they ensure that you learn the necessary basics before starting on the more complex topics.

As an aside

  I was given a problem of image processing yesterday by the seniors in my company

I don't mean to offend, but if you're currently struggling to grasp what parsing it, you're way out of your league of broaching the topic of image processing. There seems to be a huge disconnect between your current skill level and the tasks you're being given.

Whether you're in over your head at your current job, or your seniors are oblivious to your technical skill level, in either case I suggest being open about what you do and do not yet grasp. Trying to tackle complex subjects without the necessary basic skills is not only going to take a lot of time and effort, but it will inevitably teach you some bad habits because you will be unaware of alternative options.

while learning a programming first you should visualize the output and it will make easier you to code as well as u will be upgrade from the basis.
while doing the work don't take stress and do it.do in interesting way so that you wont get boring and you will find the solution of problem easily.


How Effective Is "Rosetta Code" as a Teaching Technique? When working to teach developers Scheme (which is functional programming) I'll often show them analogous examples in C#.  The idea is that by seeing something familiar it will make it easier for the students to understand the unfamiliar.  But I'm not sure that this may actually be causing more confusion to the students.  Any thoughts or suggestions on the wisdom (or lack thereof) of showing parallel code samples when teaching developers?

By the way, this is what I'm referring to by the phrase "Rosetta Code" in the question title. It's analogous to the idea of the Rosetta Stone presenting the same text in multiple languages.

EDIT

In case it wasn't clear from original question I was thinking of both the aspects of compare and contrast between languages (i. e. this is how we code a loop in C#, this is how we code it in Scheme) and the aspect of relating the unfamiliar (Scheme) by comparing it with the familiar (C#).

Here I think the teacher's instinct and experience is the best judgement. You know your own students best. Your worry, of course, is well founded, especially since the two languages are so different.

Learning to think functionally is a big deal and a mind expander. In some ways doing it cold-turkey (with no support) is good to do, since the students need to just thrash about until the see the A-Ha. But that can be very frustrating. It isn't good to leave your students frustrated, of course.

Another reason for not using the technique you suggest is that you don't want their functional code to be just misspelled C#, using ideas from imperative and/or object-oriented thought patterns. Code in one language based on knowledge of another can be truly ugly and the programmer can miss the elegance of the new language.

And functional program can be truly elegant and mind expanding.

To balance the trade-off you can, of course, use "Rosetta Coding" only sparingly. And only when it seems really needed. Perhaps you could start out without it at all and use it only in situations in which the students are struggling, rather than as a main-line technique. You could also use it only when working with individuals (office hours) rather than with the larger group if a student needs to be reminded of the basic structure of an algorithm. Personally, I wouldn't use it as the main structure of the course and am happy to let my students thrash a bit in mildly turbulent waters. But that needs limits also, of course.

Salt is fine, but don't over-salt. Judgment and a bit of restraint, perhaps.

Since the two languages are from different paradigms the difference in resulting code can be quite stark. For example, reversing a list in linear time in Scheme is quite a lot different than you would likely program it in C# with mutable data. But even Java and Ruby, closely aligned, are not the same language and have different thought  patterns. It is the thought patterns that are the most important lessons of the various paradigms.

philipxy's comment is correct.  There is one true language: mathematics.  Just explain what you are doing to your students, without using any computer language.  If it's confusing them in one language, why double the confusion, rather than eliminate it altogether?

Except for maybe a small example here or there, the answer is No, you should not be venturing into procedural programming (I assume that's what you mean when you say C#) when teaching a functional programming class.

There are only two programming paradigms: functional and procedural.  (And no, OO is not one of them.)

The purpose of teaching functional programming is to teach students to think in terms of building a circuit, that is, a black box function of other black box functions, without state (otherwise known as global variables), and also to teach complex recursion (again without state).

The idea of eliminating state is to teach students that a computer program is nothing more than just one big function, and that's it.


Breaking down the operations when auto-casting gets complex So, take a Java statement like this one, given some int n:

if ((n+"").length() == (((n+1)+"").length())) {

Or perhaps this one, given some double, temperature, and some method that returns a boolean, unHatched():

while (temperature < 100 && unHatched())

In both of these cases, multiple auto-casts are made during the evaluation of the statement, and in both cases, the final determination is a boolean that is passed into some sort of control structure.

In my work with gifted students, the most that I have ever had to do to help someone understand statements like these is to do a simple trace.  We write the statement down, mark each item by its type, and then cross off areas of the statement (and write down the new types) as we walk through the evaluation.  This method has worked pretty consistently with my students at my day-job.

However, lately I have begun tutoring an adult student who is having a great deal of trouble, and I have been struggling to break apart statements like the above examples in ways that he can parse and keep straight.

He is at the right point, curricularly-speaking, to be examining them, but I am really struggling to help him trace and understand such statements.  (Ironically enough, because he can guess and modify a statement repeatedly, he can actually write statements like these with a fair amount of success, though when he is finished, he no longer fully understands them.)

For various reasons, learning a small concept usually takes him 3-5 weeks.  This timescale is fine, it is simply the speed at which he operates.  However, this adds a constraint for me: approaches that I take to the material must lend themselves to a fair amount of repetition with only very minor variations, or they won't be effective.

I am really having trouble finding a good approach here.  How can I give him the tools to break down statements with complex data type transformations?

I suspect that you handle such situations by informally building the parse tree of the expression in your mind. Maybe not all at once, but a bit at a time, perhaps. I'm not a cognition expert, of course, but it might help him if you teach him to do it explicitly on paper. He needs a table of operator precedence, of course and needs to be able to deal with parentheses, but otherwise it is just a mechanical process. Put the lowest precedence operator at the root of a tree and then work on the operands. The interior nodes are operators and the leaves are operands.

Can't promise it will work, but it would be my next step. With time, he may learn to rely less on the paper. Or, he might learn how to build a tool to do it automatically. That might be nice to have.

Package this in a static method like so.  You are only really interested in whether the successor of a number has more digits than the number. This is clean and it avoids interface clutter.   It also keeps the intermediate variables local; unless you have a need, you do not want to expose them in your interface.  Note it is static since it is state-invariant.

/**
*   This static method tells if an integer's successor has
*   more digits than the integer.
*   @param n the integer you are checking
*   @return true if the integer n's successor has more
*   digits than n.
*/
public static boolean successorLonger(n)
{
    String nString = "" + n;
    String succString = "" + (n + 1);
    return nString.length() != succString.length();
}


Data and Database modelling books I need a suggestion for books for my University. I have a subject called "Data and database modeling" but we lack of books. Our professor gave as barely understandable scripts. This is an official explanation of the subject:Curriculum:
Introduction of data structures used in database modeling. The data structures include data objects, associations between objects and rules for performing operations over objects.
Modelling of databases regarding user demands.
Basic database concepts.
Configurations and commands for certain real databases.
SQL commands for working with databases.
Course goals/Competences:
Data Modeling and design of data structures suitable for optimum operation of databases.
Using the basic set of SQL commands for working with databases.
Any suggestions are welcome :D

I highly recommend Database: Principles, Programming, and Performance, by O'Neill and O'Neill. Learned from that book for my first database course and loved it.

A simple search at Amazon for "database modeling" will turn up several books. Any of their top choices would be suitable.


What should be included in a best practices C course? At our University, we have in the first semester a very difficult C Introductory Course, that consists of presenting a shortened version of the language specification: What are for/while loops, if clause, what is a pointer and so on.

But they never show how good C code in a more complicated application should look. What version control is, what Valgrind is (a gnu tool for detecting memory leaks) and so on.
For the many new (about 60%) to programming or C, the group projects are quite a knockout (about 40%).

Some motivated students and I decided to offer a "best practices" session before the first assignment is handed out and after the lecture has finished.
For the students to have a better chance of finishing this course successfully.

Our selected Chapters are these:

how to compile (clang and gcc and their flags and warnings)
valgrind
make
coding style

best practices -> how to allocate memory, typedefs, file operations
basic program flow, some simple patterns

git
pitfalls specific to this course and C in general
how to ask the right question (and in turn how to google their problems)
how to use the  manpage

Are there points missing? Is there something that we shouldn't do?
In short, how to improve the content. We are planning on 3 Sessions with around 3 hours each.

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 introducing a rule of thumb, you don't just give examples of code that follows the rule, but rather examples of the sort of awful code that led to the rule being created.  Let them understand why the rule exists both so they can avoid making similar mistakes and also recognize when the rule isn't applicable. (Of course, no examples will be as helpful as allowing them to write terrible code and then try to modify it, but you have limited time.)

A related recommendation that is somewhat tangential to the best practices lecture, but related to the question of how to help them complete the course successfully:
Don't assume that the more abstract explanations of topics are necessarily easier to understand than the ones that get into the gritty details.

I've had a number of students who were completely confused when we tried to explain pointers using diagrams of boxes and arrows, but as soon as I sketched out a table of memory (with addresses as indices), explained that a pointer is just an integer that is used to "index memory", and then walked through a block of code, updating the table as I went, they understood it almost immediately.  (We put the abstractions back in place when it was time to work with higher level data structures, after they understood the fundamentals.)

It's important to teach that the name C refers to two diverging languages--a low-level language which is useful for systems programming because many operations which different platforms may handle differently are handled in a documented fashion characteristic of the actual execution environment, and a more recent high-level-only language which uses the same syntax as the low-level language, but which allows compilers to behave in arbitrary fashion if code attempts certain operations whose behaviors would be defined in the former language.

Given a piece of code like:

unsigned mul_mod_65536(unsigned short x, unsigned short y)
{
  return (x*y) & 0xFFFF;
}

compilers for the former language would multiply the values of x and y
using whatever semantics the platform uses for integer multiplication,
take the bottom 16 bits of that result, and return them.  On platforms where integer overflow would yield a result whose bottom 16 bits is correct, the above would yield the correct mod-65536 sum for all combinations of x and y.  The published rationale for C89 indicates that the authors of the Standard would have expected such behavior from most current (and IMHO presumably future) compilers.

On compiler processing the latter language, however, the above code may sometimes malfunction in totally nonsensical ways if the value of x*y would exceed 2147483647.  If, for example, code were to call mul_mod_65536(i,65535) some "modern" compilers would use the multiplication to infer that i cannot be greater than 32768, and thus "optimize out" code elsewhere in the program that would only be relevant if it were.  Thus, unlike some languages which specify that an overflow will wrap cleanly (like Java), or specify that it will trap (like C#, within checked contexts), "modern C" requires that programmers absolutely positively prevent overflows from occurring under any circumstances even in cases where one of the above behaviors would suffice (or even in circumstances where either would be equally useful).

Programmers need to be aware that there exists a lot of code which is written for the former kind of C, and also that some compilers like gcc and clang will be incompatible with such code unless explicitly forbidden from applying aggressive "optimizations".


How can I automate the grading of programming assignments? As a TA, the usual workflow for grading programming assignments for an introductory course would be:

Some instructors used email as a submission mechanism (yes, really.)
So, search for submissions in email and download every submission
Organize it to make grading easier later on
Go into each directory, compile it. Realize it doesn't work.
If I email the student, I get a response 'Works on my computer'
Debug it and make it compile on my computer
Due to lack of test cases, every student has demonstrated their work with their own version of output on the console
Decipher their output and hopefully they get a good grade
Partial grading is hard because I have to dig through the code and see what parts are done and how far away they are from a working solution

All in all, it takes about 7-10 minutes per submission if I do things carefully. 100 students, 3 programming problems = 300 submissions. 10 mins per submission = 3000 minutes = 2 days of continuous grading. Impossible.

I have heard instructors make scripts, use some tools. Sometimes, they get super strict on the output of the program so they can grade it easily. Worse, they make problems easier so it's easier to grade.

How can I automate this efficiently?

The degree of automation that you can achieve depends on how you want to grade. The most valuable type of grading (to a student) does not only cover whether the code works or not, but also offers suggestions as to how to make it better, including readability, design, and so no. And that you cannot totally automate.

You can (and should) automate basic setups, compilation, and  tests, and generally remove as much grading-boilerplate as possible via automation. Todo so, the first step is to make sure that students will follow certain reproducibility guidelines. In my case,

The instructions for assignments always include a specific test environment and test command, that must run. So for example, this could be "jdk 1.7 as installed in the lab" + "javac of your .java files". This allows me to ignore "works for me in my place" excuses -- unless it works in the test environment, it will not receive a passing grade. Note that this is generally not a the development environment; that may be eclipse or whichever other IDE they choose. I generally try to stick to the lowest common bare-metal standard.
JUnit or other unit-testing frameworks are great to assert minimal performance. You can either request them to write their own tests (make sure to specify what these should cover), or provide them with pre-written tests (more effort, but hopefully more in-depth testing). Ryan Nutt's answer also offers good suggestions. Unit-testing is huge not only because it helps you to grade, but also because it makes students aware of their own errors; they will then fix these errors before submitting the assignments, which is a clear win-win.
Mandating command-line friendly build tools (maven, scons, makefiles, scripts, ...) really helps to quickly pass the above tests.
Students must use an online submission system (eg.: Moodle task) to upload their code.

Afterwards, in my grading setup,

I download all submissions for the assignment, and each will be nicely tucked into files named after the uploading student. I then run a small shell script that extracts each submission into a single folder. After significant frustration, the script has been tweaked to deal with .7z, .rar, and .tgz archives instead of the requested .zip files.
I write small per-assignment scripts that I can point at a submission and will

open my favorite IDE pointing at the submission
compare it side-by-side with previous submissions by the same author, assuming that this is an incremental project, using meld or a similar visual diff tool.
launch any corresponding unit tests to see if anything fails

I then write a per-assignment check-list of items that I want to look at in each submission. This gets refined until I have graded 5 or so, when it sort of stabilizes.
Finally, I get to grade the bulk of submissions, writing comments for students as I go, and often copying and pasting comments from previous submissions. When all are graded (and not before, because I sometimes have to backtrack or refine grading criteria), I copy-and-paste comments and grades to the online submission tool so that students can see them. The most frequent mistakes make the bulk of the next lecture.

So essentially I recommend standardizing as much as possible, and investing some time into per-assignment automation, in order to speed up actual grading.

Please, take a look at Stepik. Actually I myself work at Stepik, but if you're looking for a free cloud-based solution, it might be really useful for you. Code challenges are tested using stdin->stdout and you can specify any test cases that will be used to check student's submission.


What are good examples that actually motivate the study of recursion? One of the traps of imperative-first is how difficult it becomes to help students make sense of recursion when they finally encounter it.  And if those kids are fairly competent iterative programmers, they may also resist the new technique, as they feel perfectly comfortable solving problems without it. Many of the obvious examples of recursion (such as Fibonacci numbers) are either faster or cleaner when done iteratively.

What examples, then, cleanly motivate recursion?  To be honest, they don't have to even be coding examples.  What I want is for students to intuitively understand the purpose of this new (to them) technique.

(I am aware of this question of course, but, while it is helpful, is is after an explanatory analogy to clarify recursion, while this question is about finding a clear motivation to study it in the first place.)

I find a very easy to understand example for recursion is the folder structure on a computer.
Look through all folders (within a certain location) and... list all .doc files, for example.

First, you look in the location you were given and see what you're looking for... or not, but you see more folders.
Then you take each of those folders, look into them and see what you're looking for... or not, but you see more folders.
Then you take each of those folders... (you get the idea)

It's a simple function to write and understand (at least in pseudocode, actual implementations may vary^^) and a concept that's easy to grasp for even a complete beginner. Introducing the problem and the manual solution, it's already obvious that each time, the same thing happens again and again. Pseudocode implementation is equally simple to write and grasp:
function findFiles(folder) {
  look for .doc files, if found add them to fileList.txt
  look for folders
  for each found folder: findFiles(foundFolder)
}

I've used this example to explain recursion several times, and never had trouble getting the person to understand it. Even non-programmers can grasp the concept like this.

Water is a good example, when you pour a jug of water compare it to the algorithim the algorithim or water is continually poured until there is no more water left or the base condition is satisfied, leaving you with a solution, comparing a water fall to a bad case of infinite recursion it just continues flowing.


Using Processing as an entry point in an Introductory Course We have two entry points for programming students here: one is web-oriented and features HTML5/CSS3/ECMA6, and the other is in a robotics environment using LabView.  Both classes address the "big 5": variables, objects, functions, conditional logic, and iteration.

We are thinking about a new entry point for a new audience. What features of the Processing language lend themselves to an introductory course?

I am currently designing an intro to programming course for middle school students using Processing. In particular, I am using these two resources to focus the curriculum:

Make's Getting Started with Processing: A Hands-On Introduction to Making Interactive Graphics

Raspberry Pi Foundation's "Introduction to Processing" Resource

Make's resource moves all the way from simple, one-line programs like ellipse(50, 50, 80, 80); to OOP, file IO, JSON, data visualization, etc.

To supplement these resources, I am using videos from Daniel Shiffman's YouTube channel The Coding Train. Of particular value are his short coding challenges where he completes a programming task in the allotted time while talking through the design process.

I find that Processing's power comes from its scale combined with its ease of entry. I can confidently say that students will be writing "real" code on day zero and getting instant results on something other than the command line. Plus, there's the satisfaction of starting to learn programming with a text-based language instead of something like Scratch which can feel restricting and elementary to some students. And, as Daniel Shiffman's videos show, there's really no stopping how far you can go with it.

Bret Victor offers some excellent criticism of specifically Processing (and Javascript) as a language/environment for learning to program, in his wonderful (like almost everything he produces) Learnable Programming essay, with respect to things like readability, making computation visible, decomposition and recomposition and more. It's a must-read!

  JavaScript and Processing are poorly-designed languages that support
  weak ways of thinking, and ignore decades of learning about learning.


Is it bad to force my students not to return early? A fellow teacher of mine is teaching "basic algorithms" course in high school, and we have quite conflicting opinions when it comes to returning from functions.

She restricts return only to the end of the function, and permits no other way to escape functions. No block guards, too, and no breaking loops using return.

To be clear, the approach she teaches her student with is "Single Entry, Single Exit", when the exit is at the function's end and does not break a loop (instead she prefers using flags, even though sometimes in my opinion it makes the code messier).

In contrast, I prefer teaching my students the option to return early and how it affects their code and flow, and let them decide by themselves what they think is right to do. The criteria guidelines I usually teach are:

Do you return early because of your functions logic, or because you were given an exceptional parameter/erroneous parameter? If we're talking about the latter, it is ok to return.
Are you able to avoid returning in the middle without the cost of changing your whole control flow? If not, it is ok to return.
Will avoiding returning early add unnecessary nesting levels to the function? If so, it is ok to return.

Is it a wrong approach, giving your students the choice? Or is it wrong to force them never to return early?

Edit the answers suggested some very interesting difference between many languages. We are teaching C#, which is a high level language, so I wasn't considering jmps of assembly or lower level C's deallocation of resources.

Actually returning early should be the norm. Return as soon as you can. There are at least two reasons for this, of which the first, efficiency, is the least important. But if you return early then needless statements won't be executed. Nor will you need to devise some special code to get to the end just so that you can return.

However, the biggest and most important reason for returning early is that the programmer can put a limit on what she/he needs to retain mentally about the state of the computation. This is especially helpful in a sequential if situation. There is actually an Elementary Pattern about this ("Return, not else") that says that if you know what should be returned at the end of an if block, don't use an else, but instead end the block with the return. The reader/writer/updater then gets to ignore the previous state and start over in their thinking process.

If you return only at the end, say "return result;" then you have to track all changes to result that might occur anywhere in the function/method. You have to understand it "as a whole" rather than incrementally. But the reading itself is normally sequential and incremental.

Of course if you always write three statement methods, this won't occur, but few have the discipline to really do that. Sadly, some programmers can't understand their own code when it contains very many nested structures and tests.

I'll also note that this is somewhat related to the idea that we generally try to avoid global variables in programming. Too much extraneous information can impinge on understanding. Being able to comprehend a program "one block at a time" without reference to others, even containing blocks, is a big advantage.

Caveat. Of course, the code should be as clear as possible. If returning late makes it clearer, I wouldn't forbid it. But I think that is seldom the case. Forbidding early returns, however, is counterproductive.

I propose that the correct answer is to keep doing what you're doing, by teaching the techniques that you're currently teaching.  Both of you.

I was taught with the approach you use.  When I was first exposed to the other approach, I didn't much like it.  But with an open mind, I learned that the approach used by the other instructor is useful for some analysis processes.  Most especially this refers to some particularly older "source code analysis" software tools, but there may be some ongoing benefit to that other style too.  As I didn't have experience with the practice of using those specific auditing processes, I'm not in the best position to judge whether the benefits outweigh the pains of constraints.

So, have students be taught both methods.

Maybe students won't like being coerced into being graded on how well they use one method, only to be later graded in another class based on how well they accomplish coding using the other style.  The transition may be unpleasant.  Tough.  That's great.

It is good for students to be prepared for the workforce, and many may benefit greatly from learning that an expected style might not match whatever their personal preference is.  If they are allowed to get locked into one style, that may cause challenges in the future when they transition into their first employer, or transition between companies, or even transitioning between different departments of an organization that may have different policies for different departments.  Getting the students uncomfortable if they don't adapt may be better for them to experience now.

If having different requirements leads to them being uncomfortable, tell them that different employers may expect different things, and even different projects (e.g., different open source projects) that they may want to become a part of during their off-time.  So may different instructors.  They are welcome to use whatever approach they want for their own personal hobby projects that they are in charge of, but when other people are in charge, then cooperation can be oodles more important than advantages of a particular style.

So, no, my advice here is: don't give them a choice.  Make 'em adapt.


Engagement advice on Creative computing I'm preparing a course for next year, aimed at kids from ~6-16. It's based around the concept of creative computing:

http://scratched.gse.harvard.edu/guide/index.html

I think it will be a great experience. We'll be working around Scratch, and a lot of stuff involving game development, animations, and who knows what else will come.

The real challenge I see in this course (as well as the main objective) is how to engage the kids into this world of development: The stereotypical kid in this age range is just interested in playing games with their parent's smartphone or tablet. Some of them have a PlayStation or other gaming system, but at the end, they spend a lot of hours playing modern games, which are ridiculously easy to play (don't get me wrong, some of those are great, but the majority of them don't promote any required value like endeavor or perseverance). Those kids don't know the amount of work that those games involve, and I'm a bit afraid of them getting frustrated by the fact they cannot easily make AAA games like the ones they're used to in a matter of minutes.

Has anyone experience in a similar environment, who can provide experiences and feedback? How do you engage those kids into this world that requires so much sacrifice and willing to learn?

Show them the cool stuff they can do with Scratch.

Don't focus on explaining that they can't make a AAA game. Focus on showing them examples of stuff that is engaging and interesting, that they can do with Scratch. Come up with a showcase of interesting programs. Make sure your assignments are engaging and interesting.

Taking a step back, I'd also recommend you give your students the benefit of the doubt. Don't come in with an attitude that assumes they only care about modern video games and smartphones. Connect your lessons with stuff they do care about. Have them draw a scene from their favorite show, or have them make a game or animation about their friends.

And taking another step back, the age range of your students is very high. A 6 year old and a 16 year old are very different. I'm not sure Scratch is the right choice for 16 year olds. Maybe try something like Game Maker or Processing? I've mentioned Processing in a bunch of my other answers, and I'd be happy to talk more about it with you if you're interested.

Regarding your question:

  How do you enroll those kids into this world that requires so much
  sacrifice and willing to learn?

You don't. You present the material and there will be one of three outcomes:

They are not interested and probably never will be. This is the norm for almost every possible thing that students ever learn.
They are interested in learning, but they never end up using it beyond schooling. This covers 99% of the other cases.
They are interested and end up doing it as a career. This happens about 1% of the time for basically every possible thing that students can learn.

Schooling has two objectives: 1) produce people with broad experience, 2) produce people who can do something for a living. We need both, and cannot force students to be interested and eventually do something for a living. It is up to them. Throughout time, there have been few people doing architecture, painting, music, writing, acting, cooking, and so on. Few people do any particular thing, and there is a large and growing set of particular things that people can do.

For some reason, computing is thought to be somehow different, but it is not. Few people learned auto mechanics, or civil engineering, or aviation, or radio technology, or oodles of other extremely useful things developed in the past few hundred years. And, because it is technology, few people actually had to. That is the point of technology. It is especially true for computing.

So, teach, and let the students decide which of the three levels of interest they have, which is a decision made over the course of many years, and involving many factors, nearly all of which are outside your control.


How to explain the concept of a variable to a 9-year old? My 9 year old daughter is heavily interested in science, robots, computers, … She asked me if I could teach her how to program a computer. So, we started with Scratch, a programming language specifically designed for kids.

She likes it a lot, and she enjoys getting visual results fast. Now we came to the point that you need a variable, and I have realized that she has not yet understood what a variable is. Of course, at school, they didn't have the concept of variables in mathematics yet (mind you, she is 9 years old).

I remember that when I learned to program, I was 12 years old, and I had a hard time grasping that, too. Although I'm a professional software developer, and I help other people a lot to learn to program, I find it very difficult to explain it to her in a sense, that she can understand, and that is suitable.

Of course I can say:

  It's like a box, where you put the number 9 into it. If I ask you how old you are, then you don't say "9", but you give me the box, and I am going to look it up on my own.

That's an analogy, and she understands it, but it's difficult for her to transfer this idea to Scratch code. It doesn't feel correct.

If I say

  It's just a name for a value, and everywhere where you normally would use the value itself, you can now use the name. This has the big benefit that you can change the value, but keep the name.

it feels correct, but it's not easy to grasp any more. To cut a long story short: In contrast to a loop (do this and that for a given number of times) or a decision (if X then Y), variables are way more abstract.

So, how would you explain the concept of a variable to a 9 year old, in a way, that it is easy to grasp AND correct at the same time, i.e. it has a direct relation to writing code?

Buffy's lovely answer shows well how two variables can refer to the same thing, but since we are in early cognitive development and working with Scratch, in which you can't pass parameters, and can't arrange for two different names to refer to the same instance/spawn, I wouldn't focus my efforts on that point yet.  What matters is the idea of a holding place and mutability.

These concepts are hard to describe in a way that a 9-year-old would already know how to mentally model, but one very similar idea with which they are already familiar is the idea of a "role".

The President of the United States is currently Donald Trump.  (You should substitute the head executive leader of whatever country your child lives in for this example.)  But a few years ago, it was Barack Obama.  Later, it could be Mike Pence, or someone else entirely.  When important things need to go to the president, they go to whoever is the president right now.  They don't go to Barack Obama any more, and some day, they will no longer go to Donald Trump.  But they always go to the President.

So, to put this into Scratch, we can make a String in scratch called President, and then we can use the set box to set President to "Donald Trump".  We can then make an item in the main field that behaves as a button, that changes that variable to [insert your child's name here].

Now, we can create another value, called x, and set that to a zero.  Now, when you press the button, change x by 4, and we can watch the variables change.  Press the button 10 times, and the value becomes 40.

So, what can we say about x?  Sometimes we say that x is 40, but is it really?  Or does it just hold 40?

This is the most important early understanding to arrive at when describing a variable.  When we say that x is 40, what we really mean is that x holds 40.

First explain the kid meaning of variable as something that keeps changing (like weather). Then he will get idea about the word and then tell him, in CS how we assign a value to the variable and how we are able to change it afterwords


Easy to use database for HS students I'm a web design teacher and I teach 9th graders (14 year olds) in the US.

Currently the 9th grade curriculum in my HS programme teaches students CSS, HTML and JavaScript. Students can create buttons, forms, navigation bars, and other fun things at the end of the course.

I was wondering - I want students to be able to get data from a database so they can inject data onto their websites.

Is there any easy to use database platform that would allow 9th graders to enter data easily (like Google Sheets), and pull data using client-side JS?

Even better would be that there already exists an API for getting queries so I don't have to teach SQL?

Just looking for ideas! Even instructions on how to build the service myself would be great.

Is there any easy to use database platform that would allow 9th graders to enter data easily (like Google Sheets), and pull data using client-side JS?

Given that you're thinking about Google Sheets as a data entry method, I understand that your goals don't extend to getting the students to implement server-side form handling. But in that case, why do you need a database? It seems to me that the requirements given can be met perfectly well by a hand-coded JSON file.

You can try to use browser storages to explain some concepts of storing and retrieving data: cookies, local storage, session storage or even WebSQL.


What ethical practices do students (as potential software engineers) need to be trained in? The kinds of things that people with technical training can do have societal impacts, both for good and evil. Programmers are building the future. One future nightmare is Skynet.

Many problems in the world have been caused by scientific hubris as well as the Fallacy of the Last Move, a concept from Game Theory as it applies to Arms Control and other strategic thinking.

Unbound technologists, especially if amoral, can be very dangerous to the earth and its inhabitants.

So, it seems that future Software Developers need some training in ethical concerns. What, to you are the most important issues and where in the curriculum should they be taught?

Note that ethical issues can be simple or complex. Even something as simple a accepting buggy software can have ethical implications and such lessons can be taught in early courses.

At the other end of the scale is the question of how much a person owes to their employer vs to humanity as a whole.

What essential ethical practices do students need to be trained in?
What are effective ways of integrating ethics into the curriculum?
What are the first steps a teacher should take in integrating ethics into the curriculum?

A general discussion of Computer Ethics is: https://plato.stanford.edu/entries/ethics-computer/

I'm going to begin by quoting Ken Thompson's Turing Award Lecture "Reflections on Trusting Trust" (link).

  To what extent should one trust a statement that a program is free of
  Trojan horses? Perhaps it is more important to trust the people who
  wrote the software.

In my mind the first and most foundational lesson to impart is this: software, computers, technology -- these things are more about people than about code. There is a trust from the end-user, whoever that user may be, that must not be violated. Users are not means to an end; they are the end. The code is the means.

I am reminded of the Second Formulation of Kant's Categorical Imperative:

  Act in such a way that you treat humanity, whether in your own person
  or in the person of any other, never merely as a means to an end, but
  always at the same time as an end.

In terms of integrating ethics, the way to start in my mind is discussion. Early and often. Share news stories. Discuss implications of new apps students download. The first 12 minutes of this CS50 lecture cover the the Volkswagen/EPA scandal from 2015 and mention Ken Thompson's lecture. It is essential that awareness is built right from the beginning that software is everywhere and there needs to be an ethical code to guide that development. In my mind, while I wouldn't consider myself Kantian, I do think his point about means and ends is essential.

The AP Computer Science A curriculum outlines the following requirements under the major topics of the course:

  VI. Computing in Context

  An awareness of the ethical and social implications of computing
  systems is necessary for the study of computer science. These topics
  need not be covered in detail, but should be considered throughout the
  course.

  A. System reliability

  B. Privacy

  C. Legal issues and intellectual property

  D. Social and ethical ramifications of computer use

Similarly, in AP CS Principles, students, as a part of the Explore Task, have this on their rubric for the assessment:

  Analyzing Data and Information: Identifies one storage, privacy,
  OR security concern. Explains how the concern is related to the
  computing innovation.

The moral of the story here is that ethics must be discussed with students as soon as possible whether it is a high school AP course or an introductory computer science course at a university.

This idea of trust must be imparted to students, and it must be emphasized that the world of software engineering and computer science in general is not in a moral vacuum. It does no good to address a particular issue, say data privacy, without first contextualizing it within a larger ethical system, one that sees each user as an end, not a means, and as someone who is placing trust in you the developer.

There are certain unsolvable problems (I am not referring to NP), that seem solvable, and an apparent solution can be made and deployed. These systems can be used, but do not fulfil there requirements (security, privacy, …).

This differs from the case where the software lacks these features, because of poor workmanship (also an ethical issue), in this case it can not be done. I turn down the work, because it is impossible. The client thinks they need to find someone that is more clever, that can do it. Eventually they find someone that has no idea of the problems, that agrees to do the project. If the new supplier realises that it can not be done, and tells the client, then the process repeats, else a faulty product is delivered.

An example is electronic voting.

It is impossible to create an electronic voting system that meets all of the requirements. If we just have 2 of the requirements for a voting system.

Anonymity
Trustable

Then we can not produce an electronic system, that can meet just these requirements. There are also other requirements, thus it is even harder (in the higher than infinity sort of way (∞+1 = ∞), therefore we don't need to look at the other requirements, to see how hard it is).

How would you audit this system? You could check its source code, to see that it does the right thing (if you can read it, so every one involved would have to have a good enough level of CS, and know the language). Oh but how do we know that the system is running this code.

Every single solution to this problem, has a counter measure ( a dis-proof ).

This has not stopped these things from being deployed many times, and in countries that are considered to have a well run voting system.

What is needed

A box, that you put all of your votes into, and out comes a count for each candidate.

Possible solutions

How do you know that the output is correct. Ah that is easy, you produce an audit trail. But now we have no anonymity. So we add encryption. But for it to be audit-able, anonymity can still be broken. (If you can check your own vote, then I can check your vote (if I torture you long enough, then you will give up your key).

A solution that works, but does not use a computer.

The many boxes
  - you walk into a room (box1), and show your ID, your name is removed from the list, and you are given a voting sheet.
  - you walk into a subroom (box2), and make your mark on the sheet.
  - you then fold(box3) the sheet.
  - you leave box2 and walk to a locked box (box4), and place your sheet into it.
  - at all times observers (from all interested parties) are walking around box1, to check that the rules are being followed.
  - at the end box 4 is sealed.
  - latter box 4 is opened and the sheets counted. With lots of people watching. A set of totals is produced and announced. The sheets are put back in box 4, sealed and locked.

I have probably missed some detail, but this solution cannot be implemented electrically, because there is no way of putting people into the electronic boxes to observe.

Some videos on this

The problem

Some solutions I found a problem with all of these solution, as I was watching it (Did not have to sit and think for days).

Other stuff


Search for a useful interactive programming environment More interactive environments are easier to learn, but the text based ones I have seen lately don't let you change your mind.

I have used Read–Eval–Print Loop (REPL) environments. However these are not suitable, as it is not possible to edit or view code that one wrote earlier.

In [1]: a=5

In [2]: b=a/3

In [3]: b
Out[3]: 1.6666666666666667

In [4]:

they are of some value. However it becomes less useful when creating something big, when creating routines.

I want to be able to create sub-routines interactively, and then be able to inspect them, and edit them. It also needs to be easy enough for teaching beginners.

In [4]: def double(a):
   ...:     return 3*a
   ...:

In [5]: show double

    def double(a):
        return 3*a

In [7]: show --all

    def double(a):
        return 3*a

    def oneMoreThan(a):
        return a+1

I am not too worried about language. I am just looking for a nice interactive learning environment, that combines the best of REPL and editing. Can you tell me of anything that you use or know of?

I will add an answer that shows what I have found, but it is not an acceptable answer as I don't think it is easy enough.

I am not too worried about language. I am just looking for a nice
  interactive learning environment, that combines the best of REPL and
  editing. Can you tell me of anything that you use or know of?

Runestone Academy has a component called ActiveCode that allows you write Python code and run it. It also has a slider so that you can go back to earlier versions of your source code to review and run.

In addition to activecode, you can also execute Python code with the assistance of a unique visualization tool. This tool, known as codelens, allows you to control the step by step execution of a program. It also lets you see the values of all variables as they are created and modified.

There is a lot more to the web site but is what I use to help others learn Python 3 and the nicest part is that once the students get the hang of the e-books they tend to take off at their own pace.

I can wholeheartedly suggest Xamarin Workbooks:
https://developer.xamarin.com/guides/cross-platform/workbooks/

Awesome, nice UI. You can use it for more than Xamarin, if you are teaching any .NET based class, it is a very valuable tool. There are a couple of sample workbooks avaialable here: https://developer.xamarin.com/guides/cross-platform/workbooks/samples/

And the best part is that you can extend it yourself, if you know a little typescript. I've created one a while back to demonstrate how Entity Framework Code First creates the database tables from the defined source code. You can check it out here, if you are interested: http://dotnetfalcon.com/net-workbooks-entity-framework-model-explorer/


What part does formal Ethics training play in your curriculum? What is your current practice of teaching ethics to students, both institutionally and individually?

Note that the teaching of ethical standards (not just lists of rules) has at least two elements: What to do, as well as what not to do to be ethical.

Are your students required to take any ethics courses? Are those courses tailored in any way to the concerns of the technorati? Do you bring up ethical consequences of the things you teach? Are you required to? What topics do you think are most important?

What can you recommend to others for giving students some ethical training?

Are students required to buy in to an ethical standard beyond the classroom?

Or do we simply depend on, and hope that, it happens somewhere.

It would be helpful to know which courses you teach that clearly require ethical behavior and how you go about teaching it. For example IoT (Internet of Things) development has clear implications about security and privacy. How do students learn this?

I hadn't really considered teaching this, but one could use the ACM Code of Ethics and Professional Conduct, and simply talk through the major points. I looked at the General Moral Imperatives section and it basically boils down to the usual ideas about "doing what you would want to happen" in a situation. If people do not realize that we are in a collective enterprise and that their actions affect everyone, then they need more basic education.

To answer your questions: There is some "soft skills" training here, but I am not involved in presenting it. As far as I know, it is not discussed otherwise and the students are not required to accept any set of principles. I guess we figure that they already have it. My co-instructor referred to ethics as "the things we used to assume everyone already knew." Where and how they used to learn it and who is failing in their responsibility, I do not know.

Gerald M. Weinberg writes about The Platinum Rule (do unto others as they would be done unto) and I can't see that much more needs to be said about ethics, beyond illustrating what could happen if that rule is not followed. It is no different from other fields that have codes of ethics and professionalism. (Except that we can easily influence the lives of millions of people, for good or ill.)

In this reference - Stanford panel debates: Does teaching ethics do any good? - they ask, "can something as personal as ethics be taught in a classroom?" I don't see ethics as personal, any more than physics or finance are. If you know what to do, you can safely assume that any other person who also knows will do the same thing. The only 'personal' factor would be ignorance.

It also says, "teaching students social psychology, rather than moral philosophy, is one of the most effective ways to make them more responsible social actors." I would agree. Finally, one participant said, "When I teach them how to write a philosophy paper, I definitely assume I know better than they do how to write a philosophy paper ... [but] I'm 100 percent certain I am not more virtuous than many of my students. Some of them live much more conscientiously than I do." I don't understand that either: why wouldn't more experience make one more virtuous? As the old saying goes, good judgement comes from experience and experience comes from bad judgment. Shouldn't this be true in all cases?

IIRC, my shop and chemistry classes included mandatory safety briefings.  Many educational institutions have a code-of-conduct with which students are supposed to know and comply.  The same should happen and apply if any computing activity might affect student safety, or potentially violate the conduct code.


Should CS students be doing their tests on paper? In some CS courses (especially undergraduate and high school courses) the tests and the final exam are written on paper without the use of a computer.
But if the students are in a CS course, shouldn't they be allowed to use the computer? If some mistakes are difficult enough to not be noticeable while writing code on a computer, they are nearly impossible to be found while writing code on paper.

So, my question is, are there any advantages in doing written tests on paper, and is this the best approach?

100% yes. In beginning courses, it's practically a cognitive requirement.  Let me see if I can break down for you why it is so important.  It comes down to what we can know that the student knows.

Let's say we have a student who is a rather mediocre coder and who, to be honest, really has no idea what is going on in class. We're going to give him a problem in Java, which is to go through an array of ints, add all of the numbers in said array, and return the result.  We're also going to let him use an IDE to build it, so that he can find syntax errors and spot-check himself for silly errors by running the code.  The first thing he writes is this:

for(z=array[0], z < array, z+1){
    z=array[0];
}

So, how much can we say that he actually knows?  I can forgive that he used commas in his for loop.  I might even, depending on his background, forgive that he forgot to declare z.  But what can be said about the fact that he set z to array[0] instead of to 0?  Or that he is comparing z to array instead of array.length(), or that he is never actually changing z in his z+1 statement? These are mistakes of comprehension, not syntax.  What, also, can I say about the fact that he keeps setting z to array[0] over and over again?

The fact is that, if he writes this into an IDE, a few things will happen.  A bunch of code will light up red.  A red line will remind him that he forgot to make a return.  Another red line will tell him that z < array is not possible, because they are of different types.  So, he will start typing things until the red lines go away.  Does he necessarily understand the things he is changing, or has he been trained, Pavlovian-like, to change code that has been underlined in red?

As he makes some red lines disappear, new red lines pop up.  He then turns his attention to those until he makes all the red disappear, and now he has this:

int g = 0;
for(int z=array[0]; z<array.length; z=z+1){
    g=array[0];
}
return g;

This code is much, much better.  It's still not perfect.  But, given the flaws in his first draft, do we have any reason to believe that he really understands this new version and why it is actually better?  Or is he just changing code until the red goes away?

Now, he runs it, and it immediately ends by returning the value 0.  So, since he still has about 5 minutes left to his exam time, he starts just changing things at random.  He changes his int z to be = 0.   Now he starts getting a number returned!  He tries putting g into g=array[0], then he puts z into it.  Now he has g=array[z].

He dithers about a bit, and finally adds a + in there.  He now has the correct code:

int g = 0;
for(int z=0; z<array.length; z=z+1){
    g+=array[z];
}
return g;

He turns it in to the teacher, who says, "Boy, he sure understood this!  That's one student that I don't need to give any extra attention to, because he is in great shape in my class!"

The takeaway questions then are:

How well does the student understand the material?
How well does the student's grade reflect that?
How much worse are the odds that the student will now receive the extra help that he so desperately needs?

We need tests that actually show what you really know, which is not always the same thing as what you can produce with prompting help from an IDE.

Yes. If you use a computer to take a test, for instance, you will have the tendency to code and check the program if the software is already there else you verify your answers on the Internet. As a skilled programmer, you can take tests manually and to the coding part you can shorten it. The school and college tests are just to ensure that you can remember the concept well.


How can we educators improve a lot of the negative behavior within the CS community One thing I noticed in the years I've studied CS and wrote code is the arrogance that a lot of programmers have within the CS community.

I remember in high school, coding was just for the tech savvy children. God forbid you ask them a question about a topic because you would often get a rude response.

Then I went to college and a lot of people were acting the same way. Everyone kind of doing their own thing, very anti social, and keeping to themselves.
I now teach CS and notice the same behavior with kids whereas in other classes (like reading, writing, art) kids are more expressive, outspoken and creative.

If CS were more widely accepted, I believe more people would pursue a career in it.
I think that is the problem with CS - people are afraid to try it because it seems intimidating and is surrounded by this anti social behavior that repels a lot of people.

How do we educators improve the negative attitudes and behaviors that some of our students seem to exhibit?

I reject a lot of the assumptions implicit in the question. Computer science isn't just for geeky or "smart" students. And I don't think it's fair to say that students in other classes are "more expressive, outspoken and creative." Computer science is full of art, creativity, and expressiveness. It's a teacher's job to show that to students and encourage every student to try it out.

I advise you to work on your own assumptions first. If the teacher thinks that computer science is not for creative students, then what hope do the students have?

Things to consider:

How are you "advertising" the computer science courses? Are you highlighting the artistic and creative aspects of it? Are you appealing to  students who might not self-identify as programmers?
What types of programs are you using in your lessons? Are they "boring" command line applications, or are they interactive and visual?
What types of programs are you assigning for homework? Do they encourage students to express creativity?

In addition to working on the assumptions of both your students and yourself, I'd also advise you to consider the needs of students from "non-traditional" backgrounds. More things to consider:

Are you "making room" for students who often get drowned out by louder or more active students? "We've heard from Grace already, why don't we give somebody else a chance to answer?"
Are you recognizing the work done by every student? I'd like to show you all a really creative example of how Ada used for loops in the last homework assignment...
Are you calling out bad behavior? Are you encouraging good behavior? Hey Grace, I know you know this stuff really well, so during lab today would you mind helping me out by answering Ada's questions?

These types of change have to start with you. I don't agree with a lot of the assumptions in the question, and I encourage you to take a harder look at some of the assumptions you're bringing to the classroom (which your students pick up on and perpetuate). Fix those, and you'll be able to help your students fix their own assumptions.

I think that "arrogance and shaming" are side-effects of personality traits which are indicative of the type of effort needed to master something abstruse like programming. The people who drill down in to it and self-learn succeed because they are not social people who take time with peers or really give a rip what others think of them. If someone is more social and pleasant, they probably will not have the drive to accomplish the learning, they will be out with friends instead. Having no friends is a strong incentive to do something alone that is intrinsically rewarding: master the computer!

A similar example can be found in other fields: look at the 'best' doctors or lawyers. Are they nice, kindly people, or are they a bit ruthless? My father was a successful lawyer, but smart enough to be nice when necessary, and tough enough to work long hours, almost always. He was rewarded, but not by being considered personable by those closest to him (family).

I think we have to assess the nature of drive and consider carefully what it takes to succeed in fields where an enormous amount of effort is needed to gather and master a range of very abstract concepts. Niceness is peripheral or even an impediment to drive. That said, we can move people from their natural tendency (of arrogance, for example) toward more effective ways of relating, but that will be an add-on.


Should programming assignments be graded based on results from unit tests or based on the similarity to the correct implementation? Imagine students in a course on algorithms & data structures, which are given homework assignments to implement things like trees, hash sets, sorting algorithms, etc.

Due to the high number of students per semester and limited resources, grading is heavily assisted by automatic unit tests. The TAs will still scan through the code, but if all or most of the test cases fail and there is no simple fix in sight, students will get 0 points on an assignment.

Unfortunately, this can happen very quickly. Consider implementing a balanced tree as an example. If students fail to correctly reference the nodes, insertion, removal and searching, - despite being implemented correctly if seen individually - will not work and can hardly be tested.

As expected, some students do complain about their poor grade and argue that "although they acknowledge that their data structure does not work entirely, they at least implemented various sub-tasks correctly". This may even be correct, but the TAs very often do not have the time to dig deep in the code and grade the internal functions of the students implementation. Especially for more complex data structures, it would also take too much time to fully comprehend and even debug the (erroneous) implementations.

My question is, if it is okay to grade programming assignments based on this external view (does the implementation pass the tests?) or should grading rather be based on an internal view (are the things implemented by the student correct if seen individually?).

One important remark: In this specific scenario, students were not given the unit tests, since they are expected to test their implementation themselves.

Actually, life isn't so simple as to choose one or the other here. Code needs to be well structured and it needs to be correct. Given that students are learning, you can't really expect that they will be perfect on either of these and so you need to take both in to account. A program could, be well designed and built but have some, as yet undiscovered, flaw that prevents it from passing its tests. If the students hack it up to get tests to pass they are going backwards, not forwards.

CS students have a lot to learn. Programming is important, but not the most important thing. But to advance on many of the other goals of the CS curriculum, students need to build good code. Even better, would be the ability to build maintainable code, since many of them will start their careers in programming-heavy jobs. Even if they go to grad school, much of what they do will depend on being able to write good code.

So, in grading, points should be gained or lost depending on both code and correctness. If the code is not correct, then someone needs to make an analysis about why the code is failing. It could be something simple or profound.

In my view if a program can't be understood easily and/or seems to be hacked together, it should receive few points. If a program, on the other hand, passes few tests then it is a much more subtle problem that needs deeper analysis. Don't neglect it.

In the question heading you talk about the "correct implementation". I worry about that. Students should not be graded on similarity to any reference implementation, certainly. There are more than a few ways to write a correct program.

Unless the objective of the exercise is to copy an implementation (say from Java to C++), the "similarity" to any other implementation should have no weight in the grading. At least not in a positive sense. The similarity to another implementation could, however, be a warning sign for plagiarism. Everything else in the question is up for debate, so to speak.

The "fairness" of the grading only hangs on two principles: Consistent application of standards and advance notice of those standards. If the same standard, or evaluation, is applied to all the work received, and the assigned grade would be the same regardless of which student turned it in, or which TA assigned the grade, then the standards are applied consistently. Prior to the examination, or assignment, the students need to be informed as to how their work will be evaluated. In the course syllabus, or in the beginning of the course is the best time to inform them, of course. If they have been given such a notice, and then their work is evaluated according to that guide, there should be nothing to object to - from a "fairness" point of view. Knowing that there will be unit tests, even without knowing what those might be, is still acceptable, so long as the same unit tests are applied in a uniform manner to all the work evaluated.

How "fair" the evaluations are, however, likely has very small significance to how well the evaluations move the students toward the course objectives. Likewise, how such projects would be evaluated in a real-world workplace environment likely does not move them in the direction of meeting the course objectives. Of course, if the class is the final course in a series, the objective of which is to produce work-ready employees, then a purely external view of works vs. fails might be appropriate. In all other cases, however, such an extreme approach is not a very pedagogical approach. (As a side note, a binary go/no-go grade does not fit well into a scaled grading system either.)

In an idealized world, the student projects are a chance for the instructor to determine how well the student has apprehended the course materials thus far, discover where the student has stumbled, and take corrective measures to return the student to where they should be relative to the course materials. Teachers, of every stripe, are an over-worked, under-paid, unappreciated lot. (The TA's get to share in that "glory", and will become just as over-worked as the instructors.) As such many of the opportunities to learn about the difficulties and misunderstandings the students have will be missed when grading assignments. Having a rubric, published by preference, which the TA can apply to the evaluation often helps.

The course objectives, naturally, have greater weight in the rubric than other criteria. Yet non-course objectives should be included. While seldom included in the course specifications, clean code, naming conventions, documentation or self-documenting code, and adherence to coding style can all be covered by the rubric, and encouraged, thereby, in the students' work. Requiring adherence to such guidelines benefits the instructor (and TA's) in applying fine-grained grading evaluations. It can also aid the students in completing the projects, obtaining better results from the code, ease the burden of debugging the code prior to submission, and developing good habits for when they do enter the workforce, where go/no-go evaluations really matter. (I prefer to give more points to a clean almost-working program, than to a impenetrable kludge that passes every known test. The former can be maintained, including fixing the current version. The latter can probably only be maintained after being re-coded in some understandable manner.)

Unfortunately, my view is only one way of seeing the job of "instructor." As to it is okay to grade programming assignments based on this external view, the answer is; "While it is less than ideal, yes, it is okay to do so."


Explaining why styling should not be done directly in HTML I recently noticed that <marquee> has been deprecated from html according to this site. From this answer on Stack Overflow, the marquee replacement is made from CSS. The explanation given to the change is that html is about document structure, and that layout and animation and styling etc. should be done from CSS.

This got me thinking:

Would explicitly teaching the difference between setting the style attribute of an html tag, and doing it through CSS useful for increasing the students' understanding of the joining of CSS and HTML?

To narrow it down, I'm looking for examples or explanations of how teaching it explicitly might make it easier for the students to style their webpages. Preferably an explanation.

By "explicitly teaching" what I mean is actually devoting a lesson with the title of "Styling through .CSS", or something similar.

Some context, if it is needed:

The students learn basic web designing: HTML, JavaScript (very basic), JSP and SQL. They learn these for 1 year and at the end of the year they should have a website (for which they receive grades). I am wondering if a lesson entirely about CSS might eventually lead to better looking websites.

I like the idea of producing a few style sheets, and having the pupils apply them to their HTML. They can then see the power of having separate style sheets.

Start with a style sheet that you made. Use the new grid layout, have some college styling. But at first get them only creating the html.

They can then start editing the style sheets. They will see that the power of one small change can change every heading, or every paragraph.

I have also in the past, written a HTML file that had a set of buttons at the bottom. These buttons would trigger a different CSS file to be loaded. It was some very simple JavaScript.

To answer should they be kept separate

Keeping style and content separate, is recommended by W3 and many others. It implements separation of concerns and single responsibility. Both very important patterns in software design.

Even better: keep layout, style, structure, and content separate.

One css for layout, another for style, then a template for structure (I use moustache), pull the content from a database, to create json, and programmatically combine it with the template (use a template library). [this section is now about my teaching, but what I do for my websites.]

To answer should you devote a lesson to separate CSS files.

Yes. If it is important to keep these separate, which it is, then you should teach pupils to keep them separate. Save time by not teaching them to mix it in with the HTML (This will save time twice, as you won't have to un-teach it).

I have only done this with one or two people (not a class).

I would completely disagree - styling should be done directly in HTML.

The primary problem is that styling is not even remotely independent of the HTML structure. Simply writing the styles in a physically separate file does not change this. A good example is mobile device support. In theory, you could make a mobile CSS file. But in reality, you probably need a completely separate UI design to produce a good experience on a mobile device, and then a separate HTML structure to support this, and then a separate set of styles. "Make the button the same but a bit smaller" only works for the smallest pieces.

Producing the correct UI involves producing the HTML structure that supports the styles you need. Since the two are in fact intimately coupled, having them be colocated just makes things easy to understand and all in one place.

Moreover, since you are presumably generating your HTML through code, there is no problem with generating HTML with duplicated styles, since your code generator can spit out styles all day long.

Having raw CSS is tremendously problematic as the styles are completely random and at global scope, and difficult to re-use. You make a class name under the hope that nobody else used it. You nest your own classes inside that element to try to solve this problem a bit but now you can't re-use these classes in other places as they're not in the right DOM structure. Then you find out that some random dude in some completely separate part of your page used your class without notifying you and now you've broken it by changing your styles. And good luck getting type checking, IDE support, etc. It's also difficult to create e.g. parameterised classes, or globally apply replacements, e.g. display: flex with display: flex and display: -webkit-flex for iOS.

The correct way to deal with styles is to deal with them as with any other code- encapsulate them in some functions.


Some real practical example to teach object-oriented concepts and programming (in python) I have taught my high school students to write some simple python scripts, taking some ideas from "Automate the Boring Stuff with Python", e.g. changing file names in a folder to a specific naming pattern.
My next goal is to teach them object-oriented concepts and if possible give them some "real" examples to try themselves. But most of the materials I find (most of google's top search results) about OO programming (not just python) are laden with poor examples, if I may say so. I really don't like to use car/vehicle or animal/dog to teach them the OO concept and OOP.
A. it is boring (you know high-school kids)
B. it has no real use.
C. as one comment said "they are fatally flawed."  (But if you really like to use the animal example, check this "Object-Oriented Design")
I plan to use pathlib (btw, they already have a basic idea of the difference between Windows and UNIX)

GUI development could be another good example to teach OOP but I don't want to teach them GUI yet.
Any suggestion to introduce OO with the "real" example?
BTW, I’m not a strong advocate of object-oriented programming. But the pathlib.Path class is a useful abstraction especially compared with os.path, although the high school students are unlikely to appreciate that.
---- update ----
I find the python logging module is another good example, but it seems too complicated for non-experienced programmers.
When using the logging module we mainly use 3 objects, Logger, Handler, Formatter. Logger is the facade, as https://docs.python.org/3/howto/logging.html#loggers said,

Logger objects have a threefold job. First, they expose several methods to application code so that applications can log messages at runtime. Second, logger objects determine which log messages to act upon based upon severity (the default filtering facility) or filter objects. Third, logger objects pass along relevant log messages to all interested log handlers.

Handler is a good example to use inheritance https://docs.python.org/3/howto/logging.html#useful-handlers and handlers use formatters, which hide the complexity of LogRecord, to the format log message.
In addition to these classes, there are a number of module-level functions for convenient use.
Overall it is a good example of using composition and aggregation.
But I am not an expert on the python logging module, I hope someone who is familiar with the python logging module may add an answer to my question.
--- update 2 ----
I found Alan Kay answered the question “What are the five features of the object-oriented paradigm that you consider to be important for good software engineering practice?” with these words, in my opinion, resonate with the answer Buffy gave. But how to convey these ideas to high school students or non-experienced programmers is another challenge,

a “part” construct that can protect it's inside from its outside, and
vice versa
a “communications” construct that can convey interactions and deal
with dependencies
a “system” construct that is a combination of parts and communications
that can fit in a part recursively, and everything is made this way
the “messages” that are communicated are also in terms of the systems
the system that is being made is made with the same kinds of system
...

I expect to update this a few times and hope to eventually have a long answer.
But let me start by explaining some things that you may already be aware of, but other readers may not.
First, OO programming is not, fundamentally, about inheritance and too many books and authors fail to understand that. Moreover, they use inheritance in a dreadful way that makes software hard to understand and harder to maintain.
For example, note that the Linnaeus style hierarchy of the biological world is almost entirely one of "interfaces" and not even "abstract classes", much less concrete classes. There are no instantiated "mammals", for example. It is only at the leave of the hierarchy that things actually exist, other than as ideas. There is some genetic continuity, of course.
Second, there are some principles that can guide you in writing and teaching OO design, but they require discipline. And part of that discipline is to control the situations in which you "break" the rules.
My first advice for anyone wanting to be an OO programmer is not to think in terms of inheritance, but, rather, of composition. Complex things (objects) are composed of other things (objects) that are a bit simpler than the containing object and provide it some essential service. If you write classes where all (or even most) of your instance variables are language primitives, then you don't really get it. And if those instance variables (objects or primitive) have a lot of getters and setters, then you aren't doing OO Programming at all.
In fact, making the above mistakes, requires that the programmer keep track of all details at all points of the program where OO is designed to capture decisions so that they needn't be "checked" again. Set it and forget it, so to speak.
So, if you want to build an automobile, don't think of it as a subclass of vehicle (which gains you nothing: a personal drone and a battleship are both vehicles). Think of it instead of being composed of various parts: engine, transmission, controls, accommodations, etc. And those parts are, themselves, composed of parts. An engine has igniters and pistons, exhaust, etc. Many of those are composed of parts also. It is only at the lowest, simplest level that you build with primitives.
Two of the principles that are worth keeping in mind and following almost always are the Liskov Substitution Principle and the Law of Demeter.
The first suggests that if you extend a class with a subclass you don't also extend the public interface of the subclass. Then all subclass objects are substitutable, differing in behavior but not in interface. Demeter, on the other hand, forces you to write more explicit code that makes relationships clear to a reader. Of course it also forces you to introduce more name, and if they are intention revealing names then your code is clearer.
The Liskov principle, of course is one of the elements of SOLID which you also need to incorporate into your thinking.
In my own programming I'm very faithful to Liskov, also defining Interfaces for most things before I write classes. I'm less faithful to Demeter in the heat of battle, cascading messages. But then I sometimes also need to unravel those a.b.c.d sorts of cascades to figure out what I really mean.
One goal I have in writing OO code is to seek to write only very short methods with a minimum of structure. In other words I try to minimize Cyclomatic Complexity. My palms start to get itchy after the fourth statement in a method of if the complexity level reaches three. I can't always get away with that, but it is a goal. The solution is to refactor complexity mercilessly. Factor out methods, of course, but also "parts", creating new classes to manage the complexity. Even if many of those classes are Singletons the code is usually improved and having the goal in mind from the start, means that the refactoring step is less needed.
Design patters are tools that you need to be an effective programmer in most OO languages. Especially helpful ones are Strategy, Decorator, Observer, and Iterator. Most of these are actually used to build the various Java libraries.

Now, to get to the actual question asked here. But note that a lot of learning can take place even if the students never reach completion of the project in the allotted time. An agile approach (Extreme Programming, say, with you as "Customer") to development leaves them with some functionality even if not all specifications are implemented.
Dungeon Game
Build a text based dungeon game. The main objects are characters (people), places, and things. The places are organized in some sort of map, maze, or grid. Things happen when characters enter places. Characters find and carry things. The things have actions, depending on the kind of thing. A "spell" is a "thing" whose action might depend on context. A "transporter" object might work differently in different rooms (strategy objects).
Note that the classic board game Chutes (or Snakes) and Ladders is a simplified version of this. A text based version avoids a lot of complexity.
Calculator
A calculator has parts such as keys and the display. Less visible are the internal memory, possibly a stack. Even the operations can be objects. The behavior of the keys changes, depending on the state of the computation (Strategy pattern). It is possible to build a simple calculator without a single IF statement, actually.
Abstract Computer with an Assembly language
A Stack Based computer processor simulation is pretty straightforward. There may be accumulators and such, but a single stack on which all operations are done is simple and complete. The operations can be objects (parts). One advantage of this example is that most of the necessary methods can be very short. A program can be read with a Java Scanner object. It needs a program counter at least and possibly a frame pointer if the language is to support subroutines.
Sticky Notes (I haven't tried this)
An application that lets users keep notes and cross reference and organize them. Some classes might be Notes, Keywords, Connections, Lists.
Jeopardy
A simulator for the jeopardy game from TV. Categories, Answers, Questions, Teams, Scores.
(Back soon, maybe).

How about a boring*, but realistic, commercial example? When the students leave the "hallowed halls" and become entrepreneurs in start-ups, they will be faced with the relationships between Customer, Product, and Sale (Transaction).
By keeping all of the Product data (for example) 'together', we introduce the advantage of encapsulation over a basic data structure, eg array. There is scope for hierarchies (later).
Per earlier "composition" responses, when we look at an Address we see that each Customer must have one, oh wait, more than one if his/her billing address is distinct from the delivery address. So, if an Address is part of a Customer, should Customer "inherit" from Address? ("is a" cf "has a"!) What about the difference between a personal customer and a corporate?
Do both have a name, and address, ...? How are they similar/where do they differ? How do we keep track of the individual from the Corporation with whom we are dealing?
What happens when we make a sale? Is this data to be part of the purchasing-Customer's object, or the Product object - or objects, or what? Thus, "Interfaces" (in some languages), an invitation to expand the SRP into micro-services, drop into APIs...
There's plenty of scope for SOLID principles, best practices, language differences, and all-the-fun-of-the-fair. Meantime, you could 'dress up' problems to make the toy-examples seem 'real' any-which-way; and the students are learning 'how the world works' and thus (hopefully) enthused to progress.

personal opinion: can't imagine how Pathlib avoids the "boring" criterion (besides it has its own struggles with 'the concrete', given its abstraction from the OpSys - which is already an abstraction ... Alice, rabbit hole, Toto != Kansas...)