DEV Community

Discussion on: You changed the code, you didn't refactor the code.

Collapse
 
silkcom profile image
Silkcom

Refactoring should also aim to make something either 1) more readable, 2) more performant (because of an actual need to make it more performant), or 3) more flexible to changes that have happened in the past. The code change above fails all 3. It's harder to understand what's happening thus making it less flexible to changes that may be needed in the future.

There is nothing special about a 1 liner (it's what I call "clever coding" always with the quotes, and it's a really bad practice). A computer can read 10 lines really really quickly, and it generally takes as long or longer for a human to decipher what the 1 liner actually does vs the 10 line equivalent.

Collapse
 
marc_m_b profile image
marc_m_b

Great comment, some people still/will continue to think that "one line" is a huge performance optimization

Collapse
 
samipietikainen profile image
Sami Pietikäinen

I couldn't agree more about one-liners. Also using "tricks", little-known features and other "clever" stuff usually just makes the code harder to comprehend. IMHO the code example above doesn't really need refactoring anyway.