I have met an interview question a long time ago. Code And found the problem, that piece of code is like this:
Public String xxxxxx (string input)
{
Stringbuilder sb = New Stringbuilder (input );
// Here is a bunch of complicated Sb statements.
Return Input;
}
We can see from a glance that it's just a little bit of fun.
However, in my current project, some people make similar mistakes. This is a very serious problem. It directly causes systemic problems.
Background:
Before performing database operations, we need to standardize user input, including intercepting user input and removing leading and trailing spaces.
Similarly, the data retrieved from the database must be processed in the same way.
This of course needs to be written into the common method. This is the code segment that I found the problem:
For (Cntt = 0; cntt <Str. length; cntt ++)
{
If ((" ". Equals (Str. substring (cntt, 1 ))))
{
Strwork = Str. substring (cntt + 1, str. Length-cntt-1 );
Continue ;
}
Else
{
Strwork = Str. substring (cntt, str. Length-cntt );
Break ;
}
}
This is to remove the space in the front corner. If there is a bug in this Code, do you find any performance problems in it?
Do not tell me that stringbuilder should be used. The real problem is that it should not be intercepted in the loop.
In the loop, you only need to count and intercept it after the loop. This avoids many string operations. Isn't it better.
Therefore, I said that a good foundation is always necessary. This foundation includes both Programming Language But we need to pay more attention to the basis of programming ideas and ways of thinking.
Do not complicate simple problems, or simplify complicated problems. Write such code. I can only say that the coding staff did not think about it at all and then write the code.
Many people complain that you are asked to give interview questions, which are basic questions.
However, are you very clear about the questions?
Can you give an accurate answer without having to look up the information?
If you cannot, I suggest you go home to review your lessons first.
Don't even understand these basic things. Just talk to me about some advanced design models and the latest technologies.
Don't tell me that there is no need. Basic things can be mastered within a short period of time and will not be used by applications at ordinary times .......
In my opinion, do not: Build a high platform on the sand float.
(This article is specially sent if you are in a bad mood .)