Render unto the optimizer that which is optimizer's

I was debugging an exception in our app which is running the minifed build (uglifyjs).
Thanks to Chrome, {} allows you to unscramble minified code, so at least its more readable to the human eye

Our code was:
                    if (seller.state === 'New') {
                        model.readonly = true;
                    }

the minifier converted it to:

                "New" === seller.state && (model.readonly = !0)

pretty neat eh! an interesting way to write an if statement.

However before rushing to adopt that as a style think about how easy both are to understand. As developers we should try to write code that's easy for others to understand

I could write a cool looking if statement as the minifier did...but that's not as understandable to a human as the original version. Usually, over time, all your team will be reading and changing your code.

Write good clear, understandable code. Let the optimizer optimize it.

p.s. we're cleaning up the literal "New"

Comments

Popular posts from this blog

deep dive into Material UI TextField built by mui

angular js protractor e2e cheatsheet

react-router v6.4+ loaders, actions, forms and more