Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. userid=="administrator"

userid=="administrator"

Scheduled Pinned Locked Moved The Weird and The Wonderful
career
13 Posts 9 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Tadas Budvytis

    if (Session["UserID"] != null && Session["UserID"].ToString() == "administrator") { adminRight = "W"; } return adminRight; well first of all if it's UserID i expect it to be number, ok somebody squeezed here 'administrator' nice job. Another thing is if userID == 'administrator' it cant be in any case at the same time null.

    T Offline
    T Offline
    Tadas Budvytis
    wrote on last edited by
    #4

    for some reason i was sure that in C# oposed to C+ there are no garantees in what order (if) conditions will be compiled and executed later. Seems it's done in good way. That's good. but UserID='administrator' this wrong, i can understand that if userID is a userCODE like 'BDWR' or so but in our case in 99% it's used as a number.

    R P L 3 Replies Last reply
    0
    • T Tadas Budvytis

      for some reason i was sure that in C# oposed to C+ there are no garantees in what order (if) conditions will be compiled and executed later. Seems it's done in good way. That's good. but UserID='administrator' this wrong, i can understand that if userID is a userCODE like 'BDWR' or so but in our case in 99% it's used as a number.

      R Offline
      R Offline
      Robert Royall
      wrote on last edited by
      #5

      I'm pretty sure all C# boolean evaluations (including if) are short-circuiting, so I don't see how the block could be evaluated out of order.

      Imagine that you are hired to build a bridge over a river. The river gets slightly wider every day; sometimes it shrinks but nobody can predict when. Your contract says you can't use concrete or steel - the client only provides timber and cut stone (but won't tell you what kind). Gravity changes from hour to hour, as does the viscosity of air. Your only tools are a hacksaw, a chainsaw, a rubber mallet, and a length of rope. Welcome to my world. -Me explaining my job to an engineer

      M M 2 Replies Last reply
      0
      • R Robert Royall

        I'm pretty sure all C# boolean evaluations (including if) are short-circuiting, so I don't see how the block could be evaluated out of order.

        Imagine that you are hired to build a bridge over a river. The river gets slightly wider every day; sometimes it shrinks but nobody can predict when. Your contract says you can't use concrete or steel - the client only provides timber and cut stone (but won't tell you what kind). Gravity changes from hour to hour, as does the viscosity of air. Your only tools are a hacksaw, a chainsaw, a rubber mallet, and a length of rope. Welcome to my world. -Me explaining my job to an engineer

        M Offline
        M Offline
        Mladen Jankovic
        wrote on last edited by
        #6

        Simply called "lazy evaluation". BTW, great signature! :)

        Mostly, when you see programmers, they aren't doing anything. One of the attractive things about programmers is that you cannot tell whether or not they are working simply by looking at them. Very often they're sitting there seemingly drinking coffee and gossiping, or just staring into space. What the programmer is trying to do is get a handle on all the individual and unrelated ideas that are scampering around in his head. (Charles M Strauss)

        R 1 Reply Last reply
        0
        • M Mladen Jankovic

          Simply called "lazy evaluation". BTW, great signature! :)

          Mostly, when you see programmers, they aren't doing anything. One of the attractive things about programmers is that you cannot tell whether or not they are working simply by looking at them. Very often they're sitting there seemingly drinking coffee and gossiping, or just staring into space. What the programmer is trying to do is get a handle on all the individual and unrelated ideas that are scampering around in his head. (Charles M Strauss)

          R Offline
          R Offline
          Robert Royall
          wrote on last edited by
          #7

          Yours isn't so bad yourself! :-D

          Imagine that you are hired to build a bridge over a river. The river gets slightly wider every day; sometimes it shrinks but nobody can predict when. Your contract says you can't use concrete or steel - the client only provides timber and cut stone (but won't tell you what kind). Gravity changes from hour to hour, as does the viscosity of air. Your only tools are a hacksaw, a chainsaw, a rubber mallet, and a length of rope. Welcome to my world. -Me explaining my job to an engineer

          B 1 Reply Last reply
          0
          • R Robert Royall

            I'm pretty sure all C# boolean evaluations (including if) are short-circuiting, so I don't see how the block could be evaluated out of order.

            Imagine that you are hired to build a bridge over a river. The river gets slightly wider every day; sometimes it shrinks but nobody can predict when. Your contract says you can't use concrete or steel - the client only provides timber and cut stone (but won't tell you what kind). Gravity changes from hour to hour, as does the viscosity of air. Your only tools are a hacksaw, a chainsaw, a rubber mallet, and a length of rope. Welcome to my world. -Me explaining my job to an engineer

            M Offline
            M Offline
            MarkB777
            wrote on last edited by
            #8

            Robert Royall wrote:

            I'm pretty sure all C# boolean evaluations (including if) are short-circuiting,

            Yea thats correct.

            Mark Brock Click here to view my blog

            1 Reply Last reply
            0
            • T Tadas Budvytis

              if (Session["UserID"] != null && Session["UserID"].ToString() == "administrator") { adminRight = "W"; } return adminRight; well first of all if it's UserID i expect it to be number, ok somebody squeezed here 'administrator' nice job. Another thing is if userID == 'administrator' it cant be in any case at the same time null.

              B Offline
              B Offline
              Brady Kelly
              wrote on last edited by
              #9

              You'll get a runtime error calling ToString on a null reference, and the null check avoids this.

              Semicolons: The number one seller of ostomy bags world wide. - dan neely

              1 Reply Last reply
              0
              • R Robert Royall

                Yours isn't so bad yourself! :-D

                Imagine that you are hired to build a bridge over a river. The river gets slightly wider every day; sometimes it shrinks but nobody can predict when. Your contract says you can't use concrete or steel - the client only provides timber and cut stone (but won't tell you what kind). Gravity changes from hour to hour, as does the viscosity of air. Your only tools are a hacksaw, a chainsaw, a rubber mallet, and a length of rope. Welcome to my world. -Me explaining my job to an engineer

                B Offline
                B Offline
                Brady Kelly
                wrote on last edited by
                #10

                :laugh:

                Semicolons: The number one seller of ostomy bags world wide. - dan neely

                1 Reply Last reply
                0
                • T Tadas Budvytis

                  for some reason i was sure that in C# oposed to C+ there are no garantees in what order (if) conditions will be compiled and executed later. Seems it's done in good way. That's good. but UserID='administrator' this wrong, i can understand that if userID is a userCODE like 'BDWR' or so but in our case in 99% it's used as a number.

                  P Offline
                  P Offline
                  PIEBALDconsult
                  wrote on last edited by
                  #11

                  Tadas Budvytis wrote:

                  99% it's used as a num

                  I doubt that very much. Would you perform mathematical operations on it?

                  1 Reply Last reply
                  0
                  • T Tadas Budvytis

                    if (Session["UserID"] != null && Session["UserID"].ToString() == "administrator") { adminRight = "W"; } return adminRight; well first of all if it's UserID i expect it to be number, ok somebody squeezed here 'administrator' nice job. Another thing is if userID == 'administrator' it cant be in any case at the same time null.

                    O Offline
                    O Offline
                    Oshtri Deka
                    wrote on last edited by
                    #12

                    No horror here. :confused:

                    Tadas Budvytis wrote:

                    well first of all if it's UserID i expect it to be number

                    ID is shorter for IDentification, it can be numerical value, GUID, string... almost anything programmer wants. It's common thing for naming primary keys in RDB-s with Something + ID and usually these ID-s are integers, but that convention can be misleading for beginners. Sometimes it's better to use other types, string or guid for instance and different naming conventions.

                    modified on Monday, June 2, 2008 9:05 AM

                    1 Reply Last reply
                    0
                    • T Tadas Budvytis

                      for some reason i was sure that in C# oposed to C+ there are no garantees in what order (if) conditions will be compiled and executed later. Seems it's done in good way. That's good. but UserID='administrator' this wrong, i can understand that if userID is a userCODE like 'BDWR' or so but in our case in 99% it's used as a number.

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #13

                      I had the same objection to this while going through some code with the boss many years ago. I always checked for null separately before doing anything else. He did it just the same way like in the code here. He argued that the check for null values is always done first and does not run into the second term if the value is indeed null. This may not be sound proof, but the entire code was full of this and we never had any problems because of that.

                      A while ago he asked me what he should have printed on my business cards. I said 'Wizard'. I read books which nobody else understand. Then I do something which nobody understands. After that the computer does something which nobody understands. When asked, I say things about the results which nobody understand. But everybody expects miracles from me on a regular basis. Looks to me like the classical definition of a wizard.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups