Answering a code test like a literature pop quiz
We get some… fascinating replies from candidates to our code tests. Some of them are so bad that I really wish that I could revoke some people’s keyboard access:
Case in point, we had a promising candidate from Israel’s equivalent of MIT (Technion, which is in the top 25 engineering schools in the world).
He submitted code that went something like this:
var nameFirstChar = char.Parse(name.Substring(0,1).ToLower()); switch (nameFirstChar) { case 'a': using (StreamWriter indexFile = new StreamWriter(Path.Combine(basePath, "Name_IndeX_A.csv"), true)) { indexFile.WriteLine(name); } break; case 'b': using (StreamWriter indexFile = new StreamWriter(Path.Combine(basePath, "Name_IndeX_B.csv"), true)) { indexFile.WriteLine(name); } break; // ... // you can guess :-( // ... case 'y': using (StreamWriter indexFile = new StreamWriter(Path.Combine(basePath, "Name_IndeX_Y.csv"), true)) { indexFile.WriteLine(name); } break; case 'z': using (StreamWriter indexFile = new StreamWriter(Path.Combine(basePath, "Name_IndeX_Z.csv"), true)) { indexFile.WriteLine(name); } break; }
And yes, he had the full A-Z there. This was part of a 1475 lines methods. And no, he didn’t handle all the cases for Unicode.
Yes, he just graduated, but some things are expected. Like knowing about loops.
Comments
Sometimes many switch case giving faster performance than if/else. in this case I don't see the reason why he did that. however, as a technion graduate, I'm sure there are many other good candidates out there.
Uri,
I don't think if/else would have been an acceptable answer either.
Loops? I'm quite curious how you would use loop to solve that (instead of some string.Format) :)
I'm not sure either whatfor you would use a loop in this scenario. I would construct the file name using the nameFirstChar and then write to that file.
AG, Assuming you wanted what he did:
for(char ch = 'a'; ch < 'z'; ch++) { // code for character }
Oren, maybe you have more context which we don't see but wouldn't that do:
var nameFirstChar = char.Parse(name.Substring(0,1).ToUpper()); var fileName = string.Format("Name_IndeX_{0}.csv", nameFirstChar); using (StreamWriter indexFile = new StreamWriter(Path.Combine(basePath, fileName), true)) { indexFile.WriteLine(name); }
so no loop.
AG, Yes, I'm sorry. The code above this is actually doing a loop, and I was caught on that
:-)
Maybe he is thinking about security and avoiding tricks like "....\windows\cmd.exe". Never use the user submitted data in your program unless it is checked.
Moreover he is only accepting chars a..z and not something like '*' or '?'
The above program is one of the "cases" where you might skip BREAK and just case 'a': case 'b': case 'c': .. case 'z': do_something;
if your task is solving the problem by using a case-statement :-)
The interesting question here to me is one of predicting aptitude. The programmer presumably found a working solution which demonstrates more programming aptitude than maybe half of the general population. But the skill missing here is the ability to apply something along the lines of elementary algebraic substitution usually taught in secondary school (https://en.wikipedia.org/wiki/Elementary_algebra#Substitution).
Most likely this programmer knew there was a better way (isn't there always?) but lacks the basic skills needed to find it.
Wes, That is pretty much the point. A college graduate from the best tech school in the country should really HAVE the skills to get it
Revoking keyboard access would be a bit harsh. Give feedback so he can improve.
(And I'm sure this code would fit right in at a larger company... ;)
All letters capital and small ... !!! ??
Wow, such a cool and smart guy to call people out like this. Dick.
How typical a result is this? He seems much better than some of the graduates I've encountered, at least he got a working answer.
What do you think of teaching programming in trade schools rather than uni?
Did he have a good score on his degree?
But isn't these kind of code test results pretty common among university coders who have no real world experience and are simple mindedly trying to solve a problem with only performance in mind.
Captain Kappa, No, it isn't. We have had literally dozens of tests from people with that level of experience. We have very rarely seen stuff like that. The method in question was 1,300 lines of code, just to give you some scope
so, from the top 25 and down, all schools are crap
Comment preview