News for hackers. Stuff that matters.
Re:Why it’s hard for programmers to write a program to flatt... by brudgers on Friday February 24, 2017 @11:24AM (#13725014)
One of the problems is that for Java the task is underspecified: Flatten a list of what? Sure this one is integers, is that always the case or should the list take <object>?

Leaving out that information from the question is going to disorient novices who in a high stress situation at the short end of an asymmetrical relationship. I suppose if the interviewer lets them Google, then it is a fair test (and objectively, not Googling before writing code is probably the best criterion for failing miserably).

What the question really measures is how lucky the candidate was in their education. If they were taught in Racket rather than Java:

  (flatten '((1) ((2 3 ((4) (5 6)))))
and if they were taught the JVM rather than Java

  (flatten [[1] [[2 3 [[4] [5 6]]]]]
and with J

  flatten =: [: ; <S:0
I'd bet that the interviewer would not know if it was wrong or right. Which is the same issue of open endedness that the candidate faces.
Re:Why it’s hard for programmers to write a program to flatt... by klibertp on Friday February 24, 2017 @11:37AM (#13725155)
> is going to disorient novices who in a high stress situation at the short end of an asymmetrical relationship.

> What the question really measures is how lucky the candidate was in their education.

Yes! Exactly! This is the other point I wanted to make[1], thanks for doing it for me :)

> flatten =: [: ; <S:0

Nice, I was playing with J quite a lot but somehow missed the spread word (for the curious: http://code.jsoftware.com/wiki/Vocabulary/scapco)

[1] In my comment here: https://news.ycombinator.com/item?id=13725095

Re:Why it’s hard for programmers to write a program to flatt... by brudgers on Friday February 24, 2017 @11:43AM (#13725230)
I played with J and have it loaded on an old Android phone...but I copy pasted the code from Rosetta Code after Googling 'flatten a list in Java' which is where I became aware of the <object> issue {racket I knew and clojure I suspected}.
Re:Why it’s hard for programmers to write a program to flatt... by dragonwriter on Friday February 24, 2017 @12:40PM (#13725747)
> One of the problems is that for Java the task is underspecified: Flatten a list of what? Sure this one is integers, is that always the case or should the list take <object>?

Well, I don't Java much, but I think that even if the result List is just integers, the source list has to be (invalid syntax) List<Integer | List<Integer>>, which is somewhat problematic to type as anything but List<Object> given Java's lack of sum types.

Re:Why it’s hard for programmers to write a program to flatt... by bushin on Friday February 24, 2017 @01:02PM (#13725950)
More precisely List<Integer | List<Integer | List <Integer | List<Integer | ...> :) That would be trivial in functional languages.
Re:Why it’s hard for programmers to write a program to flatt... by dragonwriter on Friday February 24, 2017 @02:00PM (#13726554)
It would be trivial in languages with sum types and support for recursive signatures/constructors, which doesn't describe all statically-types functional languages. And there's no reason such a language would have to be functional, though most are.
Re:Why it’s hard for programmers to write a program to flatt... by dllthomas on Friday February 24, 2017 @02:32PM (#13726898)
Interfaces are (open) sum types. Or close enough for government work.
Re:Why it’s hard for programmers to write a program to flatt... by dragonwriter on Friday February 24, 2017 @02:39PM (#13726985)
Yes, but Java (unless I missed a recent change) doesn't let you assign new interfaces to existing types, so short of either wrapping Lists and Ints in containers implementing a common interface and demanding that the input be in the wrapped form, that doesn't actually help.
Re:Why it’s hard for programmers to write a program to flatt... by dllthomas on Friday February 24, 2017 @02:48PM (#13727090)
Faced with this problem, I would precisely wrap Lists and Ints in containers implementing a common interface and demand that the input be in that form (actually, the input is text right? so I'd parse it into that form - assuming I couldn't get away with just manipulating the textual representation).

Note that in the genuine sum-type case you're wrapping, too.

Re:Why it’s hard for programmers to write a program to flatt... by contravariant on Friday February 24, 2017 @01:01PM (#13725944)
I suppose a fair counter question would be how on earth the interviewer ended up with a couple of nested heterogeneous lists in Java, instead of a simple Tree data structure.
Re:Why it’s hard for programmers to write a program to flatt... by dllthomas on Friday February 24, 2017 @02:59PM (#13727238)
If you look at the actual, original question it was presumably a textual serialization of a simple data structure.