News for hackers. Stuff that matters.
Re:Dear HN "Who's Hiring" responders by ig1 on Monday April 01, 2013 @08:20PM (#5476886)
I'm not familiar with that stat but it's perfectly believable. Many people are clearly getting by with a mixture of memorization and trial-and-error rather than understanding.

I think of those who understand algorithmic reasoning (i.e. understand loops, assignment, etc.) they also fall into two categories. Those who can understand more abstract programming concepts (indirect referencing, recursion) and those who can't - you can definitely still be a good programer without understanding those but it will limit the areas you can work in.

Re:Dear HN "Who's Hiring" responders by uniclaude on Monday April 01, 2013 @10:49PM (#5477388)
I might have interviewed a very different subset of the programming world than you, but I wouldn't make the categorization in this way.

Indeed, I haven't met any programmer who couldn't understand recursion when explained in clear terms, same goes for indirect referencing.

If I had to divide the programmers who really understand algorithmic reasoning into two categories, those would be

- A: those who program because it's their job,

- B: those who program because it's their passion.

I believe this grouping is more helpful to explain differences.

Re:Dear HN "Who's Hiring" responders by ig1 on Tuesday April 02, 2013 @05:10AM (#5478334)
It's a relatively well studied area of programming pedagogy, numerous studies have shown students struggle with those concepts:

https://student.brighton.ac.uk/mod_docs/cmis/past%20papers/c...

Re:Dear HN "Who's Hiring" responders by uniclaude on Tuesday April 02, 2013 @07:49AM (#5478732)
Thank you for the link.

You wrote students, while I meant professional programmers. It's not because some people have a tougher time learning those things (whatever the reason can be) that they have no change to get them by the moment they are active professionals.

This said, if I tried to apply your grouping to the people I have been interviewing last year, I would have approximately 100% of them in one category, hence my comment.

Re:Dear HN "Who's Hiring" responders by lsiebert on Monday April 01, 2013 @11:17PM (#5477498)
Recursion isn't hard, it's just not taught correctly. It's fairly easy to break it down into rules.

Because they are shown examples, instead of taught how, people memorize how to do stuff, instead of learning it from principles.

Take the classic question, recursively reverse a linked list.

You will see a lot of people making false starts, or trying to reverse the list in some way like they would reverse an array, or even repeatedly walking the list to the end.

But if you understand some simple rules about recursion, it's fairly easy to figure out how to do this on the fly. And that is so much better then memorization, because you can explain why you are doing things.

first you are reversing, so you're moving backward, which means you calls your function, then do assignments. If you were doing something moving forwards, like printing in order, you'd print first, then call the function.

Now we need to worry about the end, and the beginning.

First, the beginning, which happens after we have recursively walked the list.

Now, we want to walk to the last node before null, and we need a place to store what we return. so assuming we have something like this in c 'node * recursivereverse(node * current)' and a node structure with next as the next link (we never touch our data)

our test is if (current->next) node * newbeginning = recursivereverse(current->next); else return current; //some assignments go here;

return newbeginning;

Then we just need to figure out the assignments.

Now, people may get tripped up and try to use the new beginning... but then they have to walk it to the end... but the current node already knows the node that comes after it.

so we assign current->next->next = current; IE the node that was previously after the current node now points to the current node as it's next. And that's fine for all the rest of the list, until we get to our original beginning node. We need to worry about the new end.

Since it's going to the end, we need to point it to NULL, otherwise it will point to it's predecessor, meaning we'll have an infinite loop at the end of the last two nodes.

Easy way to deal with it is to just assign the next of the current node to NULL, for each node.

so we add to current->next->next = current; current->next = NULL;

and then you have a reversed linked list. This makes certain assumptions about the list (like it has at least one node, and isn't circular), so don't just copy this for your interview.

So with some simple rules, I figured out how to reverse a linked list. But those simple rules aren't taught, or at least, I came up with them for myself after I became a computer science tutor at my college, because I needed people to understand recursion.

So I guess my point is, it's not that people can or can't understand recursion, it's whether they are taught to think about things in the right way.

Now to a certain extent, we need to teach people to generalize, but if you teach people a general rule (always worry about the beginning and end of any data structure, and that's important for everything, including memory management and debugging) and a recursion specific rule (call the function first to reverse, call the function after to use the current order), and they can generalize.

Too often people come to program with the ability to copy code and get it working (and that isn't anything to denigrate, because it's not simple), but lack the understanding of how to think about things in a deeper way.

Re:Dear HN "Who's Hiring" responders by lifebeyondfife on Tuesday April 02, 2013 @09:57AM (#5479261)
Because it was lunchtime and I wanted to make sure I was still employable...

static MyLinkedList<T> ReverseLinkedList<T>(MyLinkedList<T> linkedList) { if (linkedList.Next == null) return linkedList;

  var newTail = linkedList.Next;
  var reversedList = ReverseLinkedList(linkedList.Next);
  newTail.Next = linkedList;
  linkedList.Next = null;

  return reversedList;
}
Re:Dear HN "Who's Hiring" responders by infinite8s on Tuesday April 02, 2013 @08:50AM (#5478937)
Agreed about recursion being taught the wrong way. Recursion is implicitly fundamental to learning basic arithmetic (what is 5? it's just (1 + (1 + (1 + (1 + (1 + 0))))). Reasoning by induction is just recursion. I think children have a recursive intuition for counting (at least from watching my 3 year old) that quickly gets squashed when they start learning 'math' in school.
Re:Dear HN "Who's Hiring" responders by thisone on Tuesday April 02, 2013 @04:55PM (#5482017)
I've always thought of reversing a linked list in a visual way.

In my mind, a link list is a bunch of nodes with arrows pointing right. To reverse the list, all I need to do is point the arrows to the left.

6(ish) lines of code later, and I've got a recursive reverse method.

Re:Dear HN "Who's Hiring" responders by Maven911 on Tuesday April 02, 2013 @01:16AM (#5477813)
Replying so that i can go back to this and understand it one day
Re:Dear HN "Who's Hiring" responders by lsiebert on Tuesday April 02, 2013 @01:34AM (#5477852)
Mark, when you come back to this, this might be helpful for you. https://github.com/gryftir/recursivereverse
Re:Dear HN "Who's Hiring" responders by koide on Tuesday April 02, 2013 @04:21AM (#5478238)
Thanks! Sorry for asking this, but why the strange (to me) indent?
Re:Dear HN "Who's Hiring" responders by jpgvm on Tuesday April 02, 2013 @05:30AM (#5478362)
8 spaces?

Probably because this is similar to the Linux kernel programming style. Many of us learnt C from the kernel or projects that follow it's coding style.

Re:Dear HN "Who's Hiring" responders by lsiebert on Tuesday April 02, 2013 @05:56AM (#5478416)
Assuming you mean the code on github, I use tabs for indentation in vim, but have tabstop and setwidth set to 2. So if the code has 8 spaces, that is github or the browser. Feel free to make a pull request, or I can try to fix it (though I am kinda focused on my portfolio for internship applications atm). Should be a simple regex though.
Re:Dear HN "Who's Hiring" responders by mst on Tuesday April 02, 2013 @08:13AM (#5478808)

  perl -pi -e 's/^(\t+)/"  " x length($1)/e' recurse.c
seems to do the trick; vary the number of spaces inside the "" to taste.