Live data from Hacker News

Interview gone wrong

ashu1461.com

141–150 of 209 posts

Re: Interview gone wrong

#141
post #105

Earlier quoted context omitted.

There are problems I have encountered a billion times and of course I have an elegant concise solution for it, if I am an experienced programmer. if any([a in ["-h", "--help"] for a in args]): display_help() Would be one of those. Generally I learned that it can be beneficial to treat things as lists early on, e.g. if you have a program that takes one input file it costs you next to nothing to allow the input to be m…

That still looks like something that a novice might trip over when reading this. Just describing what it does is already a bit convoluted: it tests whether any value of a list of booleans, produced by a generator expression by testing membership of a value in some other list, is True. I would have gone with the following, as it requires less mental unpacking: if set(args) & set(["-h", "--help"]): display_help() Also,…

on my phone and a bit discombobulated today, so we’ll see how i go with this

> That still looks like something that a novice might trip over when reading this.

my experience with “juniors” who start with python is that they think in lists and dictionaries. they don’t think in terms of set theory. that’s just the way python is taught.

i would definitely set interview questions where a “decent” solution involves using sets and see who gets it without iterating over lists (ha, setting an interview question on sets… geddit? i’ll see myself out).

> Just describing what it does is already a bit convoluted

yeah, but python only/main “juniors” primarily think in terms of lists, see above.

so, between making sure all juniors can read the code versus doing it succinctly, but juniors all need to learn about sets — practicality wins out quite often.

> I would have gone with the following, as it requires less mental unpacking:

> if set(args) & set(["-h", "--help"]):

> display_help()

if i were reviewing this code i’d ask you to switch it to

    if set(args).intersection(set(["-h", "--help"])):
it is more verbose and more brackets, but it is more explicit and obvious what is happening to some junior who has never dealt with sets before (hmm what’s an intersection? should probably google it)

& is also used for the bitwise AND operator. plus some other stuff in various frameworks like django. so could lead to some confusion.

> Also, note that any() works with any iterable, the outer brackets are not needed given the list expression.

i generally HATE the overuse of generator expressions in python. everyone writes absolutely everything as an inline generator expression, making it hard to test.

but, rant aside, yes, this is probably the one i would pick during a review (likely after a discussion about how using the intersection method makes things less legible and then this gets suggested somewhere).

people don’t realise not every genexp needs to be a list. easy mistake to make with the “everything is a list or a dict” mental model.

Re: Interview gone wrong

#142

Stopped judging candidates on "style" due to stuff like this. I only comment if the code doesn't work, if it works i don't really bother to correct code style or provide feedback on it. 45 minutes interviews aren't really the place to evaluate this.

Linters are for this.

You need to detect if someone is humble and smart enough to fit in to how you do things as a team, whatever that is.

Not reject someone for not hitting a style guide on a piece of paper tucked behind a hidden secret door. (As I was once!)

Re: Interview gone wrong

#143
post #132

python was pleasant in the python 2 days. Now there's so many confusing ways to do one simple thing. and one thing Golang has made inroads is there's only one way to do something. and ruby is pleasurable because the interface is consistent i.e everything is an object.

What does the feature discussed in TFA (chained comparisons) have to do with Python 2 vs Python now.

As another commenter pointed out [0] this feature existed since 1.4 [1].

Also, I don't understand why so many people seem to be so confused/surprised by it. I can't be 100% sure because it was a long time ago, but I think that a lot of tutorials/introductory articles mention it. Like, "Hey, did you know that Python has this cool syntaxic sugar for this thing? Fascinating!". I think that I learned about chained comparisons long before I wrote my first line of Python.

[0] https://news.ycombinator.com/item?id=42038451

[1] https://docs.python.org/release/1.4/tut/node40.html#SECTION0...

Re: Interview gone wrong

#144
post #115

Worth to keep in mind that python first appeared in 1991 and predates even Java, JavaScript, PHP, Ruby

And the nerve to put Javascript as the example about how equality should work, a language known for: 0 == '' evaluates to True 0 == '0' evaluates to True false == 'false' evaluates to False false == '0' evaluates to True ' \t\r\n ' == 0 evaluates to True and the === operator you need to overcome the above. I don't have anything against JS and I understand why it is done that way, but if some language has weird and co…

It is merely syntatically confusing.

Make == be ~~ or .fuzzyCompare()

And === be ==

And you are fixed.

Re: Interview gone wrong

#145
post #91
post #14

Earlier quoted context omitted.

I suspect the interviewer would have likely been fine if they’d been able to explain chained comparisons and how they work. I would probably consider the interviewer using them without understanding them to be a negative signal.

It is possible that the candidate would normally use it from muscle memory, but got confused under the stress of the interview.

Fair enough. In general, I think the interview is a pretty lousy way to measure how good a software developer is.

Re: Interview gone wrong

#147
post #11
post #2

Any time you use language specific tricks in an interview, you’re probably going to confuse your interviewer and not do well.

I disagree: if you are demonstrating your mastery of a language (and with Python, these things are important: using appropriate syntax is the difference between dog slow code and fast code), you should use idiomatic patterns like the above. Another of Python features is a great REPL: when unsure or confused by an interviewer, I'd just fire python from shell and type in 'x' == 'x' == 'x' to confirm and demonstrate it…

This is my opinion as well, but unfortunately isn’t always held by others. I once interviewed and by dint of knowing Python’s itertools module, absolutely destroyed the interviewer’s questions that they clearly thought would take some time to do.

I was told later that while I “obviously knew Python quite well, it didn’t give a good signal for my capabilities.”

Re: Interview gone wrong

#148
post #135
post #122

Earlier quoted context omitted.

Yet another way in which Lisp is vastly superior to any and all blub languages: (= 2 (+ 1 1) (sqrt 4)) ; => t ( t

I have no idea what this does or if you are joking. Could use some explanation

In Lisp, you put the "operator" first, so instead of

  2 + 3 + 4
you write

  (+ 2 3 4)

This is nice for associative operations like + or *, very very very slightly confusing for - and /

---

You use the same style for comparisons, so instead of

  2 == 3 == 4
you write

  (== 2 3 4)

To support the fist "infix" syntax, you need some magic in the == operator. But the second "prefix" syntax is totally natural and you need no magic in the parser or the operator.

Re: Interview gone wrong

#149
post #125

Earlier quoted context omitted.

> the symbol it is using is overloaded with binary comparison operator, so the people will be confused I think most people would expect expressions like `5 < x < 10` to work as they do in math, without necessarily thinking about it in terms of being an overloaded binary operator. The result in other languages that `5 < 12 < 10` = `true < 10` = `true` is more surprising, just that we've (perhaps by being bitten by it…

Yeah, but should that math equivalence hold for programming though? Programming is different. x=x+1 is perfectly legal in programming but does not make sense in algebra math and could confuse mathematicians.

> should that math equivalence hold for programming though?

It's not a hard rule that overrides all other considerations, but I do think Python's choice to follow math is the right decision here.

I'd claim if you teach someone `It's also just pretty useful. It's common to want to check if a number is between some bounds, like `0 <= i < len`, or that multiple things are equal. In cases where you really do want the C behavior, I'd say you should already write that as `(x == y) == z` for clarity anyway, regardless of whether the language lacks chaining and thus lets you omit the parentheses.

Re: Interview gone wrong

#150
post #115

Worth to keep in mind that python first appeared in 1991 and predates even Java, JavaScript, PHP, Ruby

And the nerve to put Javascript as the example about how equality should work, a language known for: 0 == '' evaluates to True 0 == '0' evaluates to True false == 'false' evaluates to False false == '0' evaluates to True ' \t\r\n ' == 0 evaluates to True and the === operator you need to overcome the above. I don't have anything against JS and I understand why it is done that way, but if some language has weird and co…

"Test two values for equality, but this time we mean it."
Post reply on HN