On Aug 1, 5:15 am, Peter Michaux wrote:
> On Jul 31, 4:43 pm, Richard Cornford wrote:
> [snip]
>
>> But then I am very cynical.
>
> At least you know! 
>
>> I have the problem of setting javascript technical tests for
>> interviews (not that often, but it is part of my job), so from
>> time to time I think about what questions they should include,
>> and what I would be looking for in an answer.
>
> Given your apparent high standards and opinion of the general
> quality of JavaScript programmers, how do these employee
> searches go for you?
It is not an easy process. If you advertise of expertise you still get a
large proportion of people applying who don't even know the basics (or,
what I would consider to be the basics).
It seems to be a common problem.
> Do you simply take the best applicant or do you wait for a
> satisfactory applicant?
The potential for extreme and long term harm that can follow form
employing the wrong person is such that nobody gets in unless they
really can do the job, or clearly show the potential to learn the job
very quickly. The "best applicant" is rarely that person.
>> For example, as a verbal question I would tend to ask;
>> "which side of an inequality expression is evaluated first?" Not
>> because I want to be told the answer (I would not memorise that
>> sort of detail (after all, it does not matter 99.9% of the time),
>> and it would scare me to encounter someone who did), but because
>> I would want to hear "I would have to look it up" (or words to that
>> effect), so I could ask where they would look it up, and if given
>> the correct answer hand them a copy of the document to see if they
>> were familiar enough with it (and interpreting it) to give me the
>> correct answer quickly.
>
> If I was feeling bold and relatively happy with my current
> job, I would answer that my code should not depend on
> knowledge of which side is evaluated first.
That would not necessarily be a bad answer, if you could come up with
something well-reasoned when asked to justify that position.
> That is information that likely anyone would have
> to look up and results in code that is not quickly read
> or easily maintained.
Consider:-
SomeObject.prototype.setState = function(newState){
if(this.state != (this.state = newState)){
// some other code
this.whenStateChanged();
}
};
Is that really difficult to understand? You don't even need to know
which side of the inequality operation is evaluated first in order to
read it, as if it is right hand side first the whole - if - expression
is doomed to always be false and there is no point in having it there at
all. On the other hand, if you were writing this construct it is very
important to get it the right way around, and as we are agreed that
nobody is going to memorise this level of detail it becomes important to
be able to find out the order of evaluation, and preferably find out
with certainty and quickly (less than 30 seconds).
>> On the other hand there are things I would expect someone to know
>> (without having to look it up), and one of those is Identifier
>> resolution against the scope chain.
>
>> "Inspired" by one of the more ambiguous questions on your meebo.com
>> page I thought the following might make quite interesting written
>> test questions, and give an impression of my thought process in
>> setting javascript questions:-
>
>> /* unknown global code */
>> function outerFunction(){
>> /* unknown outer function body code */
>> function innerFunction(){
>> /* unknown inner function body code */
>> with(anObjectReference){
>> x = 5; //<--- The subject line of code.
>> }
>> /* more unknown inner function body code */
>> }
>> /* more unknown outer function body code */}
>
>> /* more unknown global code */
>
>> /* ************************************************** ******\
>> | Note: Three facts about the 'unknown' code:- |
>> | |
>> | 1. There are no more function definitions, no function |
>> | expressions and no uses of the Function constructor. |
>> | 2. There are no - with - statements in the unknown code.|
>> | 3. There are no uses of the - eval - function. |
>> \************************************************* ******* */
>
> David Mark posted nice answers. I really enjoyed this as an exercise.
> I too have never used "with".
>
> I agree with David's sentiment about using "with" as a
> weeding technique during the interview process. I think
> good JavaScript programmers likely don't use the "with"
> statement because it is hard to maintain, prone to creating
> properties in the wrong place and cannot be optimized (well?)
> by the compiler.
And I think a good javascript programmer knows why we don't use the -
with - statement. That is, knows why the results are "hard to maintain,
prone to creating properties in the wrong place", and for that they need
to know what it does (which is no more than place an object on the top
of the scope chain).
> These warnings about "with" are plastered all over the place
But being "plastered all over the place" is hardly any indicator of
truth when it comes to javascript. After all, how often do you read the
assertion that nobody should use closures because closures cause memory
leaks on IE, which is an overly extreme reaction following form a
misrepresentation of the facts. If people read things "plastered all
over the place" they really should be looking to the explanations of why
and how (with critical judgment), and so know what - with - does without
any need actually use it.
> and a good JavaScript programmer my have never bothered to use
> "with" before.
"May have never bothered" or 'may have never chosen to use (or always
chosen not to use)'? A "good javascript programmer" will be making
informed decisions about what they use, why they use it, and what they
don't use and why they don't use it.
> The places where I have encountered "with" have been in code
> that otherwise had horrendously bad JavaScript and was written
> by programmers for whom I've come to have low respect for many
> reasons.
But does that mean you have an excuse for not knowing what - with -
does? What if you had to debug/fix/correct code of that type (code that
is likely be in need of ongoing work by virtue of the quality of its
authoring), you would have to understand it, even if you would never
write it.
> If you ever feel like posting other interesting exercises please do!
Of course I will post what I feel like, whenever I feel like it.
Richard.