Today I had a comment on a code review which left me pretty confused.

I would really appreciate if some of you coders out there (some of which have written books and that :) ) could share your thoughts.

The questions are:

1. Is there a code smell here?

2. Do we really need to make variables out of duplicated strings under ALL circumstances?

I have an example here

https://lnkd.in/ejrRnCgZ

The documentation the reviewer presented to back up their argument is here: (I know it's for Go, but should still apply)

https://lnkd.in/e82Y_5tz

They have a compelling case, but from my experience, the closest thing I can come up with in terms of code smells, its the "primitive obsession", but that doesn't quite apply.

Please help?

nostr:npub19mun7qwdyjf7qs3456u8kyxncjn5u2n7klpu4utgy68k4aenzj6synjnft, nostr:npub1l2vyh47mk2p0qlsku7hg0vn29faehy9hy34ygaclpn66ukqp3afqutajft

Reply to this note

Please Login to reply.

Discussion

Sorry... I forgot about the links from Linkedin. Here they are in normal format

https://pastebin.com/vtqC5162

and

https://rules.sonarsource.com/go/RSPEC-1192/

From: (ThyLobster) at 01/05 11:39

>

> The questions are:

> 1. Is there a code smell here?

Yes, but it's not a big one. Personally, in the case you presented, I would keep the duplicated string for two reasons. First, it reads better. Second, I do not trust that the two strings will remain duplicated. Some marketting or UI Designer will likely want to rephrase them and could easily make them different.

> 2. Do we really need to make variables out of duplicated strings under ALL circumstances?

No. I would take it case by case.

CC: #[3]

CC: #[4]

Thank you!

In the example I added, the string repeats twice, but in the real case, it repeats 25 times. But other lines also duplicate 2 or 3 times.

I just don't think we should make it ugly, less readable, more complex... So I guess we agree.

Thanks again.