Jump to content

Short-hand if statements, better or not?


vineld

Recommended Posts

I have not really began using the short-hand if statements with question marks and colons myself, mostly because I think it makes the code more difficult to read for others, but I am wondering why those of you who use it have chosen to do so? Is it just to shorten the code?

 

Performance-wise, which alternative is best, if any?

Link to comment
Share on other sites

Performance-wise, which alternative is best, if any?

I ran some tests a while back, and found it was fractionally slower using the ternary operator than writing out the full if statement in longhand. Quite why this should be, I don't know.... I'd expected to find that both forms compiled to the same code.

 

Link to comment
Share on other sites

I absolutely HATE the shorthand if statements.  In my opinion they make things so much harder to read and digest when you're trying to debug something.  However, I can't speak to whether or not they are more or less efficient.  I would think they would be more efficient but I can't say for sure.

Link to comment
Share on other sites

Performance-wise, which alternative is best, if any?

I ran some tests a while back, and found it was fractionally slower using the ternary operator than writing out the full if statement in longhand. Quite why this should be, I don't know.... I'd expected to find that both forms compiled to the same code.

 

Thanks for the input, fractionally slower would mean that it doesn't really matter which one you use then. Even if they compile to the same code they will still need to be parsed and that's probably wherein the difference lies.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.