Order Of Arguments In Expressions


Recommended Posts

This is perhaps "just" a style question; however, even for matters of style that fall into the 'personal preference' category, there must be a rationale. (Mustn't there?)

I am interested in why, given a variable, an operator and a value, people choose to write either

if (variable operator value) -- e.g., if (myItn == 0)

or

if (value operator variable) -- e.g., if (0 == myInt)

I have a strong personal preference on this matter, for which I have a well-thought-out rationale and from which I never vary, and although I have seem many examples of the opposite order, I have never been apprised of the rationale for it.

Which order is your choice, and why?

Thanks in advance for your response.

Link to post
Share on other sites
if (variable operator value) -- e.g., if (myItn == 0)

Usually reads more naturally.

if (value operator variable) -- e.g., if (0 == myInt)

Catches ==/= typos.

Which order is your choice, and why?

The former. Prefer the way it reads, never had trouble avoiding typos, often use assignment in conditionals.

Edited by jcl
Link to post
Share on other sites
  • 1 month later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...