NewPipeExtractor icon indicating copy to clipboard operation
NewPipeExtractor copied to clipboard

Why does EMPTY_STRING exist?

Open Stypox opened this issue 3 years ago • 1 comments

This is a followup to my joke PR #825. The reason I made that PR was to emphasize the fact that storing "" in a constant variable and then using that variable throughout the code is imo completely pointless.

  • If we are doing this for optimization purposes -> we are not optimizing anything. JVM already does this for us: https://www.tutorialspoint.com/how-and-where-does-string-literals-in-java-stored-in-the-memory.
  • If we are doing this for clarity -> I personally find "" clearer, more standard and more recognizable than EMPTY_STRING that sometimes could also appear as Utils.EMPTY_STRING and from a first look looks like a non-empty constant string. "" can be considered a constant for which no name is needed, just like 0 (while it would be a good idea to give a name to the various -1 scattered about in the extractor), and anyway the name EMPTY_STRING doesn't give any more information than just "".
  • Importing EMPTY_STRING in all files increases the bytecode size (though this would really be just a minor problem)

I can only find downsides for EMPTY_STRING to exist and I would therefore remove it completely.

Stypox avatar Apr 30 '22 14:04 Stypox

Note: This was introduced with https://github.com/TeamNewPipe/NewPipeExtractor/pull/287 / https://github.com/TeamNewPipe/NewPipeExtractor/commit/00d1ed439b49cdbabcd6933afd7945bc45e9aefc#diff-8fd4eab23bfbb031a3e5af338eb2e9814c1a7fcef5862a192566dfed8ccb474e

I'm also in favor of removing it.

litetex avatar May 01 '22 13:05 litetex