SpartanRefactoring / Main

Eclipse plugin that performs automatic refactoring of Java source code, making it shorter, more idiomatic and more readable
https://www.spartan.org.il
100 stars 56 forks source link

Correction of Ternarization.md #1626

Open wei-yuan opened 7 years ago

wei-yuan commented 7 years ago

Hi guys Thanks for your tutorial But I believe there might have something missing here in Ternarization.md

Here is another example, taken from the JTL code development. The following code excerpt uses the string s twice.

if (tail.isEmpty())
    return s;
return s + ":" + tail.toString();

to

if (tail.isEmpty())
    return s;
else
    return s + ":" + tail.toString();

Correction file here

OriRoth commented 7 years ago

I think the idea was to take a real world example (JTL) (i.e. existing code). Otherwise the two cases are identical and both can be spartanized. Is there something I missed? Anyway thanks for your interest.

OriRoth commented 7 years ago

BTW the spartanization here can be incorrect in some contexts; the original code can return null while the spartanized version cannot. I think the current version of the spartanizer only merges the statements without pushing down the ternary operator:

return tail.isEmpty() ? s : s + ":" + tail.toString();
wei-yuan commented 7 years ago

@OriRoth Thx for reply, I just want to make sure I didn't misunderstand anything