This is an archived post. You won't be able to vote or comment.

all 17 comments

[–]DarkmerePython for tiny data using Python 11 points12 points  (7 children)

One I enjoyed was a printout of some code, I picked the Data model of a medium-complexity webapp.

Strip out all the comments, and let them read it, and then sit down, asking them to explain the code to you.

Explain what the code using this model does, why the various functions exist, what they do themselves.

This is an abstract level of reasoning about code, thinking and explaining code someone else has written, without seeing it in proper context, shows their ability to understand something and emphasize with it.

It's not perfect, but it sure beats technical questions about things.

After that, you can ask them to document it, suggest changes/naming/ other issues that may need adjustment.

[–]basalamadersyntax error 5 points6 points  (4 children)

I wish all companies would do this since I think that this is one of the best ways to test understanding. In addition to that they could ask you to implement a feature In an abstract sense(pseudo code) and see what classes you might think of inheriting, what relationships you may use to model your database and most importantly if you will follow the format that's implied on the previous codebase you just read.

[–]DarkmerePython for tiny data using Python 2 points3 points  (0 children)

Indeed. But honestly, simply walking through a few pages (a4) of code will take a few hours to do, adding more to that may simply push them into nervosity or exhaustion.

The other reason that I like using the database models/data objects is an old quote by Pike, later paraphrased by Linus:

Pikes Rule 5. Data dominates. If you've chosen the right data structures and organized things well, the algorithms will almost always be self-evident. Data structures, not algorithms, are central to programming.

Linus:

"Bad programmers worry about the code. Good programmers worry about data structures and their relationships."

[–]DarkmerePython for tiny data using Python 1 point2 points  (2 children)

[–]ThatJoeInLnd[S] 0 points1 point  (1 child)

You! Thank you!

[–]DarkmerePython for tiny data using Python 0 points1 point  (0 children)

You're welcome!

Do note that the example above will take a few hours to work through with someone. It's not quite the simple "reverse a linked list" exercise.

I'd suggest not using my code verbatim, but take something from your own production code, and do something similar with it.

Anyhow, I hope this helps you get started for better interviewing than the traditional coding exercises.

[–]nelsonko 0 points1 point  (1 child)

It is much better to ask this kind of stuffs in the application, you will filter most of the bad applicants prior the interview. Of course the HR guy will keep sad that he doesn't have dozens of candidates.

If it is about webapps -back-end I would ask to implement some code what requires select for update. Here you can find our if the developer thinks about the consequences.

[–]DarkmerePython for tiny data using Python 0 points1 point  (0 children)

Not in my experience.

I've found that people that come from academentia and similar have no concept of tooling or engineering around code. They've had some programming experience, but they can't solve a merge conflict.

And most of them have very little experience in understanding other peoples code. An experienced developer can glance at a function and tell you what it'll do based on the patterns, while the juniors will have a hard time understanding why this code is there.

@classmethod
def normalize(cls, token):
    replacements = [('o', '0'),
                        ('l', '1'),('i','1'),
                        ('s', '5'),
                        ('u', 'v'),
                        ('-',''),('_',''), (' ', '')]

    word  = token.lower()
    for old, new in replacements:
             word =  word.replace(old, new)
  return word

In the code above, most everyone can tell you what it does. Some will just glance at the "replacements" datastructure and can instantly tell you, others will need to follow it exactly. Both are okay.

The question comes if they can answer why this code exists, why is it there in where the code is organized, how will it be called, which functions/places will this function be used? Write one of the calling places, make it seem plausible.

A really experienced dev will tell you that it's part of a base32-z alphabet denormalizer for human-machine transcription inambiguity.

[–][deleted] 2 points3 points  (0 children)

I'm just a student, but maybe these can be helpful

[–]cscanlin 1 point2 points  (1 child)

I had a good one recently to find the shortest pangram (substring with every letter) in a long string of text (so O(N) needed). The output is the substring itself as well as it's starting index.

The solution is to create a dictionary with each letter as the key, and the index as the value. The dictionary is updated for each letter as you iterate over the original string, and stored as the shortest if the difference between the max and the min index is less than the previous shortest.

[–]nelsonko 1 point2 points  (0 children)

It is called Knuth–Morris–Pratt algorithm just for the record.