patterncsharpMajor
What are some indicators that I was over-thinking my solution to this problem?
Viewed 0 times
thisproblemthinkingwhatareindicatorsthatsomewassolution
Problem
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:
And the code after some quick refactoring.
```
internal class PhoneNumberManager
{
private string _nonNumeric = "[^0-9.]";
private string _result;
public PhoneNumberManager(string number)
{
_res
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)
{
_res
Solution
The Regex expression
If you remvoe the
But, this can be furthermore simplify to
So the whole thing could be written in one line
I don't think it is worth to create a
Pre optimization is the root of all evil
While your code may not be perfect or optimized, but it works and that is your primary focus/target. Optimization and refactoring only come after because, while working on the code, your view is narrowed on the problem. And, thus unable to view the big picture.
Don't push yourself too much when you just started as junior developer. A lot of tools and techniques are refined from experiences that you will eventually pick up along the way.
[^0-9.] matches anything other than 0 to 9 and ..If you remvoe the
. from the expression, It should only match everything you want.But, this can be furthermore simplify to
\D which matches anything but numbers.So the whole thing could be written in one line
Regex.Replace(value, @"\D", "")I don't think it is worth to create a
PhoneNumberManager class that holds the direct (and maybe? the temporary) result to perform this kind of task. It could be refactored down to a helper class like this :internal class PhoneNumberHelper
{
public static string StripNonDigit(string number)
{
const string NonDigit = @"\D";
return Regex.Replace(number, NonDigit, string.Empty);
}
// and your bunch of other methods below
}Pre optimization is the root of all evil
While your code may not be perfect or optimized, but it works and that is your primary focus/target. Optimization and refactoring only come after because, while working on the code, your view is narrowed on the problem. And, thus unable to view the big picture.
Don't push yourself too much when you just started as junior developer. A lot of tools and techniques are refined from experiences that you will eventually pick up along the way.
Code Snippets
Regex.Replace(value, @"\D", "")internal class PhoneNumberHelper
{
public static string StripNonDigit(string number)
{
const string NonDigit = @"\D";
return Regex.Replace(number, NonDigit, string.Empty);
}
// and your bunch of other methods below
}Context
StackExchange Code Review Q#56130, answer score: 21
Revisions (0)
No revisions yet.