Code through the looking glass
-
One of my RSS bloggers Ayende Rahien has recently organized a series of coding interviews for a job at his company (they make a .NET based NoSQL database RavenDB). He asked candidates to write a tool that parses a large-ish CSV file and searches the content based on email address. One of the candidates was so bad, it deserved a series of blog posts cataloging his many screwups.
- Finding today's log file
- All you need is a dictionary (and O(N) )
- I'm the God of all OOP
- Sorting large data sets
- And a linear search to rule them
Representative sample:
The intent is basically that you'll read the file and load that into a dictionary, then use that to perform queries.
This candidate has done just that, although things started being strange pretty much from the get goโฆ
...Dictionary<int, string> emails = new Dictionary<int, string>(); //... public Dictionary<int, int> EmailSearcher(string email) { Dictionary<int, int> answer = new Dictionary<int, int>(); int count = 0; foreach (var entry in emails) { if (entry.Value.ToString().Equals(email, StringComparison.OrdinalIgnoreCase)) { answer.Add(count, entry.Key); count++; } } return answer; }
-
-
We interrupt your regularly scheduled ry about code quality to report a Duckhorse sighting outside of WTDWTF:
DUCKHORSE!
And now back to your regularly scheduled thread.
-
@cartman82 This is why algorithms and data structures are taught in school: not for the likes of you and I, who could generally figure it out, but for the likes of this guy.
-
@Yamikuronue Some of the more complex algorithms aren't simple to figure out, but that's why we have libraries and we know that when we need the big algorithmic guns, we look up how to deal with them. The idiot from the article seriesโฆ he doesn't need to be taught so much as put somewhere well away from computers where he won't cause any damage.
Or he could work on SSDS. That would be an appropriate use of his skills. After all, he's already mastered going forwards through the data!
-
Just don't read it with a non-maximized browser window ....
-
@Luhmann
E_NO_REPRO
-
@Onyx
Did you try by making your browser window 3px smaller?
-
@Luhmann Made it as small as it would let me. No dice.
-
@Luhmann WOMM, Firefox on Windows 7
Edit: Reducing the width and height while expanding the sidebar does make it screwy
-
@Jaloopa
Exactly, if the bar to the left is expanded and you reduce the browser height it foomps
-
I expected it be some whiny complaints about slightly suboptimal code to create the data structure for the lines from the CSV file.
Instead, I got a giant . Well done, sir.
-
@Dragnslcr It's the wildly inappropriate use of data structures that just makes me go โโ. It's just so hard to understand what questions the guy thought he was trying to answer with those information associations.
-
Reading "Sorting large data sets" and looking at
UnifyIdLists()
you just feel the helplessness. When I write code like that it's a sign I haven't found a good frame of reference to express a solution. This code isn't bad because it doesn't work, nor because it's slow. It's bad for not knowing how to use the tools. One is left with evidence that the author of the code does not understand how dictionaries work or how they are employed.Of course I had the privilege of being taught Data Structures at university. And also the privilege of being smug enough to try and read Okasakis book so when it comes to dictionaries I have good footing.
-
@dkf Yeah, the dictionary with integer keys that are just a sequence of 0..n is pretty special. It makes me wonder if the person has ever heard the terms "array" or "list".
-
My favorite part is where he goes to the trouble of sorting the keys (does it wrong and expensively, but that was the intent), and then searches linearly.
-
That's a really interesting series of posts, that echoes a discussion I was having with one of my colleagues earlier today.
We have a developer who can produce good, clean, safe code but he just can't do it right - like the candidate on the blog, he gets there in the end but through the most tortuous possible route.Unfortunately, we've come to the conclusion that we can't teach this guy to do this better (can't as in a] we're not teachers and b] we can't afford to).
-
@gleemonk said in Code through the looking glass:
Of course I had the privilege of being taught Data Structures at university.
I've interviewed developers before.
That means jack shit.
-
@skotl said in Code through the looking glass:
We have a developer who can produce good, clean, safe code but he just can't do it right - like the candidate on the blog, he gets there in the end but through the most tortuous possible route.
How can code be "good" and "clean" if it's also tortuous? Or do you mean he starts with a mess and eventually refactors to something sane?
-
@Kian said in Code through the looking glass:
How can code be "good" and "clean" if it's also tortuous? Or do you mean he starts with a mess and eventually refactors to something sane?
Good as in compiles and (technically) works, clean as in contains relevant comments and doesn't spellar things wrong.
Torturous because it is anti-optimized (though to be fair, pre-optimization can be just as torturous) and potentially literally tortures the machine running the code.
-
@blakeyrat said in Code through the looking glass:
That means jack shit.
It depends on whether they bothered to turn up to class and listen (or to do all the assigned work, including the optional bits and background reading1). The lazy fuckers think they're optimizing their life, but they're just not learning stuff and wasting their time and money.
1That's actually harder than going to class, but some people learn better that way.
-
@dkf said in Code through the looking glass:
It depends on whether they bothered to turn up to class and listen
Meh. Personally, I don't learn while listening. At all. I have to read about and/or play around with stuff to memorize it. What has always worked best for me in uni was reading the slides and sometimes the referenced books and summarizing them in my own words.
-
@asdf said in Code through the looking glass:
Personally, I don't learn while listening. At all.
I see you also didn't read the next part of what I wrote. Good job there. Carry on!
-
@Tsaukpaetra said in Code through the looking glass:
Good as in compiles and (technically) works,
We seem to have different definitions of "good". As far as I'm concerned, "code" that doesn't compile is just gibberish. Code that doesn't fulfill its function is not even bad, it's just wrong. There's no point in grading it, because it has to be rewritten anyway until it works. To be able to say that code is bad, it has to at the very least "technically work".
Once you get there, I'd classify code which is anti-optimized (performing a linear search over data you know to be sorted) as bad, code that does the obvious thing as regular (doing a binary search over data you know to be sorted), and code that manages to be optimized and readable as good (using a hashmap instead, when it has been measured and shown to be better, without sacrificing readability).
Note I don't claim to always write good code myself. I'm happy if I manage consistently regular code.
-
@dkf I did, but it doesn't apply to me either: I never did the assigned work (unless forced to), I did whatever I thought would be interesting to try out. ;)
-
@Kian said in Code through the looking glass:
@skotl said in Code through the looking glass:
We have a developer who can produce good, clean, safe code but he just can't do it right - like the candidate on the blog, he gets there in the end but through the most tortuous possible route.
How can code be "good" and "clean" if it's also tortuous? Or do you mean he starts with a mess and eventually refactors to something sane?
As @Tsaukpaetra says (how do you get multiple quotes in response?) it compiles and, technically, it's decent code. But as the OP highlights, it sets about trying to solve the problem in the wrong way. I'm not going to try to explain it; the OP points us at Ayende's posts and they explain it better than I ever could.
Long story short, this is a guy who could turn out code exactly to the specification that you or I put in front of him, but he can't come up with that specification himself. To get all scrumalicious, he also doesn't grasp the concept of done in terms of unit tests, automation, etc.
-
@skotl said in Code through the looking glass:
he can't come up with that specification himself
People like that, when given freedom, tend to generate code that is plain insane. It might look OK, but the logic is just from Planet Strange in the WTF Galaxy.
-
@skotl said in Code through the looking glass:
it compiles
@skotl said in Code through the looking glass:
how do you get multiple quotes in response
Like this? After you've selected text and hit Reply, put the cursor where you want it, and select another block of text and hit reply again.
-
@FrostCat said in Code through the looking glass:
@skotl said in Code through the looking glass:
it compiles
@skotl said in Code through the looking glass:
how do you get multiple quotes in response
Like this? After you've selected text and hit Reply, put the cursor where you want it, and select another block of text and hit reply again.
I have to have to be the one to ask this. How do you do on mobile? I can't seem to dismiss the composer without destroying my Draft.
-
@swayde said in Code through the looking glass:
How do you do on mobile?
Sorry, I don't know. I don't like to read forums on mobile.
-
@swayde well, I don't, because right now I can't even get the post editor to open on my iPhone. But when I was, it had a glitch (I'm assuming) where if I hid the keyboard, the editor didn't leap up to monopolize the entire viewing area like it wants to do. So that was a workaround.
-
@swayde said in Code through the looking glass:
I have to have to be the one to ask this. How do you do on mobile?
Make the screen 3 pixels wider
-
@swayde said in Code through the looking glass:
How do you do on mobile?
Ah, now that's the correct question!
Realistically, it's PITA. But, if you'reinsanestubborn enough to actually do it, it involves the following:- Make your first part of the quoted reply.
- Select all the text in the composer, and cut it into the clipboard.
- Dismis the composer (Yes, you're sure you want to discard this post).
- Select-
quoteReply again, but before typing, sniggle your cursor to the beginning and paste the clipboard at the top. - Repeat 0 through 0 until your post is composed.
- Pray you didn't mess up the formatting.
-
@Tsaukpaetra Even Discourse made mobile work better than that.
-
@loopback0 said in Code through the looking glass:
Even Discourse made mobile work better than that.
Not arguing against that. I've said (alongside a few of our more vocal members) that the Composer should have a lot of tender love and care put into it, but currently that's not a focus so much.
I just provide technically viable workarounds until it's fixed.
-
@Kian said in Code through the looking glass:
@skotl said in Code through the looking glass:
We have a developer who can produce good, clean, safe code but he just can't do it right - like the candidate on the blog, he gets there in the end but through the most tortuous possible route.
How can code be "good" and "clean" if it's also tortuous? Or do you mean he starts with a mess and eventually refactors to something sane?
That sounds like how I work because at the start, I will be handed vague requirements/specifications so I'll just hack sparingly and see if the stuff is actually what is wanted by the PM, then I will start refactoring into better structures.
-
@WPT Do mock-ups instead. The problem with refactoring after something's working is that it's much harder to sell people on "It works, but it's terrible, give me another week to redo it". They'll want to test and ship asap.
-
@Yamikuronue You must understand that from the places that I have worked in, they do not appreciate mock-ups. They would rather ship a broken pieces of prototypes then preparing a mock-up. So, I have gotten used to taking the extra time and effort to treat every prototype as though I am creating the real thing, which is why I mentioned sparingly, allowing my structures to be adaptable to changes and refactoring bits and pieces at the start of each week to keep the technical debt down.