This question is a cross between career question and a code review. I was uncertain where to ask, but since there is code involved I went with CodeReview.
I’m going through the process of technical interviews, and it hasn’t been a positive experience but I’m trying to make sense of the feedback I’ve gotten to improve the experience.
While some feedback is conflicting with other feedback, I’ve been told more than once that I’m overthinking, and that my solutions are too complex (not talking about complexity as in Big O). I’m trying to understand what that means so I know how and what to change.
My theory is the following: I’m a junior developer, but the developers I hang out with are senior- and probably beyond that. All the conversations are around architecture and complex problems- and it probably rubs off on me as I find myself thinking a lot about ‘what is the best design etc.’
The questions I have (this where I need your help): What is meant by overthink/overly complex? Any examples? What would be a good approach to avoid doing that?
I’ll give you an example, and please keep in mind that the code was written under pressure and I was a nerve wreck. One of the things I had to implement was replacing a country code from a phone number with 0 and remove space and non didgit (this was one out of approx. 10 user stories). I did it TDD style, and here is the test:
[TestMethod]
public void StripNumber_WhenGivenNumber_ReturnsNumberWithoutSpaceAndNonNumeric()
{
var number = "046 55.5";
var expectedString = "046555";
var numberManager = new PhoneNumberManager(number);
var cleanedString = numberManager.StripWhiteSpaceAndNonDigit().Result();
Assert.AreEqual(expectedString, cleanedString);
}
And the code after some quick refactoring.
internal class PhoneNumberManager
{
private string _nonNumeric = "[^0-9.]";
private string _result;
public PhoneNumberManager(string number)
{
_result = number;
}
public PhoneNumberManager StripWhiteSpaceAndNonDigit()
{
_result = Regex.Replace(_result, _nonNumeric, "").Replace(".", "");
return this;
}
//bunch of other methods, and a Result() method
}
What/how I did:
- Started on test
- Wrote enough code to make it pass – some red test in-between, did some debugging
- Refactored to a class
- Verified test still runs green
- Quick minor refactoring
- Moved on to next story
Took me 20 minutes with some discussions around it and other questions that came up (I would think it would take way less if I was at work and coding and not an interview)
Keep in mind this was live coding via screen share, and this was just one of of 10 stories to implement. It pains me to share this, but this is how my code looks like under pressure.
EDIT: Since some seem to have missed the part about several user stories: There were 10 of them, all of them dealing with the phone number somehow.
EDIT RE. TDD: The interviewer talked a lot about TDD before the interview (and how this was important to them), and before I started coding I asked if I should do TDD since they had said I would be evaluated on code and tests. Reply was : 'do what you usually do' - so I did TDD.
As I was coding I said things such as:
- I verified the amount of data we would be working with so I could estimate how much I should worry about complexity
- Naming isn’t terrible good here, but I’ll leave it at that for now since the focus is the code (I blanked out on naming basically)
- I don’t like the Regex and Replace combo, I should use a Regex only
- The other dev (interviewing) suggested a Regex match but I said no since that meant we would get a split at each non digit, yielding a collection which I thought would add overhead.
- I didn’t like the lonely “0” concat
- I regretted not using a string builder instead- but data amount wouldn’t be big (first thing I asked)
At the end of the coding session I refactored the class to a fluent approach with method chaining, explaining that I considered this to be a pipeline approach where we might want to use different pipes and still have one defined place to go for the output.
Where did I go wrong? What are the signs of overthinking in the code?- and also, always happy to hear what is messed up in the code or can be improved :)
Manager
. \$\endgroup\$