25 points · by formulathree · 3y ago · 85 comments
Here's an example of a recent one:
https://github.com/anonanonme/takehome-sample
takehome instructions: https://github.com/anonanonme/takehome-sample/blob/master/README.md
takehome readme: https://github.com/anonanonme/takehome-sample/blob/master/documentation.md
Can anyone provide some legit criticism? Or is the person evaluating this just being unreasonable?
The chance you will get ghosted? Very high.
The four hours could be better spent.. you are more likely to get a response by cold emailing other companies.
Send them open source work and ask them to judge your ability/style based on that. If they are not interested they were never going to judge your submission based om your style / abilities and the four (8) hours can be better spent.
This is my anecdote, you can take it for what it's worth.
Even if they are serious, and you ask questions after the take-home then find out they don’t believe in version control and testing, you still wasted your time!
I've never failed a take-home round and I've never been ghosted.
Again, this is my personal experience.
When using them I find you need to keep your wits about you. Some are sharks. Always confirm whether or not they are putting you forward for something being the main thing. I have been put forward for roles without knowing then got unstuck because 2 agents put me forward for the same role.
There was even one company that was clearly not a culture fit; I think the HR was a little racist, based on the tone in the email. But I passed the filter test and they probably had to interview anyway.
First round filter tests are usually along the lines of Fizzbuzz though. More than 20 mins and it's a red flag.
If they do not value your time while you are interviewing, there is zero reason to believe they will respect it once you are hired.
Just wondering though with 4 failures in a row, I think there is a good chance something is wrong with my code so I wanted to make sure with this post.
I've been doing the grind for years, but this is the first time I had so many take home projects.
Additionally, I never gotten hired by doing a good take-home either. Which is weird.
Additional question: What's your guys take on take-homes: Anybody ever successfully get hired by doing well on a take-home?
As ridiculous as it may sound, don’t take it personally.
Yeah thanks for the tip. I'm not taking it personally. But I still do consider this practice rude and inappropriate. It's just the rudeness is not directed at me personally but at everyone in general.
It still will reflect on the company regardless of whether anyone takes it personally.
But! there was one huge flaw with my code! like huge. Only one person in this entire thread caught it. This is a rejection level flaw for sure. It may have been it but this thread is making me think it might not be.
What's astonishing is that nobody caught it. Nobody but one guy. This flaw would've gone past all unit tests all type checking and all integration tests. No engineering process would've caught it other then analyzing the code line by line and seeing exactly what each step does.
So it makes me think that if more or less no one on this thread caught it... it's likely that the reviewer didn't catch it either. I'm thinking it's more likely some superficial aspect of the code screwed me over even though this flaw is huge. Like no unit tests or something.
It's not even some obscure flaw either it's very visible. the ZRANK call isn't doing anything. it's an empty command with discarded output... a snippet generated by code from chatgpt which lied to me about what that command does. I tested that code extensively and it worked fine.
This mistake deserves rejection, but like I said, I somehow think that this wasn't what got me rejected.
This might seem superficial but as a super senior staff, I'd expect that you mentor your junior coworkers in how to build large yet maintainable projects. One important aspect is readability and consistent style. That's why black becomes more and more used even though some of its rules are fugly.
Second not so easy change: I find "The code was also not fully organized for testing" - this actually hints at you either not writing a lot of tests in your day to day life or being very inefficient in producing tested code. You also could have at least included one sample test.
I default to this " ". But I switch around when needed. This is standard python methodology. Anyway..
This kind of thing doesn't matter. It's pure aesthetic, it's ocd stuff in my opinion. Whether you use " or ' has zero consequence to readability, maintainability, safety, and performance. Literally zero. Your code can grow to a billion lines this still doesn't matter. This is actually an ocd instinct that you should try to separate from your rational thinking. The inconsistent quotes * feel * wrong, but rationally they have zero consequence on any metric. It's just a feeling not an actuality.
Less experienced programmers often get caught up in stylistic issues but fail to realize when style is actually of zero rational consequence. Not all styles have zero consequence but some of it does.
>The code was also not fully organized for testing
Only literally 2 functions are unit testable here.
One of them is so basic that it's not even worth testing.
All unit testable functions are segregated away from IO so from a fundamental standpoint it's pretty much unit testable to the full extent.
The reason why I wrote that it's not is because the random path generation function has a bit of a flaw. It uses random number generation, so it can't be unit tested. I can't predict the output in the assert because it's random.
That's it. The amount of logic amenable to testing is so trivial and little it's not worth it here. I could segregate the random number out of the path generation function deterministic and testable but I made a judgement call here. It's a take-home and segregating the code like that leads to an API for the function call that's less intuitive. The function would need random seeds as input parameters.
Ideally, yes I shoulda done that. But this is a valid shortcut. I would say though, the majority of people aren't able to even realize how random number generation effects unit testability.
The unit testing thing is valid. Everyone mentioned that even though what's testable is so little. I'll just have to cater to the current dogma of the programming world.
It used to be different when it was hard to find people. We would be looking for excuses to accept people - e.g. the code is a bit rough, but maybe they didn’t put too much effort into the take home - let’s get them in for an interview just in case…
Now with so many applicants it will be much more a case of who can we reject so we don’t spend all our time interviewing…
Also, don’t forget, the people reviewing your code may not be the senior engineers, bend with the wind, run your code through a standard formatted so that it will match expectations. Do the unit tests even if you think it’s pointless.
Play the game.
" # returns the path and current count that was just made.
return {"path": path, "count": int(data[0])}"
also maybe extract variables and name them better like:
"pipeline_execution_result = await pipeline.execute()
count = int(pipeline_execution_result[0])"
same here:
return [{"path": path.decode('utf-8'), "count": count} for path, count in response]
what's in settings.py should probably be in an env fileoverall: variables and methods name could be clearer, use good names instead of bad comments, extract variables, don't define methods inside of methods
it's definitely not BAD code, but I'd expect a guy with 10YoE to do better
Have you used Django? Django follows the pattern of a settings file. No environment variables.
A global env file imo is definitively worse. It forces you to write code outside of the python ecosystem to extract these variables. Additionally python code references an environment variable that's not explicitly set by the env code could hit some logic errors or unexpected state.
What I would do if I had more time is have the settings file reference an env. The main benefit is that settings can be reused across apps and env errors are localized to a single point of failure instead of being littered throughout the app as references to env vars.
>This kind of comments are kind of useless it should be self explanatory
They are useless. I agree. I put the comments there in case someone disagrees. Doesn't hurt in my opinion.
>also maybe extract variables and name them better like
You mean with patten matching. No that's actually syntactically less appropriate here. The return value was not a structured product type. It was not a tuple.
The return value was a list which implies variable length. Should the list change in size that would change the pattern match. This is most likely just bad typing on the library. But my handling of said type is appropriate. Also it's super minor.
>variables and methods name could be clearer, use good names instead of bad comments, extract variables, don't define methods inside of methods
I'm actually with you on this one. I prefer clear names over elegant names. But this is not overall sentiment among the majority.
Overall people prefer an elegant name over a very descriptive one simply put of some universal intrinsic ocd instinct they all have... even though short elegant names could provide zero informational value.
I'm just catering to the majority here. Make myself a comment Nazi as most people don't disparage that and use elegant names as most people prefer that over longer descriptive names.
>it's definitely not BAD code, but I'd expect a guy with 10YoE to do better
Have you seen code written by people with 10yoe? What you will find is overall 10 yoe doesn't converge on your personal view perfect code.
It converges on their view which likely is wildly different from your view.
But this thread has been extremely informative on that fact seeing how literally everyone's view is completely different and how everyone thinks they're own personal view of the universe is the enlightened path.
The common theme: is lack of unit tests. But to further illustrate the diversity of opinions... You didn't even touch on testing. It took a back seat to "bad comments".
People are biased, and I'm biased as well, so I hope other people can see past it and see what's wrong with my code.
- requirements.txt is the standard for specifying deps, right?
- making a README explaining the project might be good (I see you have this, but maybe switch documentation.md to README.md)
- tests?
- building the flask application via a function is a bit more testable
- reading settings from ENV is preferred (12 factor apps)
- output not sanitized for /test endpoint
- generator in util could have been pulled out probably? It’s created every time
- generate test path function seems a bit longer than it should be — all those lambdas should probably just be functions since you’re going to use them a lot
- did you have to define your own Json type? Is that complete? Where’s null?
- url generate function should probably template hostname — that’s more important than host, most of the time for running in different environments
- trailing slashes matter in flask, evidently, and every request without one gets redirected (test suite would have caught this)
- on the usage of redis, I wonder if scanning + in-memory aggregation is better… zincr/zrank/zrevrange is good, but you’ll have to hold all data in memory (and receive it in one large response) and logN anyway, might as well do it simply with a set with a dynamic prefix and scan while building the output data structure as you go.
- do your API endpoints return JSON?
- error handling around points of failure like redis
— your app goes down if the connection is flaky right?
- zrevrange is deprecated now btw
Hard to tell for far they wanted you to go, but asking might have made sense… some nice-to-haves:
- healthz endpoints?
- metrics?
- tracing?
- error reporting (ex. Sentry)
>- requirements.txt is the standard for specifying deps, right?
poetry is a new thing. I just tried it for this project it replaces requirements.txt with pyproject.toml
>- making a README explaining the project might be good
I did. It's documentation.md. I didn't title it README.md because I wanted the front page on github.com to show the takehome instructions rather then my docs on it.
>- tests?
This was addressed in the documentation.md. I was given 4 hours to work on this problem so I just used manual tests.
>- building the flask application via a function is a bit more testable
Flask is an IO app. It's inherently not testable via unit tests because it's a server. You'd have to build integration tests around an entire server which is huge overkill for this project. Testable logic is usually pure and stateless, that's located in utils.py. It's ok this is good criticism.
You can monkey patch or make your code 10x more complicated with modules that accept mockIO for dependency injection but I'm actually against this style of programming as it over complicates the code with little benefit.Trying to test Flask by mocking everything out is basically just testing the mocks. Better to do this haskell style and segregate IO from pure functions (see utils.py). IO can't be unit tested.
Not many people understand the "testing" philosophy I'm following here so this is good feedback. I should sometimes just follow what's popular but ultimately not the "best" way in my opinion.
>- - output not sanitized for /test endpoint
this I don't get? Sanitized? The http request returns typical python structs, which are automatically converted to Json by flask/quart.
>- did you have to define your own Json type? Is that complete? Where’s null?
Nope don't have to, type checking is optional in python, but why not? You have to do this to get correct type annotations to everything. You're right about this missing Null/None. It all still type checks.
>- generator in util could have been pulled out probably? It’s created every time
Why pull it out? A generator is cheaper then creating a list from a list comprehension every time. instead of storing every value in a list and iterating through it, I just iterate through a generator. Saves memory and runtime cost is still O(N) regardless.
>- - url generate function should probably template hostname — that’s more important than host, most of the time for running in different environments
Sure but the context is a takehome project and it's running in docker-compose as specified by the directions. I mean yes, I can make that utility function more general for sure.
>- trailing slashes matter in flask, evidently, and every request without one gets redirected (test suite would have caught this)
I'm aware of this, it's not a mistake. I left it in as valid. The redirect does not get counted so api/xxx/ is equivalent to api/xxx
- on the usage of redis, I wonder if scanning + in-memory aggregation is better… zincr/zrank/zrevrange is good, but you’ll have to hold all data in memory (and receive it in one large response) and logN anyway, might as well do it simply with a set with a dynamic prefix and scan while building the output data structure as you go.
Your way is NlogN sorting and constant time inserts. The current way is zero cost sorting and logN inserts.
LogN is blazing fast, while nlogn can get slow if N gets too large. See this for relative visualization: https://i.stack.imgur.com/osGBT.jpg. Given the picture I would say my way is better. .
>- - do your API endpoints return JSON?
Yes this is the default. If you return anything that's equivalent to that JSON type I defined in utils.py, flask will automatically return serialized json.
> - error handling around points of failure like redis
Flask/quart runs under the hypercorn server (see the dockerfile). Additionally If a handler throws an exception the user automatically gets a 500 error from flask it's handled exactly as you would expect an http server should handle it. The server does not crash.
>— your app goes down if the connection is flaky right?
No it does not. hypercorn remains running if the python worker crashes. But of course if hypercorn itself goes down then it's done. This of course can be mitigated by systemd but that's overkill for this project.
>- zrevrange is deprecated now btw
Yeah your right. My mistake. Still works though. So it's marked for deprecation, but not actually deprecated yet.
>-healthz endpoints?
>-metrics?
>-tracing?
>-error reporting (ex. Sentry)
For a four hour take-home project? These things weren't even in the spec and how these things and if these things are implemented are extremely variable per company across the industry.
You know overall your post has been enlightening but not in the way you think because we are clashing on most of these points. I can see how developers can literally disagree on everything and how code reviewers can make a ton of assumptions and have a ton of arbitrary opinions. Not to mention varying levels of experience and what experience for that matter causes them to make completely different judgement calls. Don't take this as a slight, I'm sure if I was in your position I would be reviewing your code in the same way and you'd see me in the same way as well.
I'm starting to think take home assignments are just bad. Even worse for evaluating programmers then algorithm interviews because there's so many biased variables here that programmers are just clashing on. Maybe it's a good filter for finding programmers who view the programming world in the exact same way they see it.
I disagree. You could argue that the type of tests outlined here https://flask.palletsprojects.com/en/2.3.x/testing/ are integration tests, in the sense that you're actually testing a full endpoint, but it doesn't require the kind of full integration testing setup that you're describing. I'm not suggesting this is a reason you "failed" the take-home — as others have mentioned, there's myriad reasons why you could have failed, none of which have anything to do with your code, but I did feel the need to correct what I see as a wrong understanding of the type of testing setup that is required here and what's possible.
Think of IO as a virus it pollutes the outer scope of anything it lies within. Anything that contains IO becomes IO and therefore is not unit testable. In fact any function marked with "await" or "async" is usually a good indicator of this pollution. Async await keywords actually spread around according to this exact logic I specified.
Example:
async def handler(request) -> response:
x = await iocall()
y = add(2, x)
return response(y)
iocall is in the scope of handler, handler becomes polluted with async and thus "not unit testable". I took the time to encapsulate pure addition logic into the add function, this makes add testable because it doesn't enclose over any IO functions.That's the pattern of making unit testable code. You should try to move as much logic as possible into pure functions like add. Keep IO functions small and general and devoid of custom logic while segregating all your custom code into pure functions. Then just test these pure functions and leave everything else alone because all that other stuff goes into the realm of IO and integration tests.
You could get around this with mocking and using dependency injection but that comes with it's own set of problems including more complexity and spending the extra time to get the mocks to return results you want for each test. I would move these into the realm of integration tests rather then mock. In this case the usage of the flask test_client would still have to involve spinning up some sort of infra involving the database.
Your point about the unit test client from flask is completely valid for certain cases. It only works if the handler does not touch IO. In that case you wouldn't even need to mark the handler with the async keyword as nothing is awaited.
Ah thanks, I saw this later -- the pyproject.toml was very illustrative.
> I did. It's documentation.md. I didn't title it README.md because I wanted the front page on github.com to show the takehome instructions rather then my docs on it.
Is there a reason for this? I would think this was a good chance to show off your ability to write succinct/standardized documentation w/ sections that anyone else would be glad to read/see.
> This was addressed in the documentation.md. I was given 4 hours to work on this problem so I just used manual tests.
Yeah I can see this, but I think "automated tests" are quite big in peoples' minds. Feels like it would be a checkbox on the item.
Budgeting some of the time to make 100% sure your code was tested seems like it might have been a good idea.
> Flask is an IO app. It's inherently not testable via unit tests because it's a server. You'd have to build integration tests around an entire server which is huge overkill for this project. Testable logic is usually pure and stateless, that's located in utils.py. It's ok this is good criticism. > > You can monkey patch or make your code 10x more complicated with modules that accept mockIO for dependency injection but I'm actually against this style of programming as it over complicates the code with little benefit.Trying to test Flask by mocking everything out is basically just testing the mocks. Better to do this haskell style and segregate IO from pure functions (see utils.py). IO can't be unit tested. > > Not many people understand the "testing" philosophy I'm following here so this is good feedback. I should sometimes just follow what's popular but ultimately not the "best" way in my opinion.
I disagree here -- table stakes for a good API is integration and E2E testing -- and they're the easiest to do (no need to manipulate a browser window, etc).
I agree with you on not testing the mocks, but for that I personally would bring in a library for this like testcontainers for python: https://testcontainers-python.readthedocs.io/en/latest/READM...
IMO E2E tests are the most valuable tests.
> this I don't get? Sanitized? The http request returns typical python structs, which are automatically converted to Json by flask/quart.
Sorry INPUT is what I meant to write there -- what happens if you get a -1 ?
> Nope don't have to, type checking is optional in python, but why not? You have to do this to get correct type annotations to everything. You're right about this missing Null/None. It all still type checks.
Right, but this is what I mean -- when I read that I wondered if it was complete, and it wasn't. That's an unnecessary ding to take.
If you're going to type it, it should type correctly, or you should use pull in the typings from somewhere else, IMO.
> Why pull it out? A generator is cheaper then creating a list from a list comprehension every time. instead of storing every value in a list and iterating through it, I just iterate through a generator. Saves memory and runtime cost is still O(N) regardless.
This is going to build objects dynamically every execution right? That's what I thought could be avoided. Less about lists vs generators, more about doing things that look like they allocate so much.
Do you think there's something you could do to create less garbage during the function execution? If not then you can disregard that point!
> Sure but the context is a takehome project and it's running in docker-compose as specified by the directions. I mean yes, I can make that utility function more general for sure.
It's not about making it general per say -- it's more like what is your instinct at this point.
My instinct personally (and granted I spent like... 30min to an hour just reading all the code) is that I always take my host/port from ENV, and everything else possible. It's just something you know is going to come up.
> I'm aware of this, it's not a mistake. I left it in as valid. The redirect does not get counted so api/xxx/ is equivalent to api/xxx
Ah OK, but this isn't what they asked for, right? If we want to be really pedantic, your endpoint returns a 3xx for every single error.
Redirects are not followed automatically, it depends on the HTTP client, right? So one that doesn't follow redirects would fail this test. It's unlikely, but maybe this code failed automated testing for a little reason like that.
> Your way is NlogN sorting and constant time inserts. The current way is zero cost sorting and logN inserts. > > LogN is blazing fast, while nlogn can get slow if N gets too large. See this for relative visualization: https://i.stack.imgur.com/osGBT.jpg. Given the picture I would say my way is better. .
The measurement endpoint will be called far more (100x, 1000x, ...) than the stats endpoint -- it's the hot path.
Also, note that sorting is zero cost, but retrieving the data will still be in N time including network round trips, which will likely dwarf any time you spend sorting in local memory. Even the conversion to JSON will dwarf the time you spend sorting for large N.
You're right about the complexity -- but note that ZREVRANGE is O(log(N)+M), and in this case we KNOW that M = N, so IIRC that's O(N).
Regardless of the complexity, I personally wouldn't make that tradeoff until it was necessary -- speed of the hot path is more important in my mind, and there are other ways to manage speed of the stats endpoint.
Also, the point of memory usage being potentially large is still relevant. My instinct is that when I see something returning a possibly very large piece of data, setting up for streaming is the way to go. Doing a scan you have the possibility to use far less memory for an individual request, and you could actually stream responses back in extreme cases, so you can avoid holding the entire result set in memory at all.
If you want to get really fancy, you can get creative with how data is stored on the redis side and get the size to N.
> Flask/quart runs under the hypercorn server (see the dockerfile). Additionally If a handler throws an exception the user automatically gets a 500 error from flask it's handled exactly as you would expect an http server should handle it. The server does not crash.
Ahh OK, I did see hypercorn in the Dockerfile and forgot about it, I see how that your worker would be restarted by hypercorn.
The point about error handling still stands with respect to reporting though -- you generally want to see error handling in code, rather than just leaving it up to the runtime to fail the task and carry on.
Adding this would have prompted you to think about some sort of error reporting, which is generally good practice.
> For a four hour take-home project? These things weren't even in the spec and how these things and if these things are implemented are extremely variable per company across the industry.
The things you include/don't include by instinct I think is valuable signal.
Like I said, they're nice-to-haves, but error reporting is probably the big one there. In production errors should to be gathered somewhere.
You can make the argument that they'll be collected by a logging system and that's why you've left them out, but I also don't see any structured logging.
> You know overall your post has been enlightening but not in the way you think because we are clashing on most of these points. I can see how developers can literally disagree on everything and how code reviewers can make a ton of assumptions and have a ton of arbitrary opinions. Not to mention varying levels of experience and what experience for that matter causes them to make completely different judgement calls. Don't take this as a slight, I'm sure if I was in your position I would be reviewing your code in the same way and you'd see me in the same way as well. > > I'm starting to think take home assignments are just bad. Even worse for evaluating programmers then algorithm interviews because there's so many biased variables here that programmers are just clashing on. Maybe it's a good filter for finding programmers who view the programming world in the exact same way they see it.
Yeah, that's a pretty common take (see all the comments in this thread).
I'd disagree that it's worse than algo interviews, because algos are rarely the most important thing in a professional code base, especially one with that's about web services and not something more demanding.
All this said though, the only way to know why they passed is to ask! Unfortunate that you can't get any feedback.
I threw the docs in the README for the submission, but for HN readers they want to see the problem first. The submission didn't even include the specs.
>Yeah I can see this, but I think "automated tests" are quite big in peoples' minds. Feels like it would be a checkbox on the item.
Yeah you're completely right here. I'm gonna go with it next time.
>I disagree here -- table stakes for a good API is integration and E2E testing -- and they're the easiest to do (no need to manipulate a browser window, etc).
Yeah but many companies don't do integration testing as the infra on this is huge and writing tests is more complicated. It's certainly overkill for take home. I would say you're wrong here. Completely. This company was not expecting integration tests as part of the project at all.
I've worked for start ups most of my career, and I'm applying to start ups. It's mostly the huge companies that have the resources to spend the effort to have full coverage on that.
Integration tests are Not easy, btw. Infrastructure is not easy to emulate completely, how would I emulate google big query or say aws iot on my local machine? Can't, most likely integration tests involve actual infra, combined with meta code that manipulates docker containers.
>Sorry INPUT is what I meant to write there -- what happens if you get a -1 ?
You get a 500. Which is not bad. But you're right a 400 is better here.
>Right, but this is what I mean -- when I read that I wondered if it was complete, and it wasn't. That's an unnecessary ding to take.
I feel this is such a minor thing. I'm sure most people would agree if you dinged that you'd be the one going overboard, not the candidate.
>This is going to build objects dynamically every execution right? That's what I thought could be avoided. Less about lists vs generators, more about doing things that look like they allocate so much.
You're going to build objects dynamically every execution Anyway. This saves you the extra intermediary step of not having to save it to an extra list.
numbers = [i*2 for i in range(500)] #allocated list in memory: 500*sizeof(int) (big)
for i in numbers:
print(i + 1)
numbers = (i*2 for i in range(500)) #allocated generator in memory: sizeof(*generator) (small)
for i in numbers:
print(i + 1)
Look at the above. Same concept. Generators are drop in replacements for actual state. State and functions are the isomorphic (ie the same thing). Building a generator is cheaper then building a list. You should read SICP about this topic of how functions and data are the same.>Ah OK, but this isn't what they asked for, right? If we want to be really pedantic, your endpoint returns a 3xx for every single error.
It's a reasonable assumption that all users assume /xx/xx equals /xx/xx/. It's also reasonable for a client to handle a 302 redirect. The specs didn't specify the exact definition on either of these things.
>The measurement endpoint will be called far more (100x, 1000x, ...) than the stats endpoint -- it's the hot path.
So? logN is super fast. You have 100 objects binary or whatever indexed insert redis uses gets there in at most 4 or 5 jumps. So even if it's the hot path redis can take it.
NLogN is slow enough that if N is large there is noticeable slow downs EVEN when it's a single call. Recall that redis is single threaded sync. NlogN can block it completely.
Either way this is all opinion here right? Ideally the results are returned unsorted. the client is the best place to sort this, but that's not the requirement.
>Also, note that sorting is zero cost, but retrieving the data will still be in N time including network round trips, which will likely dwarf any time you spend sorting in local memory. Even the conversion to JSON will dwarf the time you spend sorting for large N.
Of course the act of reading and writing data will cost N regardless. But your reasoning is incorrect. Look at that picture again: https://i.stack.imgur.com/osGBT.jpg. O(NlogN) will dwarf O(N) when N is large enough. It will even dwarf IO round trip time and has the potential of blocking redis completely on processing the sort.
>Also, the point of memory usage being potentially large is still relevant. My instinct is that when I see something returning a possibly very large piece of data, setting up for streaming is the way to go. Doing a scan you have the possibility to use far less memory for an individual request, and you could actually stream responses back in extreme cases, so you can avoid holding the entire result set in memory at all.
Sure but look at the specs. It's asking for http requests. It's not a streaming protocol here. I mean at this point if you were evaluating my code for a job you'd be going to far already as your going off the rails completely.
>The point about error handling still stands with respect to reporting though -- you generally want to see error handling in code, rather than just leaving it up to the runtime to fail the task and carry on.
I mean I could build a full logger and error handler framework here. I'd put custom handling in a decorator and have the error handling invisible in the http route handlers. Flask already does this, but it just returns 500 on all exceptions. That is the most elegant way imo. But again this is a bit outside of the scope of a takehome, given the framework handles a lot it and the extra effort required.
>If you want to get really fancy, you can get creative with how data is stored on the redis side and get the size to N.
For takehomes and in general people prefer readable code. Only optimize if it's needed. I mean I can write the whole thing in assembly code for ultimate performance. I can def see some nitpicker dinging me for optimized but unreadable code.
>The things you include/don't include by instinct I think is valuable signal.
Not to be insulting here. But I think your instincts are pretty off here. There's a limited amount of time assigned to this project. All the basics were included with what I did in the time allotted.
When you have good instincts you know when to apply automated testing, when to use error handling. These aren't things you should do all the time. Your attitude is something I see in many younger engineers. This attitude of rule following and best practices is just adhered to without thinking it all through properly. For the scope of the project. most of what you wrote here isn't needed.
You're also not testing what's traditionally tested in interviews. They test intelligence, depth knowledge and ability to design and solve problems. You're testing the ability to follow written rules. I mean following these things is trivial. It doesn't take much brain power to write error handling or unit tests. Perhaps you're just testing for someone that agrees with your programming philosophy. I mean these things can be followed regardless
Your mention of integration tests is telling. I mean the code for integration tests can rival the size of the code in the project itself with the a minor benefit in safety . It's not just take home assignments but many many many companies loaded with senior engineers skip over automated integration tests and keep those tasks in todo lists for the longest time. There's a huge engineering cost to building out testing infra to the maximum ideal, and many companies just don't bother. It's mostly the bigger well established companies that have the resources to do this.
>I'd disagree that it's worse than algo interviews, because algos are rarely the most important thing in a professional code base, especially one with that's about web services and not something more demanding.
It is worse in my opinion because it's biased. What if your opinion was more correct then my opinion but I judged you based off of my world view? Would that be right? No it wouldn't. Programmers are diverse and the best organizations have diversity in opinions and expertise.
All in all I mostly disagree but I think your right on one thing: At least one of those job candidate evaluators that are looking at my code likely had a similar attitude as you do and I should bias my code towards that more. Likely won't write integration tests though, hard no on that one.
Also good catch on the /test/-1/. That's definitely a legit ding imo.
You should learn to accept the fact that you will not get an honest review. If you choose to enter in to a take home test go in to it with that understanding.
The interview process is a chance for them to review you, but also for you to review them. Make sure the process is equitable. If they ask for too much you owe it to yourself to push back. Ultimately they will respect you more if you stand up for yourself. It shows you have healthy boundaries and will protect their interests when you work for them.
I've heard this argument many times but can't quite get it. Based on my experience some companies do provide honest feedback, some don't. I try to ask in advance and decline those who will not give any feedback.
But lets say they know you're not a fit. So they decline you based on your test project. What is the benefit to the hiring manager to have them or a developer sit down and tell you why you weren't a good fit? It costs them time a lot of time. That does not benefit their need, finding someone for their open role. The biggest negative to this behavior is a reputation hit for the company with that one person.
Liability: providing feedback gives you the interviewee something to argue about. It also is a communication done by acting members of the company and therefore relatively official. All it takes is someone being a bit rude, disrespectful, or even a misunderstanding to make this now official communication something somone could try and publically shame the company with. Its easier for them to say nothing or ver little at all.
With a third party recruiter there is an expectation that the recruiter will take a percentage of the placed applicants salary. And the employer expects the recruiter will bring them quality applicants. Therefore the rectuiter often has more leverage than you might and can sometimes eek out more information for you.
Im not saying I agree entirely with this behavior. Specifically i think ghosting an applicant especially later in the process is unforgivable.
But I also think its your personal responsibility to figure out where you stand technically and socially. Find resources, people who care about you and ask them for feedback.
The interview process is terrible and its only gotten worse in the 25 years ive been working. Hang in there and do your best, but try and keep your expectations reasonable; you'll live longer.
I interviewed for a company in May that gave me a takehome that was very vague and probably would have taken my entire weekend to do it. So I declined and moved on.
My rule of thumb though is to spend no more than 2-3 hours on a takehome challenge. If you think it will take any longer, don't do it. And lack of any feedback from the company pass or fail is ridiculous to me.
As for your submission it LGTM. I'd bring you in and probably ask about how you'd want to improve it if you had more time, expecting the usual best practices and scalability things. I'm not sure your Python experience, but given the context of the problem space, I'd ask why you wouldn't consider other approaches like adding the url metric logic in a decorator or some other modularization that could be reused to "performance test" future API calls. I'd ask about your submission's lack of tests (getting at unit tests here) and how you could refactor your solution to facilitate better test coverage if you had more time. Deepdive about the tradeoffs of using Python coroutines as opposed to other concurrency methods.
Unfortunately there's always going to be a desperate developer out there who will spend every waking second overengineering a solution that will set a high standard for everyone else to be compared against.
Wishing you the best of luck!
Every commenter hit on this. I have my reasons. But it's so common that next time I'll be for sure doing it.
Lesson for me and everybody: for take homes write tests.
>I'd ask why you wouldn't consider other approaches like adding the url metric logic in a decorator or some other modularization that could be reused to "performance test" future API calls.
I would consider it. I just didn't do it lol. You can already use that test route to run integration tests, but the logic in that route is easily placed in its own undecorated function for usage outside of flask .
>Unfortunately there's always going to be a desperate developer out there who will spend every waking second overengineering a solution that will set a high standard for everyone else to be compared against.
I actually could've spared the time for more hours on this. But they specifically requested I spend no more than 4 hours on this. I think they've gotten things that obviously took much longer then 4 hours and they didn't like it. I think maybe I should've done it anyway just for adding unit tests. They can maybe tell that something took more then 4 hours if a project took 16 hours but likely not one that took maybe 6 to 8.
That's not going to return the right value most of the time - for instance, in the example from the docs at https://redis.io/docs/data-types/sorted-sets/ has this:
zrank hackers "Anita Borg" is 4
but "Anita Borg"'s score is 1949. The operation you likely wanted was "zscore".It would be straightforward to check this, either manually or in an automated test - simulate hitting "/api/abc/" once and "/api/xyz/" three times. The result of 3 of the 4 requests will be wrong:
for /api/abc/: will have count=0 because /api/abc/ is the only entry in the sorted set
first one for /api/xyz/ will have count=1 because /api/abc/ sorts before /api/xyz/ and they both have a score of 1
second one for /api/xyz/ will have count=1 because /api/xyz/ has a higher score than /api/abc/
third one for /api/xyz/ will have count=1 because that's still true
Now, it's true that the assignment didn't say anything about what the service should return: you might have done better on this assignment by returning HTTP 204 and an empty body.IMO when a "super senior / staff engineer" chooses to write code, they should write WORKING CODE and verify that that's true.
There are three functions: https://github.com/anonanonme/takehome-sample/blob/master/ut...
I don't judge people for these types of mistakes either. It's all nits. Especially in an HN comment. But someone evaluating a job candidate, in my opinion, needs to step up his game and I'm thinking a lot of these people are treating it the same way you're treating it.
You can spin the code up with "docker-compose up --build"
You and everyone else can then verify your statements on my project by running this:
docker exec -it flask poetry run http localhost:5000/api/abc/
docker exec -it flask poetry run http localhost:5000/api/xyz/
docker exec -it flask poetry run http localhost:5000/api/xyz/
docker exec -it flask poetry run http localhost:5000/api/xyz/
(By the way the response on these calls actually returns the current count of the specific route for easier testing. You can see whether your hypothesis is real by watching the results unfold on each request.)Then run this:
docker exec -it flask poetry run http localhost:5000/stats/
and the results are: [
{
"count": 3,
"path": "xyz"
},
{
"count": 1,
"path": "abc"
}
]
Which is correct. Which means You are wrong sir. You did not test my code. Literally, I just ran this in my code, you can try it if you have the time.I mean you're not the only person to make wrong assumptions on this thread. I'm getting the sense that reviewers just take a quick look and make rash judgements and then throw it into the trash. I'm betting it's not too far off from what the reviewer did for me.
You didn't run the code, which is fine, it's not expected of you. But shockingly, I think it's quite likely the evaluator at the company didn't run my code either and that is not expected or appropriate imo.
I think it's safe to say that This thread in general and your response included is becoming an accurate representation of typical shenanigans that happen for take home projects.
(Your mistake here fine, not a big deal, you're not evaluating me just giving me advice so getting things wrong is understandable in your case)
# - pipeline insures that the zincrby and zrank call happen atomically and prevents race conditions.
# - zincrby increments the score on the string, zrank fetches the new score
pipeline = redis.pipeline()
pipeline.zincrby(URL_PATH_COUNT_DATA_STRUCTURE, 1, path)
pipeline.zrank(URL_PATH_COUNT_DATA_STRUCTURE, path, )
data = await pipeline.execute()
# returns the path and current count that was just made.
return {"path": path, "count": int(data[0])}
So you make a pipeline so that the zincrby and zrank can be atomic. But the zrank seems to be completely pointless, it does not, as the comment suggests, "fetches the new score." The reason the counts are correct is because you are pulling the first reply out of the pipeline which is the result of zincrby, which is the new score.So if I were evaluating your code I would wonder
- Why is there a pipeline here at all?
- Why is it zranking?
- Did the comment go stale and the candidate just has poor attention to detail?
- Is the comment the candidate telling me that they don't know how zrank works and they don't know how pipeline works?
- Why is the comment lying to me?
- Does this super senior engineer think "insure" and "ensure" are the same word?
The above code seems to my reading to be identical to score = await redis.zincrby(URL_PATH_COUNT_DATA_STRUCTURE, 1, path)
return {"path": path, "count" int(score)}If there's any raw legitimate claim to a rejection it's this.
Literally everyone else commented on a bunch of superficial things and no one hit on the extra zrank here. It's not even about not being able to follow the code. I think very few people even remember specific redis commands or even bothered to follow the logic.
That first part over there blew up your whole effort. No matter how good as an engineer you are, if you don't provide any unit tests, most often it's an automatic rejection.
Also why did you put that self-criticism section anyway? You don't owe them anything nor should they owe you as well.
As a final thought when you are doing the effort to apply to work for someone else then they can reject you for pretty much anything so don't sweat it too much.
I understand. It's disheartening. But it's not you, it's them.
That's why I posted my code. Was wondering if there's something fundamentally wrong here.
I think you underestimate how many comms-poor companies there are, how many shite hiring managers and processes, etc.
I will say from the perspective of the reviewer he is likely to not be aware of this. Likely he thinks his pet preferences should be standard practice as do most programmers think of their own.
Take-home exam is bullshit in my opinion. I've done total of 3 in my career, and nothing came out of it. Zero feedback other than you are not what we are looking for. I've long since declined about any take home exams. I rather leetcode than take home because leetcode can scale, while take home is just unpaid work.
I addressed the unit testing thing in other comments. First I'm not an adherent to unit testing much of the code is io based and very little logic can actually be unit tested.
But everyone, literally everyone is calling out the lack of tests. So likely I will do it next time.
Maybe a dumb question, but did you follow up and ask for feedback? Sometimes people just don't think to provide feedback, but they would if prompted to.
Other than that, I think the code is completely fine. Stylistically I can see people having non-consequential nit-picks based on what they like but I think it wouldn't be an issue to get weeded out by.
Code review: For a senior dev, I would expect tests even if I didn't ask for them explicitly. I'm also surprised to see that the functions are in a generic utils instead of better named files.
The reality: 1. other people are spending more time on these takehomes. 2. Being more senior means that there are higher expectations. 3. The takehomes are typically a qualitative assessment
Good tip. They already said in the rejection letter no feedback will be given.
> For a senior dev, I would expect tests even if I didn't ask for them explicitly.
Several people mentioned this. You're definitely onto something here.
The thing here is that the code is mostly IO, not amenable to unit testing. For most web applications that has a lot of logic moves from database to web app to client to route, not much can be unit tested.
Typically the best pattern to follow here is to segregate as much logic away from IO as you can and move it into pure functions. That's what utils.py is. But you'll see utils.py is so small there's not much there to be worth testing. (Dependency Injection and mocks is a more popular pattern for unit testable code but it makes things much more complicated and you end up writing a lot of mock code and the unit tests end up testing mocks more then the actual logic itself)
The fact that utils.py is so small is an indicator that this web app is mostly an IO app and you have logic on the database dependent on logic on the server and vice versa which takes a lot of time to write "integration tests" for. Integreation tests are excessive imo for a takehome project.
Believe it or not excessive adherence to unit tests is actually a quality of junior engineer. They aren't knowledgeable enough to practice nuance and to see when unit tests become completely pointless.
But this is probably just my opinion. I think it's quite likely a lot of (senior) reviewers are following your train of thought.
Thanks! They requested me to spend only 4 hours on it.
> I can't see the restriction on number of path segments in the code ("/api/ followed by 1 to 6 path segments") and they might have insisted on tests while not mentioning tests.
the segment amount is restricted via a default value in utils.py:
def generate_test_paths(test_path_amount: int,
segment_amount: int = 6, #here!
string_pool_amount: int = 3,
string_length: int = 3) -> List[str]:
The segment_amount gets inserted into this lambda: segments = (segment_generator(random.randint(1, segment_amount)) for _ in range(test_path_amount))
which generates a list of strings from a pool of pre-selected strings.Perhaps this section isn't clear?
>Nobody can tell what "production readiness, and code structure" might mean for them.
yeah I hate that.
No need to waste another 4 hours per company (a ridiculously large task).
It's also kind of stupid in my opinion because of the way they pick the question. Usually they'll find the most interesting leet code style problem that their company had to solve one time in a blue moon and make that their test problem.
I'm not exactly the most successful socially saavy engineer with a bunch of industry connections. I'm more just a lone wolf programmer. I like to think I'm really good, but guess not?