Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Somewhat got confused by the question given part 1. I didnt think we were asked to modify the source but just write a middle layer. Considering you want to stay in sync with the main codebase for memcache with updates and what not, my (potentially incorrect) solution was somewhat hacky

1. Client saves value in local memory. Then issues a command to update the number to a string version of the number (maybe with a flag telling any client to parse it as integer for get). Assuming setting a value is “safe”, this would cause other concurrent clients to error if they are trying to incr (according to example from part 1) 2. Client that did this update now multiplies that local variable. 3. Client updates value to final answer.

If a failure/crash happened you could still sort of retrieve the original value since it is a string version of itself.

Anyway it is hacky and sort of messes up if someone attempts to get the variable while it is a string. So I probably would fail this question.



I went down a very similar train of thought, making the same assumption. I think this makes us “type 1” engineers: wrongly assume that we are not allowed to break the existing code contract, and attempt to use it to implement a new solution “over” the old. Extending without modifying.

I took that as a kind of lesson in and of itself. I’ve certainly had to face code monstrosities and cut through multiple layers to discover the simple rewrite before. If somebody had modified instead of extended sooner, if someone assumed the existing solutions were not so sacred, maybe a monstrosity could have been avoided in the first place.


On the flip side I've also experienced the opposite. Someone modifies existing code from an open source library and then we aren't able to safely upgrade it because of tons of merge conflicts with the modifications that were added.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: