Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correction of Ternarization.md #1626

Open
wei-yuan opened this issue Sep 1, 2017 · 3 comments
Open

Correction of Ternarization.md #1626

wei-yuan opened this issue Sep 1, 2017 · 3 comments
Assignees

Comments

@wei-yuan
Copy link

wei-yuan commented Sep 1, 2017

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 OriRoth self-assigned this Sep 1, 2017
@OriRoth
Copy link
Collaborator

OriRoth commented Sep 1, 2017

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
Copy link
Collaborator

OriRoth commented Sep 1, 2017

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
Copy link
Author

wei-yuan commented Sep 2, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants