﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>SEO commented on Code twisters: The functional loop</title><description>The purpose of interview questions is this: i want a view into how the candidate thinks and solves problems in a pressure situation.
  
  
In that vain, this question is useful from the perspective of how a candidate deals with things like pointless questions or a fool in a 'management' role. Does he/she stay composed?
</description><link>http://ayende.com/4498/code-twisters-the-functional-loop#comment24</link><guid>http://ayende.com/4498/code-twisters-the-functional-loop#comment24</guid><pubDate>Mon, 21 Jun 2010 07:55:12 GMT</pubDate></item><item><title>Bunter commented on Code twisters: The functional loop</title><description>I would 
  
  
Func
&lt;int,&gt;
 nextLevel = new Func
&lt;int,&gt;
(x =&gt; x - 1);
  
  
and have no issues with increment/decrement precedence.
</description><link>http://ayende.com/4498/code-twisters-the-functional-loop#comment23</link><guid>http://ayende.com/4498/code-twisters-the-functional-loop#comment23</guid><pubDate>Sat, 15 May 2010 21:06:48 GMT</pubDate></item><item><title>Andy commented on Code twisters: The functional loop</title><description>11 times ?
</description><link>http://ayende.com/4498/code-twisters-the-functional-loop#comment22</link><guid>http://ayende.com/4498/code-twisters-the-functional-loop#comment22</guid><pubDate>Fri, 14 May 2010 01:12:10 GMT</pubDate></item><item><title>IObtuse commented on Code twisters: The functional loop</title><description>The purpose of interview questions is this: i want a view into how the candidate thinks and solves problems in a pressure situation.  
  
  
In that vain, this question is useful from the perspective of how a candidate deals with things like pointless questions or a fool in a 'management' role.  Does he/she stay composed?
  
  
 As a candidate I respect problems like the counterfeit coin, anagrams, etc as they are implicitly respecting me in asking them. Questions like these throw the bozo bit on the employer and raises more red flags than it clears.  
</description><link>http://ayende.com/4498/code-twisters-the-functional-loop#comment21</link><guid>http://ayende.com/4498/code-twisters-the-functional-loop#comment21</guid><pubDate>Thu, 13 May 2010 18:34:36 GMT</pubDate></item><item><title>Dathan commented on Code twisters: The functional loop</title><description>To me, ALL interview questions are valid.  Whether or not they're GOOD questions has less to do with the question than with how the interviewer uses the answer.  In this example, if the interviewer's simply trying to gauge level of factual knowledge, and you get a plus for right and a minus for wrong, then it's a bad question.  On the other hand, if the interviewer is using the question to evaluate the developer's thinking processes, it's a perfectly valid question.  
  
  
Now consider - if that's what the interviewer is doing, everyone who says "You're never going to see that in production code, so it's a terrible question, and you're just prejudicing the interview process against anyone who's never done C" is totally off-base: the candidate who's never done C is AT AN ADVANTAGE, because he gets to show off his thought processes, and the interviewer will be able to accurately evaluate the candidate's problem-solving process.  A developer who's got the entire language down cold, though, will just spit out the answer, and will have to sit through another (and maybe another, and another) question before the interviewer can get the information he wants.
  
  
Don't discard questions out of hand because you THINK you know the way in which the interviewer is going to use them.  Just because the question strikes you as contrived, artificial, or pointless, doesn't mean it really is - the interviewer may just be doing more than you give him credit for.
</description><link>http://ayende.com/4498/code-twisters-the-functional-loop#comment20</link><guid>http://ayende.com/4498/code-twisters-the-functional-loop#comment20</guid><pubDate>Thu, 13 May 2010 18:05:24 GMT</pubDate></item><item><title>configurator commented on Code twisters: The functional loop</title><description>I think the more appropriate interview question would be: This code causes an infinite loop. Why?
</description><link>http://ayende.com/4498/code-twisters-the-functional-loop#comment19</link><guid>http://ayende.com/4498/code-twisters-the-functional-loop#comment19</guid><pubDate>Thu, 13 May 2010 17:41:50 GMT</pubDate></item><item><title>zvolkov commented on Code twisters: The functional loop</title><description>Damn, my comment got flagged as spam :) I just wanted to say: this is how Ayende will stop being Ayende eventually. By embarrassing himself to the point of not making his bold opinions public anymore.
</description><link>http://ayende.com/4498/code-twisters-the-functional-loop#comment18</link><guid>http://ayende.com/4498/code-twisters-the-functional-loop#comment18</guid><pubDate>Thu, 13 May 2010 17:21:28 GMT</pubDate></item><item><title>Jason Y commented on Code twisters: The functional loop</title><description>I agree that this is a bad question if it is strictly to see how good of a language lawyer the candidate is.  However, I can see it being useful for watching how someone goes about solving a problem as Bryan pointed out.
</description><link>http://ayende.com/4498/code-twisters-the-functional-loop#comment17</link><guid>http://ayende.com/4498/code-twisters-the-functional-loop#comment17</guid><pubDate>Thu, 13 May 2010 15:31:05 GMT</pubDate></item><item><title>apalmer commented on Code twisters: The functional loop</title><description>Horrible interview question...
  
  
Its the kind of thing that will catch 90% of developers out there  on the spot, but 90% of the people who got caught would find it within 1 minute with a debugger running, if it came up at work in real life. Plus the whole x--, --x thing is left over from the C/C++ days it really serves no purpose in C# code compared to the much simpler x += 1 construct..
  
  
 So it filters out people with something that is totally outside of real world usuage, that would easily be resolved in the real world, without testing their true understanding.
</description><link>http://ayende.com/4498/code-twisters-the-functional-loop#comment16</link><guid>http://ayende.com/4498/code-twisters-the-functional-loop#comment16</guid><pubDate>Thu, 13 May 2010 14:33:54 GMT</pubDate></item><item><title>Bryan commented on Code twisters: The functional loop</title><description>@Jonty
  
  
IMO the reason this is a good interview question is when you hire a new person, you are going to have them maintaining a bunch of code that they didn't write, and that there is a good chance that they would "have done it differently". That's how this works. So, when the developer is confronted with code that they aren't familiar with, how do they work through the code, and figure out what it does. Do they have critical thinking, and reasoning skills. They don't have to get it right, the goal isn't to see if they get it right, but rather to watch how they reason, and talk through it.
  
  
Obviously a unit test, or the debugger could get the answer, and it's good to use tools to solve the problems efficiently, but as developers, we are problem solvers, and you want to exercise those skills in an interview as well as the candidates technical skills.
</description><link>http://ayende.com/4498/code-twisters-the-functional-loop#comment15</link><guid>http://ayende.com/4498/code-twisters-the-functional-loop#comment15</guid><pubDate>Thu, 13 May 2010 14:19:26 GMT</pubDate></item><item><title>Pointless Code commented on Code twisters: The functional loop</title><description>I think this is a classic case of unreadable code dressed up as clever code. What's the point?
</description><link>http://ayende.com/4498/code-twisters-the-functional-loop#comment14</link><guid>http://ayende.com/4498/code-twisters-the-functional-loop#comment14</guid><pubDate>Thu, 13 May 2010 12:19:25 GMT</pubDate></item><item><title>Jonty commented on Code twisters: The functional loop</title><description>I don't think it would make a good interview question. Good interview questions aren't about catching people out. A good developer might be caught out by some code, but would have unit tests that aren't.
</description><link>http://ayende.com/4498/code-twisters-the-functional-loop#comment13</link><guid>http://ayende.com/4498/code-twisters-the-functional-loop#comment13</guid><pubDate>Thu, 13 May 2010 11:39:48 GMT</pubDate></item><item><title>AlonE commented on Code twisters: The functional loop</title><description>Resharper actually identifies it as a redundant decrement...
</description><link>http://ayende.com/4498/code-twisters-the-functional-loop#comment12</link><guid>http://ayende.com/4498/code-twisters-the-functional-loop#comment12</guid><pubDate>Thu, 13 May 2010 11:28:41 GMT</pubDate></item><item><title>configurator commented on Code twisters: The functional loop</title><description>x =&gt; x-1 would also work. It's the return value that matters, not the decrement.
</description><link>http://ayende.com/4498/code-twisters-the-functional-loop#comment11</link><guid>http://ayende.com/4498/code-twisters-the-functional-loop#comment11</guid><pubDate>Thu, 13 May 2010 10:53:13 GMT</pubDate></item><item><title>Jason Y commented on Code twisters: The functional loop</title><description>Whoops!  Didn't see that level is set to what the lambda expression evaluates to.
  
  
Ditto what others said about --x vs. x--.
</description><link>http://ayende.com/4498/code-twisters-the-functional-loop#comment10</link><guid>http://ayende.com/4498/code-twisters-the-functional-loop#comment10</guid><pubDate>Thu, 13 May 2010 10:33:51 GMT</pubDate></item><item><title>Jason Y commented on Code twisters: The functional loop</title><description>I expect that lambda bodies, like bodies of other methods, use _copies of_ the arguments passed in (copies of value-type arguments or of references, but not copies of objects), so running nextLevel(level) has no side effects outside of itself--i.e., it decrements its local copy of level (x), not level itself.  So Rafal is right.
</description><link>http://ayende.com/4498/code-twisters-the-functional-loop#comment9</link><guid>http://ayende.com/4498/code-twisters-the-functional-loop#comment9</guid><pubDate>Thu, 13 May 2010 10:30:34 GMT</pubDate></item><item><title>Petar Petrov commented on Code twisters: The functional loop</title><description>Infinite. If you change the nextLevel func to Func
&lt;int,&gt;
 nextLevel = new Func
&lt;int,&gt;
(x =&gt; --x);
  
  
			var x = 10;
  
  
			x = x++;
  
  
			Console.WriteLine(x);
  
what will be printed ? ;)
  
[weblogs.asp.net/.../..._2B002B00_-and-C_2300_.aspx](http://weblogs.asp.net/kennykerr/archive/2006/03/29/Increment-differences-in-C_2B002B00_-and-C_2300_.aspx)  
</description><link>http://ayende.com/4498/code-twisters-the-functional-loop#comment8</link><guid>http://ayende.com/4498/code-twisters-the-functional-loop#comment8</guid><pubDate>Thu, 13 May 2010 09:23:37 GMT</pubDate></item><item><title>yew commented on Code twisters: The functional loop</title><description>infinite...  should be --x instead of x--
</description><link>http://ayende.com/4498/code-twisters-the-functional-loop#comment7</link><guid>http://ayende.com/4498/code-twisters-the-functional-loop#comment7</guid><pubDate>Thu, 13 May 2010 09:17:25 GMT</pubDate></item><item><title>rvin100 commented on Code twisters: The functional loop</title><description>It will be an infinite loop !
  
  
Unless you define nextLevel this way :
  
  
Func&lt;int, int&gt; nextLevel = new Func&lt;int, int&gt;(x =&gt; --x);
  
  
nextLevel will always return level...
</description><link>http://ayende.com/4498/code-twisters-the-functional-loop#comment6</link><guid>http://ayende.com/4498/code-twisters-the-functional-loop#comment6</guid><pubDate>Thu, 13 May 2010 09:16:47 GMT</pubDate></item><item><title>Roma commented on Code twisters: The functional loop</title><description>x--
</description><link>http://ayende.com/4498/code-twisters-the-functional-loop#comment5</link><guid>http://ayende.com/4498/code-twisters-the-functional-loop#comment5</guid><pubDate>Thu, 13 May 2010 09:16:34 GMT</pubDate></item><item><title>Kons commented on Code twisters: The functional loop</title><description>--x should do the trick.
</description><link>http://ayende.com/4498/code-twisters-the-functional-loop#comment4</link><guid>http://ayende.com/4498/code-twisters-the-functional-loop#comment4</guid><pubDate>Thu, 13 May 2010 09:15:04 GMT</pubDate></item><item><title>David a r Kemp commented on Code twisters: The functional loop</title><description>Shame this took so long to crack - should have got this straight off from my C++ days.
  
</description><link>http://ayende.com/4498/code-twisters-the-functional-loop#comment3</link><guid>http://ayende.com/4498/code-twisters-the-functional-loop#comment3</guid><pubDate>Thu, 13 May 2010 09:14:59 GMT</pubDate></item><item><title>Phil Murphy commented on Code twisters: The functional loop</title><description>Infinitely, because the use of "x--" returns the value of x *before* decrementing x (locally), and hence nextLevel( n ) always returns the original value of n?
</description><link>http://ayende.com/4498/code-twisters-the-functional-loop#comment2</link><guid>http://ayende.com/4498/code-twisters-the-functional-loop#comment2</guid><pubDate>Thu, 13 May 2010 09:14:35 GMT</pubDate></item><item><title>Rafal commented on Code twisters: The functional loop</title><description>infinite?
</description><link>http://ayende.com/4498/code-twisters-the-functional-loop#comment1</link><guid>http://ayende.com/4498/code-twisters-the-functional-loop#comment1</guid><pubDate>Thu, 13 May 2010 09:12:40 GMT</pubDate></item></channel></rss>