8

So, this is apparently how you concatenate a list of Strings or should I say cities πŸ˜‰ (with a delimiter between each element but excluding the last one)

I wish my esteemed colleague at least had decency to hide the fact he copied it from SO 😭

Question: what's wrong with this code❓

Comments
  • 1
    The language
  • 3
    Also why the fuck is the function called toString?!?
  • 0
    just a guess: substring is deleting the last one character from the last "city" as well
  • 2
    Woaaaah so much complicated for just:

    ','. Join(cities)
    ... Dear java you run on more than 3 billions hardwares, but you're still so uncomfortable to dev with!
  • 5
    @lumy The problem in this instance isn't Java. It's the developer.
    You can do the exact same thing in under five lines of code.
  • 1
    @for-Each It definitely is busier then it should be. Too much dependence on for loops will get you in trouble quickly.
  • 4
    Let me have a stab at what I consider wrong here. Please feel free to correct me on any of the points or add more to it :)

    0. Method name (10pts to @Skayo)

    1. No JavaDocs (sorry, I'm a stickler)

    2. Clearly copied someone's sample that concatenates cities and didn't even bother to generify the "city" variable

    3. StringBuilder is a FUCKING builder, why not use it as such: builder.append(city).append(delimiter)

    4. Annotating method args with @NonNull in util methods and then bubbling up NPEs is just lazy. Own your fucking code!!!

    5. Any reason for not using TextUtils.join() from Android API (since API 1) or Arrays.join() from Java8? Or Kotlin Array.joinToString()?
  • 1
    String.join(delimiter, list)
    Please.
  • 1
Add Comment