cheptsov / AdvancedExpressionFolding

https://plugins.jetbrains.com/plugin/9320?pr=idea
141 stars 30 forks source link

stringVar[0] folded to stringVar.first() #72

Closed petteyg closed 7 years ago

petteyg commented 7 years ago

It's not really a great fold if the resulting text is longer than the original code :)

ciscorucinski commented 7 years ago

As a standalone example, it would seem to be a bad fold; however, shorter does not always mean better. In this case, the ever so slightly longer folded text provided a very good description of what you wanted to get.... You wanted the first item in the array.

Plus, this fold is paired with last() and last is much shorter than .getSize() - 1 or .length - 1.

On Fri, Jun 23, 2017, 5:23 AM Gordon notifications@github.com wrote:

It's not really a great fold if the resulting text is longer than the original code :)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/cheptsov/AdvancedExpressionFolding/issues/72, or mute the thread https://github.com/notifications/unsubscribe-auth/AITcNXBMNZ5qsrWCNT6Gsv3S_8pc6bGpks5sGs0sgaJpZM4OCzMR .

petteyg commented 7 years ago

String[] ss = StringUtils.split("I will. always have. three dots. in here", '.'); String ss0 = ss[0]; String ss1 = ss[1]; String ss2 = ss[2];

There is no "last()" fold if I'm not using getSize() -1, and to be blunt, if you can't tell that element 0 is the "first()" element, you have no business coding.

cheptsov commented 7 years ago

Sometimes I have similar feelings. Do you think it makes sense to remove the ".first()" folding but keep ".last()"?

petteyg commented 7 years ago

last() is always shorter and more concise in its meaning, so as a "fold" it makes plenty of sense.

ciscorucinski commented 7 years ago

I think the first fold is useful. Personally, you should expand it to other indexes; not take this away!

The human mind is use to positional notation; only in computers do you use an unintuitive zero-based cardinality. That is why languages have implemented the first notation for indexes.

In the given example above, it is way more intuitive to see the fold...

int a = ss.first();
int b = ss.second();
int c = ss.third();

Or something more precise...

int a = ss.1st();
int b = ss.2nd();
int c = ss.3rd();

If a user accidentally used a one-based index instead of a zero-based index, then a user would see the following issue before even running the code..

int a = ss.2nd();   // ss[1]; instead of ss[0]
int b = ss.3rd();   // ss[2];
int c = ss.4th();   // ss[3];

This would be a huge lose if you got rid of first or didn't make it more concise as indicated above. As noted above, you can allow a user to disable this fold in particular.

Also, the point of this plugin is not to be concise, but to be concise and expressive. First is very expressive but 0 is more concise. 1st() or 1st is a good compromise of both concise and expressive (especially expressive).

cheptsov commented 7 years ago

I dropped .first and kept .last