SPONSORS:






User Tag List

Results 1 to 8 of 8
  1. #1
    Senior Member
    Join Date
    Jul 1999
    Location
    Burlingame CA 94010
    Posts
    502
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Coding Challenge #1

    Write a function that returns one of the following strings depending on the current browser state.

    "Active" - Browser is active
    "Inactive" - Browser is inactive
    "Doesn't Exist" - Browser doesn't exist

    Here's the tough part.

    Write the entire function contents in ONE line.

    Here's the function header.

    STRING GetBrowserState ()



  2. #2
    Member
    Join Date
    Feb 2002
    Location
    Overland Park, KS
    Posts
    39
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Coding Challenge #1

    Well, here goes.

    return (TRUE == Browser.Exists () ? (TRUE == Browser.IsActive () ? "Active" : "Inactive") : "Doesn't Exist")

    I'll be honest, I hate looking at these conditional statements...

    ------------------

  3. #3
    Senior Member
    Join Date
    Jul 1999
    Location
    Burlingame CA 94010
    Posts
    502
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Coding Challenge #1

    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by robbed:
    Well, here goes.

    return (TRUE == Browser.Exists () ? (TRUE == Browser.IsActive () ? "Active" : "Inactive") : "Doesn't Exist")

    I'll be honest, I hate looking at these conditional statements...

    <HR></BLOCKQUOTE>


    Perfect, with a slight modification. The 'TRUE ==' are redundant. Exists () and IsActive () are BOOLEAN statements already.

    return (Browser.Exists () ? (Browser.IsActive () ? "Active" : "Inactive") : "Doesn't Exist")


    ------------------
    John W Green
    jwgreen@automationexpertise.com
    http://www.automationexpertise.com

  4. #4
    Member
    Join Date
    Mar 2002
    Location
    Pune, MH, India
    Posts
    41
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Coding Challenge #1

    Hi,

    My thoughts.

    Although TRUE is redundant it improves
    readability.

    As robbed rightly pointed out, writing
    such code is good exercise but have
    poor redability.

    [Niteen]



    ------------------

  5. #5
    Senior Member
    Join Date
    Jul 1999
    Location
    Burlingame CA 94010
    Posts
    502
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Coding Challenge #1

    One line immediate if statements can make code more readable. Consider the following.


  6. #6
    Member
    Join Date
    Feb 2002
    Location
    Overland Park, KS
    Posts
    39
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Coding Challenge #1

    What if iCount is 0? Or negative?

    But seriously, I don't have a problem reading the above. I think that's an appropriate use of the conditional. I tend to have problems reading nested conditionals with calls to functions containing 3 or 4 parameters each. That's when it becomes abusive, IMNSHO.

    rob


    ------------------

  7. #7
    Senior Member
    Join Date
    Jul 1999
    Location
    Burlingame CA 94010
    Posts
    502
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Coding Challenge #1

    If count is zero, it will say 0 messages, if negative, -5 messages. This shouldn't cause a problem.

    I think it's a good tool to have in your toolbox for certain situations.




  8. #8
    Member
    Join Date
    Feb 2002
    Location
    Overland Park, KS
    Posts
    39
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Coding Challenge #1

    Oh, you're right. I didn't think it through before writing about the 0 and -5 numbers...

    ------------------

 

 

Posting Permissions

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

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.0.9 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Questions / Answers Form provided by vBAnswers (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominatevBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 07:12 AM.

Copyright BetaSoft Inc.