Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I've come to believe that it is the cognitive dissonance between the programmer and the machine. The language used often obscures what is actually executed. Often we find this useful but without proper cues we can write programs that make the divide between program and process really wide.

Personally I find declarations about properties, relationships, and categories of things easier to understand than descriptions of the tedious processes that calculate them. The former give me the ability to reason about the program elements in a logical way. The latter requires me to become a stack machine and execute the program in my head... a process that is error-prone and full of false assumptions.

eg: how many people believe that "all arrays are just pointers," in C? When is an array not like a pointer?

Research like this is good. Are there any studies that go beyond trying to trick programmers with trivial programs in the Algol family and look at the difference in performance between categorically different styles? I mean languages that are declarative vs imperative vs functional vs concatenative in nature. I think that would be very interesting to read.

updated for clarity



> eg: how many people believe that "all arrays are just pointers," in C? When is an array not like a pointer?

Ok I know this wasn't your point but I got stuck on this and am just curious to know: what you were thinking of here? One thing that occurs to me is that in a recursive function you will run out of stack space a lot faster if you are using arrays rather than allocating from the heap. I don't think that is what you were referring to though, hence the question.


Well my example was meant to support how programming languages can create a cognitive dissonance between what the programmer thinks will be executed vs. what is actually executed.

One area where I think there is a high dissonance is in how C uses the same syntax for defining arrays, indexing into arrays, and referencing pointer offsets. Other examples are the array decomposition rules, array function parameters, etc. Even experienced programmers get tripped up by them:

http://c-faq.com/~scs/cgi-bin/faqcat.cgi?sec=aryptr


If you're asking about differences between pointers and arrays, one example is:

  int a[10] = { 7 };
  int* p = a;
  
  assert(a[0] == p[0]);
  assert(sizeof(a) == sizeof(p)); // FAILS




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: