What is string banging and why is it bad?

My boss continues to use the term โ€œline beatโ€ (we are a Java store) and usually makes an example of me whenever I ask him about something (as if I should know about it already). I researched this term only to find results related to theoretical physics and string theory.

I suppose this has something to do with using String / StringBuilders incorrectly or not in accordance with best practices, but for my life I can't figure out what it is.

+4
source share
6 answers

"String bashing" is a slang term for cutting strings and manipulating them: splitting, merging, pasting, tokenization, parsing, etc.

This is not inherently bad (despite the connotation of "bashing"), but as you point out, in Java you need to be careful not to use String when StringBuilder would be more efficient.

+4
source

Why don't you ask your boss about an example of beating strings. Remember to ask him the right way to refactor the examples that he gives you.

+2
source

Guess: this may mean something related to creating unnecessary temporary objects, and in this particular case, Strings. For example, if you create a String token using a token, it is usually recommended to use StringBuilder. If String is not built using the builder, each concatenation will result in the creation of a different temporary object (and later garbage collected).

In modern virtual machines (I think HotSpot 1.5 or 1.6) this is rarely a problem if you are not in critical critical code or you are building long lines, for example. in for loops.

Just a hunch; maybe it is better to ask what he or she means? I have never heard this term before.

+1
source

From the context, "string bashing" doesn't really matter. This is not an echoing word for any good or bad behavior. This would simply mean "bashing strings", as with string operations.

Good or bad depends on what you do, and the role of the lines will not really matter. There are good and bad ways to process any data.

Sometimes โ€œline breaking" is actually the best solution. For example, consider that you want to highlight the first three characters of a string. You can create a regex that isolates characters, but that would certainly be redundant as there is a simple string operation that can do the same thing, which is much faster and easier to maintain.

+1
source

Effective Java has an element about using strings: "Point 50: Avoid strings where other types are more appropriate." Also on stackoverflow: Strictly printed . "

+1
source

There are several google results that reference the bashing string in this context. They do not seem to cite concerns about inefficient time series and the use of StringBuilder.

Instead, it appears to relate to simplified parsing of strings. That is, doing things, for example, checking substrings, cutting a string, etc. In particular, it seems to imply that this is a hacker solution to the problem.

This can be seen poorly, because you must either use real parsing or get data in a non-linear format.

0
source

All Articles