Results 1 to 10 of 10

Thread: [RESOLVED] Any difference with parenthesis?

  1. #1

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,104

    Resolved [RESOLVED] Any difference with parenthesis?

    I was translating a vb.net code and since the not and the and the stuff are easy to miss I passed it into a translator just to be sure.
    So this ended up with a code with double parenthesis from the translator.
    So is there any difference ?

    Code:
    //me
       if (!Uroles.IsAdmin && !Uroles.IsGUser) this.Response.Redirect("~/Default.aspx");    
    
    //translator
            if ((!Uroles.IsAdmin && !Uroles.IsGUser))
            {
                this.Response.Redirect("~/Default.aspx");
            }
    The original was:

    If Not URoles.IsAdmin And Not URoles.IsGUserThen Me.Response.Redirect("~/Default.aspx")
    .

  2. #2
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,653

    Re: Any difference with parenthesis?

    Both are Valid,

    The Parenthesis are required if you have multiple lines after your if statement e.g.

    if ((!Uroles.IsAdmin && !Uroles.IsGUser))
    {
    log.Write("Invalid Login");
    this.Response.Redirect("~/Default.aspx");
    }
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  3. #3
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    33,587

    Re: Any difference with parenthesis?

    The double parens feels like overkill to me... Not sure why it did that for you, clearly they were already there. Other than that, it's basically a stylistic choice as to the use of the curly braces. Personally I use them because then it's easier to add additional lines for what ever reason down the road.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    CT
    Posts
    18,130

    Re: Any difference with parenthesis?

    Quote Originally Posted by techgnome View Post
    Personally I use them because then it's easier to add additional lines for what ever reason down the road.
    Exactly why I do the same thing. It's all about maintainability when you come back to visit later and make changes.

    I actually auto-stub out the IF like this...

    Code:
    if (true) {
    
    }
    ...Just so it's nice and indented and in the right spot...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  5. #5

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,104

    Re: Any difference with parenthesis?

    Thanks.

    I'm a little confused on what some said.
    Isn't this valid?

    Code:
    if (!Uroles.IsAdmin && !Uroles.IsGUser)
    {
    log.Write("Invalid Login");
    this.Response.Redirect("~/Default.aspx");
    }
    Or I'm missing something?


    I think szlamany is answering on C# but is thinking Javascript
    .

  6. #6
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    CT
    Posts
    18,130

    Re: Any difference with parenthesis?

    Quote Originally Posted by sapator View Post
    I think szlamany is answering on C# but is thinking Javascript
    Yup! Guilty as charged!

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  7. #7
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    33,587

    Re: Any difference with parenthesis?

    Quote Originally Posted by sapator View Post
    Thanks.

    I'm a little confused on what some said.
    Isn't this valid?

    Code:
    if (!Uroles.IsAdmin && !Uroles.IsGUser)
    {
    log.Write("Invalid Login");
    this.Response.Redirect("~/Default.aspx");
    }
    Or I'm missing something?


    I think szlamany is answering on C# but is thinking Javascript
    Yes, it's perfectly valid... that's why I'm a little confused as to why the translator added more parens to it... unless it just blindly did it.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,104

    Re: Any difference with parenthesis?

    OK.
    Thanks.
    .

  9. #9
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,611

    Re: Any difference with parenthesis?

    Quote Originally Posted by szlamany View Post
    Exactly why I do the same thing. It's all about maintainability when you come back to visit later and make changes.

    I actually auto-stub out the IF like this...

    Code:
    if (true) {
    
    }
    ...Just so it's nice and indented and in the right spot...
    well... c# coding standards put the opening curly bracket on a new line.

  10. #10
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    CT
    Posts
    18,130

    Re: Any difference with parenthesis?

    Quote Originally Posted by Lord Orwell View Post
    well... c# coding standards put the opening curly bracket on a new line.
    Sapator figured out I was in the wrong room, lol!

    Quote Originally Posted by sapator View Post
    I think szlamany is answering on C# but is thinking Javascript

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

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



Click Here to Expand Forum to Full Width