Skip to content

Just wanted to share this code gem

September 22, 2009

I spotted this in some ASP.NET today:


if (confirm("Are you sure?")==true)
return true;
else
return false;

You never need to compare something to true though:


if (confirm("Are you sure?"))
return true;
else
return false;

And the whole if-boolean-then-boolean construct can be refactored out:


return confirm("Are you sure?")

It’s less to maintain, less to look at, and simpler to understand. That is all.

Advertisement
No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

Gravatar
WordPress.com Logo

Please log in to WordPress.com to post a comment to your blog.

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.