In the near future, I again have to attend to finding a workplace, in connection with which I recall my dramatic employment experience and read about interviews for a programmer position. In particular,
Aleksey Kolupayev ’s article
“A simple question at an interview or how not to get into startups” made me
depressed .
The author positions himself as an unconditional expert in the selection of programmer personnel, illustrating this by analyzing the real and hypothetical answers to one task given to them at the interviews: create a PHP script that rearranges the characters in an arbitrary line in reverse order. At the end he writes:
“ I assure you - using this task (and, of course, many others), I have never seriously made a mistake with the candidate. After all, the formal knowledge of PHP in the candidate - believe me, far from the main thing. Much more important is the attitude to his work, the desire for development, the ability to play as a team, the vision of the world, if you like. I find it much more interesting how a person solves a problem than its actual solution . ”
')
It is paradoxical that the approach demonstrated by him corresponds to this promise with the exact opposite. The hierarchy of answers built by him - from the worst to the most valuable, is in fact the exact opposite of the true one, and I am going to show it.
So, the author formulates the problem as follows:
<?php
$a = 'abcdefgh';
// ,
//
// $a,
echo $a;
?>
— «» , , , , , :
$a='hgfedcba';
! . « » (What you want is what you get), «-», , ! , «
— ! …».
, :
« - „ , “. „ , “. , , ».
, ! , «
Microsoft» , «». :
«, , „“. , — PHP, …».
, , , , . . , , . —
. ? ? . , ! ™ ! (, -, ), , - , , , ( , , ) , , «
».
« „ PHP …“. , , , PHP . , , . . , , ? ».
- PHP — . , , ,
— . , , DOM-,
, ! , , Javascript.
, - («
, - »), , , , , PHP . ( . UTF-8 ; . ! ,
, . , (!) , mb- , . , -, .)
$b = '';
for ($i = strlen($a)-1; $i>=0; $i--)
$b .= $a[$i];
$a = $b;
«
, ». ,
( ). , , , ? «
»? «
». «
» :
$b = '';
$l = strlen($a)-1;
for ($i = 0; $i < $l/2; $i++) {
$b = $a[$i];
$a[$i] = $a[$l-$i];
$a[$l-$i] = $b;
}
, , :
$char, $half_length, $char_counter
, . - « », ( «
, , » ). , . ,
.
, —
, (, ) «
».
, - ( ), — , , , - . , , — !
, .
, (, , , , , , , ) «
», — «
… , - - - » (-!):
$l = strlen($a)-1;
for ($i = 0; $i < $l/2; $i++) {
$a[$i] = $a[$l-$i]^$a[$i];
$a[$l-$i] = $a[$l-$i]^$a[$i];
$a[$i] = $a[$l-$i]^$a[$i];
}
? ,
( , - , ,—
,— ).
, , , ( «») , . , , «
, ». , , «» .
: Jedi suxx, Sith rules…