On Tuesday, 10 May 2016 at 13:40:30 UTC, Chris wrote:
On Monday, 9 May 2016 at 19:09:35 UTC, Joe Duarte wrote:
[snip]
Let me give you a sense of the sorts of issues I'm thinking of. Here is a C sample from ProgrammingSimplified.com. It finds the frequency of characters in a string:

int main()
{
   char string[100];
   int c = 0, count[26] = {0};

   printf("Enter a string\n");
   gets(string);

   while (string[c] != '\0')
   {
      /** Considering characters from 'a' to 'z' only
          and ignoring others */

      if (string[c] >= 'a' && string[c] <= 'z')
         count[string[c]-'a']++;

      c++;
   }

   for (c = 0; c < 26; c++)
   {
      /** Printing only those characters
          whose count is at least 1 */

      if (count[c] != 0)
printf("%c occurs %d times in the entered string.\n",c+'a',count[c]);
   }

   return 0;
}

[snap]

I went to www.programmingsimplified.com/c-program-examples and found that this was example 48 out of 59. The examples start with:

- Hello world
- Print Integer
- Addition
- Odd or Even
- Add, subtract, multiply and divide
- Check vowel
- Leap year
- Add digits
- [...]

and so on, with increasing complexity.

Nobody starts with examples like the one above. More likely with number 1 in their list:

#include <stdio.h>

int main()
{
  printf("Hello world\n");
  return 0;
}

Not so difficult to understand.


You're arguing that the 32-line example on finding characters frequency in a string was too complicated? I think it might help to clarify my purpose in that post. It was to pick a random example of a simple C program to illustrate the sorts of problems programming syntax has from a cognitive science and pedagogical standpoint. For my purposes, I didn't need to choose a 6-line program, and something that short would probably undermine my ability to illustrate some things.

Note also that I saw myself as being a bit *charitable* to C by choosing that sample. For instance, I didn't use an example littered with the word "void". Void in English most commonly means invalid, canceled, or not binding, as in a voided check, a void contract (such as where one party is a minor), and "null and void" is a common usage, so starting a function declaration by declaring it void is jarring. There was a discussion that Walter linked to from the late 1980s I believe, where people were requesting that this issue be fixed in C (Walter linked to it as background on the naming of D I think). It's a hole in the type system and bad syntax -- I predict that it adds confusion to learning a language that uses it.

Something I've wondered is if foreigners actually have an easier time with the syntax of English programming languages. The jarring usage of terms like void, or things like dollar signs and question marks to not mark dollars or questions, might not be jarring to non-native English speakers, or non-English speakers. For them, all this might just be arbitrary tokens and they'd just have to learn what the tokens signify (and it's very interesting to think about how they and English speakers learn this). Andreas Stefik did some research where he used a randomly generated programming syntax, I think it was called Randomo, and some mainstream languages were just as hard to learn as the randomly generated one (Java or C, I think -- they're both pretty bad anyway). To non-English speakers, and especially non-Latin-alphabet-users, all of our programming languages might be randomly generated for all intents and purposes.

You gave a Hello World example above. Don't get me started on Hello World. Well, too late... Here's the deal. It's not just Hello World -- a ton of programming examples in online references and introductory texts, perhaps most of them, present programs that are pointless. By "pointless" I mean they do no useful work. Commonly, they repeat something back to us. So here we're typing 64-ish characters into a console or something in order to have the computer repeat back an 11-character string to us. If we have to type "Hello World" (and a bunch of other stuff) in order for the computer to display it, well we've not had a productive interaction.

I think examples should quickly illustrate computers computing or otherwise doing productive things for us. Displaying a string in a console environment is also too far removed from normal computing environments like a smartphone or Windows 10/MacOS graphical desktop. If we're going to teach displaying a pop-up message, we should cut right to a windowing environment from the outset.

I think the Hello World example is also extremely confusing to newbies and rational knowers. It's not clear why the main function has an integer type, since we're not doing anything with integers, why there is an empty set of parentheses after it (what are they doing there?), why we're saying "printf" when we don't want to use our printer, why there's a newline code *inside the quotes*, why we are "returning" 0, and what that even means, and of course why there are curly braces just sitting there on otherwise blank lines. We just wanted to display "Hello World", not deal with all this other stuff.

Reply via email to