News for hackers. Stuff that matters.
Re:Why it’s hard for programmers to write a program to flatt... by klibertp on Friday February 24, 2017 @10:17AM (#13724358)
The word "Java" really should be in the title.

Whatever else you say about it, Java is one of the entry-level languages. It's no wonder there are many entry-level programmers among its users. It's obviously a trade-off, as you get that many more candidates to choose from, compared to for example OCaml, Clojure or Erlang programmers. On the other hand, a percentage of people who can flatten a list is greater in users of the more "advanced" languages.

If you want to have a good signal to noise ratio: avoid languages used in "Programming 101" like a plague and languages which are currently fashionable. This way you'll get candidates who learned the language by themselves, in most cases after learning and mastering their previous language.

Becoming a programmer is a long process. Depending on the person, the time required to learn a single programming language may be shorter than the time needed to really master all the essential programming skills. Which I think explains why there is a correlation between good programmers and people who know more than one programming language.

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.
Re:Why it’s hard for programmers to write a program to flatt... by cableshaft on Friday February 24, 2017 @11:30AM (#13725067)
But...but Python is starting to become a Programming 101 language, and Python is awesome :( :(
Re:Why it’s hard for programmers to write a program to flatt... by maxander on Friday February 24, 2017 @02:01PM (#13726567)
The coming glut of Python devs is going to be a problem. Its an excellent language, I've used it for work for years, but its almost too powerful. A minimally skilled programmer can write mostly-functional Python programs while still not having the slightest notion of what they're doing, meaning the pressure for a developer to understand and improve their craft is often minimal.

If I were responsible for hiring developers into a Python post, I would only consider candidates to could show (ideally substantial) work in some other, strongly-typed, lower-level language. It hardly even matters if they haven't seen Python, a decent developer can become a useful Python programmer in a few hours. Python experience does not teach or demonstrate a decent understanding of software structure.

Re:Why it’s hard for programmers to write a program to flatt... by collyw on Friday February 24, 2017 @02:22PM (#13726768)
I have seen a fair bit of Python code in the style of Java (as well as some completely unreadable Python). Just because you can be useful in Python doesn't mean you are writing good idiomatic Python code. And if you aren't doing that, then what is the point in using Python?
Re:Why it’s hard for programmers to write a program to flatt... by cableshaft on Friday February 24, 2017 @02:56PM (#13727196)
To be fair, I probably still have a bit of C-stink in my python code. I don't know the idiomatic way to do everything, and I don't try to put everything into list comprehensions by default, but I still think it's an excellent, and fast, language, and have been using it for many years.