DEV Community

Cover image for I prefer not to use the keyword “it”
le0nidas
le0nidas

Posted on • Originally published at le0nidas.gr on

I prefer not to use the keyword “it”

And the reason is simple:

I want to be as explicit as possible and allow the reader of my code to have an uninterrupted flow.

Think about it. Every time you encounter the it keyword you do, a quick, conversion between what you see and what it represents. Personally I do it even in very small lambdas, imagine if you are two or three lines deep in a lambda and you see an it:

It might not look much in this simple example but read it now with an explicit value:

You don’t have to do a mental translation and it also provides some details regarding the format of username.

This last part can make the code even more readable since it allows us to describe the values we use:

this hints that (a) values list does not contain usable data and (b) the of function will perform some kind of cleaning

Top comments (1)

Collapse
 
jillesvangurp profile image
Jilles van Gurp

It's not a keyword; it's a variable name. And you can refactor it to whatever simply by renaming. If you have nested blocks, you will get a warning about name shadowing if you don't do that. And of course you should not tolerate any warnings.

Your last example, you could shorten to

values.map(Name::of)
Enter fullscreen mode Exit fullscreen mode