Live data from Hacker News

LINQ Ruined My Favorite Interview Question

scottchamberlin.tumblr.com

131–140 of 218 posts

Re: LINQ Ruined My Favorite Interview Question

#131
post #116

Earlier quoted context omitted.

(Note: When I say LINQ I am referring to the functional style it encourages, not the query syntax. The query syntax is nice, but it's just a trivial syntactic transformation.) Correct me if I'm wrong, but the world is moving towards functional programming (i.e. LINQ) not away from it. Personally, I find LINQ far, far easier to read, write, and analyze. (On the other hand, I understand the deferred semantics and watch…

I'm definitely in agreement with the last point. However, I originally said that good C# code contains a lot of LINQ, not that C# code with a lot of LINQ is necessarily good. Deferred execution is something that confuses people, but frankly, it's a concept they need to learn. It's been in the language since yield return got added in 2.0. LINQ's deferred execution was the right choice for performance, but it's the har…

Don't forget about Memoize(). Often it can be a better choice than ToList().

Re: LINQ Ruined My Favorite Interview Question

#132
post #4

LINQ tends to get thought of as "database syntax sugar", but it's way more than that. It's C#'s version of the lazy collection operations you find in most functional languages, just given friendlier sqlish names. (IE, "Select" instead of "map" and "Where" instead of "filter") I almost feel a bit gross when I have to write a "foreach" loop at this point, because there's almost always an equivalent way to do it in LINQ…

>It's C#'s version of the lazy collection operations you find in most functional languages, just given friendlier sqlish names. (IE, "Select" instead of "map" and "Where" instead of "filter")

Actually........

It's more generic than that. It's C#'s monadic comprehension syntax ala Scala's for and Haskell's Do.

It works on more than just IEnumerable, it actually works on anything that implements Select, SelectMany, and Where...

Re: LINQ Ruined My Favorite Interview Question

#133
post #13

I hate to be the arrogant know it all on Hacker News, but seriously, if you're writing c# and not using LINQ all the time, you need to catch up. I'm tired of seeing people answer interview questions with anything _other_ than LINQ.

I answered a phone interview question once with LINQ -- it was about combining string arrays while avoiding duplicates. The HR interviewer followed up my answer asking about runtime and memory usage. While these are good questions, I got the feeling they didn't want to receive an answer using a single line of LINQ.

Do you know the runtime and memory usage of a LINQ query? That's sort of a complication of LINQ.

Re: LINQ Ruined My Favorite Interview Question

#134
post #17
post #4

LINQ tends to get thought of as "database syntax sugar", but it's way more than that. It's C#'s version of the lazy collection operations you find in most functional languages, just given friendlier sqlish names. (IE, "Select" instead of "map" and "Where" instead of "filter") I almost feel a bit gross when I have to write a "foreach" loop at this point, because there's almost always an equivalent way to do it in LINQ…

I almost feel a bit gross when I have to write a "foreach" loop at this point Agreed. I've transitioned to spending most of my time in JS, and wherever I can I use .map(), but the chaining it's not quite the same as LINQ. Someday I intend to write a library of Array addons to provide GroupBy and so on, but I can't imagine it'll be super efficient.

In Underscore, you can do something like:

    _([ ... ]).map( ... ).filter( ... ).value()
It's not exactly extending the native array...but there are far fewer side effects to doing it this way.

Re: LINQ Ruined My Favorite Interview Question

#135
post #8

I hate to be the bearer of bad news, but I think there may be even simpler solutions to this problem: (take 10 (reverse (sort-by (comp first rest) (frequencies (string/split ... #"\+s")))) The above is a Clojure one-liner example that I believe satisfies the original problem. So while LINQ may have simplified from the C-language family solutions he had seen, it's clearly possible to take it one step further with the…

expressivity of modern languages like Clojure Uh, no. Your solution just uses a bunch of standard library functions (at least, I hope they're not syntactic forms… and why a function as specific as "frequencies" not in some namespace boggles my mind). I could write that in C with an appropriate standard library. Ironically, expressing this in something like SQL actually speaks to the expressivity of the language becau…

Ironically, expressing this in something like SQL actually speaks to the expressivity of the language because the solution was produced entirely with syntactic forms.

What? Pure untyped lambda calculus does things "only with syntactic forms". Don't tell me that your solution wouldn't use some basic operators other than rudimentary syntax. Keep in mind that in Lisp-family languages, many things that are a part of syntax in other languages are actually simple functions - arithmetic operations being a case in point - so you really can't avoid using library functions.

I believe that the major point of Clojure etc. is that they provide concise basic operations that you can use everywhere to compose complex operations better than you can do with, say, C#.

Re: LINQ Ruined My Favorite Interview Question

#136

Earlier quoted context omitted.

"Sorry, we're stuck with Python 2.3.7 and collections isn't part of the standard library."

"""Thank you, I think I've heard enough. I don't think continuing the interview would be a productive use of time."""

Because of an older version of python?!

Re: LINQ Ruined My Favorite Interview Question

#137
post #116

Earlier quoted context omitted.

(Note: When I say LINQ I am referring to the functional style it encourages, not the query syntax. The query syntax is nice, but it's just a trivial syntactic transformation.) Correct me if I'm wrong, but the world is moving towards functional programming (i.e. LINQ) not away from it. Personally, I find LINQ far, far easier to read, write, and analyze. (On the other hand, I understand the deferred semantics and watch…

I'm definitely in agreement with the last point. However, I originally said that good C# code contains a lot of LINQ, not that C# code with a lot of LINQ is necessarily good. Deferred execution is something that confuses people, but frankly, it's a concept they need to learn. It's been in the language since yield return got added in 2.0. LINQ's deferred execution was the right choice for performance, but it's the har…

In particular, a query like the one in the original blog post will evaluate multiple intermediate lists that then need to be thrown away.

Why not fuse the operations, if the values are immutable?

Re: LINQ Ruined My Favorite Interview Question

#138
post #105
post #8

I hate to be the bearer of bad news, but I think there may be even simpler solutions to this problem: (take 10 (reverse (sort-by (comp first rest) (frequencies (string/split ... #"\+s")))) The above is a Clojure one-liner example that I believe satisfies the original problem. So while LINQ may have simplified from the C-language family solutions he had seen, it's clearly possible to take it one step further with the…

For a sys-admin job: tr 'a-z' 'A-Z' | sed 's/[^A-Z][^A-Z]*/\ /g' | grep -v '^$' | sort | uniq -c | sort -nrk1 | head -10 edit: I don't know enough about HN,there should be a newline after the backslash in the sed command.

This is too complicated...

echo $sentence | rs -T | sort | uniq -c | sort -rn|head -10

Re: LINQ Ruined My Favorite Interview Question

#139
post #136

Earlier quoted context omitted.

"""Thank you, I think I've heard enough. I don't think continuing the interview would be a productive use of time."""

Because of an older version of python?!

If they're stuck on a version of software that hasn't been supported in 5 years for bugs or security with a set of features that was originally released nearly 10 years ago, it means that there are some culture issues in the workplace that will most likely drive me insane.

Therefore, I am unlikely to take the job.

Post reply on HN