Live data from Hacker News

Why it’s hard for programmers to write a program to flatten a list?

shekhargulati.com

41–50 of 128 posts

Re: Why it’s hard for programmers to write a program to flatten a list?

#41
post #8

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…

But...but Python is starting to become a Programming 101 language, and Python is awesome :( :(

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 flatten a list?

#42
post #2

I'm a retired data architect and C developer with 36 years of professional experience. In my opinion, this is not how you find an appropriate candidate. It would be better to ask substantive questions that are related to the thing you are making. What does this person bring to the team? How will the team receive this person? Has this person delivered something of substance in the recent past that would convince you t…

Sounds to me like that's a really god way to hire people who are really good at bullshitting.

The absolute hardest thing about hiring developers is hiring people who I can trust to write code. Most applicants are just not adequate programmers and any other redeeming qualities they have can't overcome that core deficiency. I need people who can look at different ways to solve a problem, implement an approach that makes sense, and explain why it does. I need code reviews to be about architecture decisions and correctness not lessons on how to write code. If someone can't do that I really don't care how well they can sell themselves as an "asset".

Re: Why it’s hard for programmers to write a program to flatten a list?

#43

Earlier quoted context omitted.

It does not really test potential because a junior trained in Java has poor tools for flattening a list because idiomatic Java would not represent hierarchical data structure as a nested list. Idiomatic Java would use tree and node objects. Idiomatic Java also prefers arrays over lists for sequential data. An experienced programmer might look at the problem and choose a better tool: a different language or call a ser…

Idiomatic Java hasn't preferred Arrays since the advent of the Collections API back in 1.2. Idiomatic Java as of 1.8 now has flatMap on Streams, which all Collection implementations provide.

I don't disagree. I was thinking about how Java is typically taught in computer science contexts where Fortran in any language is not uncommon because that context seemed the relevant one to nest inside the context of junior programmers using Java.

One of the difficulties of learning Java is that because it has been around so long, old idioms live on on the internet. For example, the Java examples of flatteing a list (which I recently looked at) do not include flatmapping a stream. It does not surprise me that it is there since I believe Java is an incredible and sophisticated language.

Re: Why it’s hard for programmers to write a program to flatten a list?

#44
post #23

Earlier quoted context omitted.

> An experienced programmer might look at the problem and choose a better tool: a different language Come on, you are not going to call Haskell or Python to flatten a list in your Java. > or call a service I know we have "micro" services now, but really? Sending serialized data to ListFlatteningService to get deserialized FlattenedList? > or rewrite the offending code Something may produce it because it makes sense i…

I make no claim to being a good programmer or having high potential (of any sort but the wasted), just the ability to occasionaly mimic those who are. Charged with flattening lists, I'd write my Java in Clojure. (flatten [1 [[2] [[3 4] [5 [6]]]]]) as much of it as I could because it would be less work and easier to read and maintain and debug. Since nested Java lists are isomorphic with trees, there's more than one w…

Aren't list-of-lists more like trees where values are only stored on the leaves? In this case, aren't {pre,in,post}order all the same?

Re: Why it’s hard for programmers to write a program to flatten a list?

#45
post #23

Earlier quoted context omitted.

> An experienced programmer might look at the problem and choose a better tool: a different language Come on, you are not going to call Haskell or Python to flatten a list in your Java. > or call a service I know we have "micro" services now, but really? Sending serialized data to ListFlatteningService to get deserialized FlattenedList? > or rewrite the offending code Something may produce it because it makes sense i…

I make no claim to being a good programmer or having high potential (of any sort but the wasted), just the ability to occasionaly mimic those who are. Charged with flattening lists, I'd write my Java in Clojure. (flatten [1 [[2] [[3 4] [5 [6]]]]]) as much of it as I could because it would be less work and easier to read and maintain and debug. Since nested Java lists are isomorphic with trees, there's more than one w…

Sorry, are you suggesting that "flatten a list" leads to microservices?

Re: Why it’s hard for programmers to write a program to flatten a list?

#47
post #2

I'm a retired data architect and C developer with 36 years of professional experience. In my opinion, this is not how you find an appropriate candidate. It would be better to ask substantive questions that are related to the thing you are making. What does this person bring to the team? How will the team receive this person? Has this person delivered something of substance in the recent past that would convince you t…

yes its a very artificial Q a better one might be how would you use a computer to measure how efficient 100 different toilets are :-)

Re: Why it’s hard for programmers to write a program to flatten a list?

#49
I don't really write Java, but I fail to see any easy and robust way to assign a type to the flatten function in Java.

Is this the signature you would expect in a solution to this?

    List flatten(List)
Or something like

    List flatten(NestedList)
with a definition for NestedList?

Is there even a way to define something like NestedList without coercing back and forth from Object? Is there a way you can do this so that you don't have to basically reimplement List?

Re: Why it’s hard for programmers to write a program to flatten a list?

#50
The fact that "int or list of int" isn't sanely representable in any concise way in the mainstream OO languages is a sign that perhaps this isn't a great example problem for a Java interview.

Obviously you can do this with brute forcing the sum type with some class hierarchy (ugh) or make the algorithm accept some List or Java "List" interface.

Both of those options are pretty terrible.

I think the intents of the question are good - see if the candidates understand the importance of naming, signature, tests.

There has to be a question that does this and doesn't immediately have the subject crying over the type system.

Post reply on HN