SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Guru augathra's Avatar
    Join Date
    Jul 2004
    Location
    united states
    Posts
    826
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Ternary operators

    Would using the ternary operator make scripts more efficient?

  2. #2
    Non-Member
    Join Date
    Oct 2004
    Location
    Net
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe.

  3. #3
    SitePoint Wizard Mike Borozdin's Avatar
    Join Date
    Oct 2002
    Location
    Edinburgh, UK
    Posts
    1,743
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It depens on what you mean by word 'efficient'. If you mean performance, you can check it yourself by using the micrtotime () function, if you mean just coding organisation, then it's recommend to use ternanry operator instead of if-else statement, it just take 1 line for tenrary operator.

  4. #4
    SitePoint Guru augathra's Avatar
    Join Date
    Jul 2004
    Location
    united states
    Posts
    826
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I see. Ternary does seem more organized, but when I need to scan someone elses code or read a large sheet of my own, it seems like they would be harder to find, even with comments. /shrug

    I believe I will start using them though, just to get the feeling of both sides.

    Thanks for the replies.

  5. #5
    SitePoint Guru augathra's Avatar
    Join Date
    Jul 2004
    Location
    united states
    Posts
    826
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh, and the ternary way was 1/1000 of a second faster.
    So, 1000 if statements = 1 second faster script!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •