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. I fix it!!!111

I fix it!!!111

Scheduled Pinned Locked Moved The Weird and The Wonderful
helptutorialquestionannouncementcode-review
14 Posts 8 Posters 0 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.
  • S Slacker007

    what about handling null values for new and old data parameters? this has bitten me in the ass before.

    C Offline
    C Offline
    Claies
    wrote on last edited by
    #3

    pretty soon all the data in the database will be =false

    1 Reply Last reply
    0
    • S Slacker007

      what about handling null values for new and old data parameters? this has bitten me in the ass before.

      B Offline
      B Offline
      BuggyTimes
      wrote on last edited by
      #4

      The code is sufficient in this case not to check for null :). The parameters passed are from an event, and the function is called when the field it is bound to changes. Additionally the apiCall function doesn't change anything, but the overhead of making a request to the api should be avoided, hence it's wrapped in an if statement.

      1 Reply Last reply
      0
      • B BuggyTimes

        We have two functions apiCall and handleChangeEvent. The simplified version below.

        function apiCall() {
        // smart stuff here
        }

        function handleChangeEvent(newData,oldData) {
        if(newData !== oldData)
        {
        apiCall();
        }
        }

        One of my colleagues reports they have a problem with apiCall not being called from handleChangeEvent because of the if condition. They claim that the event is sometimes handled and sometimes not. Suspicious claim, as the apiCall code can be triggered from other locations, but it's an issue they should be able to handle so I didn't investigate further. Later the cheery colleague says they solved the issue and I decided to review their code. I take a look at their work from time to time to help improve their code and this is the solution they came up with:

        function handleChangeEvent(newData,oldData) {
        newData = !oldData;
        if(newData !== oldData)
        {
        apiCall();
        }
        }

        :wtf: :(( I told them that this is not the way to solve the issue, and took the time to show them that that apiCall was in fact called from another location. I also gave them a few solutions that could be made and left to take a break. I hope to help guide them, but I fear that there is no helping them :sigh: . I'm still puzzled and angry that someone would write such a solution!?

        R Offline
        R Offline
        Ray Raymos
        wrote on last edited by
        #5

        It looks fine syntax wise however you should add what the solution is meant to do. If this is dealing with a database or with some form of data than parameters should be put there. Someone did say Null values and that can come with some downsides. With handling data some limitations should be added. However as I said I have no idea what data the function is trying to deal with. All I know is that it handles two objects. One newData and Two oldData. I know that if newData and oldData are the same than it will be false and in that instance the API would be called. Could you go in depth a little bit further or what type of data you are dealing with.

        B 1 Reply Last reply
        0
        • B BuggyTimes

          We have two functions apiCall and handleChangeEvent. The simplified version below.

          function apiCall() {
          // smart stuff here
          }

          function handleChangeEvent(newData,oldData) {
          if(newData !== oldData)
          {
          apiCall();
          }
          }

          One of my colleagues reports they have a problem with apiCall not being called from handleChangeEvent because of the if condition. They claim that the event is sometimes handled and sometimes not. Suspicious claim, as the apiCall code can be triggered from other locations, but it's an issue they should be able to handle so I didn't investigate further. Later the cheery colleague says they solved the issue and I decided to review their code. I take a look at their work from time to time to help improve their code and this is the solution they came up with:

          function handleChangeEvent(newData,oldData) {
          newData = !oldData;
          if(newData !== oldData)
          {
          apiCall();
          }
          }

          :wtf: :(( I told them that this is not the way to solve the issue, and took the time to show them that that apiCall was in fact called from another location. I also gave them a few solutions that could be made and left to take a break. I hope to help guide them, but I fear that there is no helping them :sigh: . I'm still puzzled and angry that someone would write such a solution!?

          C Offline
          C Offline
          CHill60
          wrote on last edited by
          #6

          As a matter of curiosity what language is that in? I've never seen that construct !== before

          Z L 2 Replies Last reply
          0
          • C CHill60

            As a matter of curiosity what language is that in? I've never seen that construct !== before

            Z Offline
            Z Offline
            ZurdoDev
            wrote on last edited by
            #7

            Probably javascript. 1 == "1" will be true in JavaScript because == casts objects to a common type. However 1 === "1" is false since one is int and the other is string. === does not cast objects. !== will be not equal to without casting of objects. If you're sure both sides of the operand are of the same type then using === or !== will be faster.

            There are only 10 types of people in the world, those who understand binary and those who don't.

            C R B 3 Replies Last reply
            0
            • Z ZurdoDev

              Probably javascript. 1 == "1" will be true in JavaScript because == casts objects to a common type. However 1 === "1" is false since one is int and the other is string. === does not cast objects. !== will be not equal to without casting of objects. If you're sure both sides of the operand are of the same type then using === or !== will be faster.

              There are only 10 types of people in the world, those who understand binary and those who don't.

              C Offline
              C Offline
              CHill60
              wrote on last edited by
              #8

              Cheers for that!

              1 Reply Last reply
              0
              • R Ray Raymos

                It looks fine syntax wise however you should add what the solution is meant to do. If this is dealing with a database or with some form of data than parameters should be put there. Someone did say Null values and that can come with some downsides. With handling data some limitations should be added. However as I said I have no idea what data the function is trying to deal with. All I know is that it handles two objects. One newData and Two oldData. I know that if newData and oldData are the same than it will be false and in that instance the API would be called. Could you go in depth a little bit further or what type of data you are dealing with.

                B Offline
                B Offline
                BuggyTimes
                wrote on last edited by
                #9

                The actual data passed is a timestamp when a change has happened. The handleChangeEvent function is an event handler bound to a field, like an input field onchange event in the browser. The framework takes care of when to call this function, and then the control takes responsibility of what needs to happen. The point of my semi-rant being that the dev in question tried to fix a problem by doing the wrong thing in the wrong place :)

                F 1 Reply Last reply
                0
                • Z ZurdoDev

                  Probably javascript. 1 == "1" will be true in JavaScript because == casts objects to a common type. However 1 === "1" is false since one is int and the other is string. === does not cast objects. !== will be not equal to without casting of objects. If you're sure both sides of the operand are of the same type then using === or !== will be faster.

                  There are only 10 types of people in the world, those who understand binary and those who don't.

                  R Offline
                  R Offline
                  Ray Raymos
                  wrote on last edited by
                  #10

                  I was thinking the same thing ,because you can automatically rule out Vb.net due to structure. You can rule out C# due to operator types involved. There are some serious violations with C#,C++,C,Objective C and Java. I felt confused by the extended/longer operator types. Good call on it being javascript!

                  1 Reply Last reply
                  0
                  • C CHill60

                    As a matter of curiosity what language is that in? I've never seen that construct !== before

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

                    PHP or JavaScript is my best guess.

                    The first step in the acquisition of wisdom is SILENCE, the second is LISTENING, the third MEMORY, the forth, PRACTICE and the fifth is TEACHING others!

                    1 Reply Last reply
                    0
                    • B BuggyTimes

                      The actual data passed is a timestamp when a change has happened. The handleChangeEvent function is an event handler bound to a field, like an input field onchange event in the browser. The framework takes care of when to call this function, and then the control takes responsibility of what needs to happen. The point of my semi-rant being that the dev in question tried to fix a problem by doing the wrong thing in the wrong place :)

                      F Offline
                      F Offline
                      Freak30
                      wrote on last edited by
                      #12

                      Why does the object even support a logical not operator and what is it supposed to do to the object?

                      The good thing about pessimism is, that you are always either right or pleasently surprised.

                      B 1 Reply Last reply
                      0
                      • F Freak30

                        Why does the object even support a logical not operator and what is it supposed to do to the object?

                        The good thing about pessimism is, that you are always either right or pleasently surprised.

                        B Offline
                        B Offline
                        BuggyTimes
                        wrote on last edited by
                        #13

                        It doesn't support it :). The actual code created a new string with Date.now().toString(), which would make the subsequent if check fail every time.

                        1 Reply Last reply
                        0
                        • Z ZurdoDev

                          Probably javascript. 1 == "1" will be true in JavaScript because == casts objects to a common type. However 1 === "1" is false since one is int and the other is string. === does not cast objects. !== will be not equal to without casting of objects. If you're sure both sides of the operand are of the same type then using === or !== will be faster.

                          There are only 10 types of people in the world, those who understand binary and those who don't.

                          B Offline
                          B Offline
                          BuggyTimes
                          wrote on last edited by
                          #14

                          Indeed it is javascript :)

                          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