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. Here's a specific reason devs hate JavaScript!

Here's a specific reason devs hate JavaScript!

Scheduled Pinned Locked Moved The Weird and The Wonderful
javascripthtmlcssgame-devcollaboration
55 Posts 29 Posters 8 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.
  • R raddevus

    ZurdoDev wrote:

    I love JS. Does that make me NOT a developer?

    No, no. Of course not. I mean, if you become addicted to any substance, does that make you not an addict? I'll let you answer that for myself. :laugh:

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

    ouch

    Everyone is born right handed. Only the strongest overcome it. Fight for left-handed rights and hand equality.

    R 1 Reply Last reply
    0
    • C ClockMeister

      A poor craftsman blames his tools. Javascript (or any language) is as good or bad as the developer using it. You can paint yourself in a corner using any language the only difference is the color of the paint! Sorry guys, but tell me that ain't the truth. ;-)

      If you think hiring a professional is expensive, wait until you hire an amateur! - Red Adair

      J Offline
      J Offline
      Jorgen Andersson
      wrote on last edited by
      #34

      A good craftsman blames himself, for not bringing the right tols to the job.

      Wrong is evil and must be defeated. - Jeff Ello

      1 Reply Last reply
      0
      • Z ZurdoDev

        ouch

        Everyone is born right handed. Only the strongest overcome it. Fight for left-handed rights and hand equality.

        R Offline
        R Offline
        raddevus
        wrote on last edited by
        #35

        ZurdoDev wrote:

        ouch

        :-D Please don't let it spread around, but I really like JavaScript too. I like it because it is proliferate --- browsers are everywhere -- you can write code anywhere! I just wish it had some more and better tools for debugging and compiler warnings so development with it could be more structured and systematic. But sometimes I just really like it because it is so wild and zany too. It's so dynamic you can do crazy cool things with it. Also, the Canvas (drawing / gaming) stuff that you can do is amazing and quite easy to learn. Check out my robotDots article (HTML5 Canvas : Clean JavaScript & Code Organization Allows Faster Dev, Easier Extensibility[^]) or my console in a web page article (Command Console in your browser via HTML5 Canvas & JavaScript[^]) here at CP. Of course you are a real dev. :thumbsup:

        Z 1 Reply Last reply
        0
        • R raddevus

          ZurdoDev wrote:

          ouch

          :-D Please don't let it spread around, but I really like JavaScript too. I like it because it is proliferate --- browsers are everywhere -- you can write code anywhere! I just wish it had some more and better tools for debugging and compiler warnings so development with it could be more structured and systematic. But sometimes I just really like it because it is so wild and zany too. It's so dynamic you can do crazy cool things with it. Also, the Canvas (drawing / gaming) stuff that you can do is amazing and quite easy to learn. Check out my robotDots article (HTML5 Canvas : Clean JavaScript & Code Organization Allows Faster Dev, Easier Extensibility[^]) or my console in a web page article (Command Console in your browser via HTML5 Canvas & JavaScript[^]) here at CP. Of course you are a real dev. :thumbsup:

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

          I agree. Well said. :thumbsup:

          Everyone is born right handed. Only the strongest overcome it. Fight for left-handed rights and hand equality.

          1 Reply Last reply
          0
          • J jsc42

            A convention in JS (and it is just a convention, I do not know if JSLint checks for it) is to name functions that are used as constructors with names starting with a capital letter and functions not used as constructors with names starting with lowercase letters (or $ or _). So, if you had used that convention, you would have written 'new Room()' and you would have been safe.

            M Offline
            M Offline
            Member 10731944
            wrote on last edited by
            #37

            As with all conventions, there are many: Where I work, we use _ to designate private stuff, and $ to designate DOM objects...

            F 1 Reply Last reply
            0
            • M Member 9167057

              It's not just JS, there's other languages where the compiler just chugs along trying to make sense of whatever code is there. VB isn't much better (although option strict and option explicit help). Or what about C? Ever had a nonsensical (it seems) error 14 lines later than where you made the mistake? And that's supposed to be THE system language on the planet.

              M Offline
              M Offline
              Member 10731944
              wrote on last edited by
              #38

              At my first employer as a very junior software engineer (though we called ourselves programmers back then - early 1990s), we used a variant of the PICK operating system called UniVERSE that ran on AIX. Our code was mainly in PICK BASIC, which was a "business BASIC" variant. With the version we were using, we'd sometimes run into bugs that would throw an error at runtime, but when you'd run it in the debugger (which was a nice step-wise debugger, with tons of nice features for the time), it would pass right by the line with the supposed error, and work just fine. Then you'd exit the debugger, run the same piece of code - and it would work perfectly! Think about that - it was a literal debugger! Even so, it was hella annoying...

              M 1 Reply Last reply
              0
              • M Member 10731944

                At my first employer as a very junior software engineer (though we called ourselves programmers back then - early 1990s), we used a variant of the PICK operating system called UniVERSE that ran on AIX. Our code was mainly in PICK BASIC, which was a "business BASIC" variant. With the version we were using, we'd sometimes run into bugs that would throw an error at runtime, but when you'd run it in the debugger (which was a nice step-wise debugger, with tons of nice features for the time), it would pass right by the line with the supposed error, and work just fine. Then you'd exit the debugger, run the same piece of code - and it would work perfectly! Think about that - it was a literal debugger! Even so, it was hella annoying...

                M Offline
                M Offline
                Member 9167057
                wrote on last edited by
                #39

                The heisenbug, a bug disappearing when being looked at. My own experience with such bugs boils down to mostly 2 situations: 1. Timing conditions, the debugger (by principle) slows code down. Solution: Introduce a Sleep(300). 2. Code design to behave differently under a debugger. I remember inheriting a piece of code written like that, cursing loud enough to get asked WTF is going on my several colleagues, throwing this piece of trash away and reimplementing the same functionality anew.

                T 1 Reply Last reply
                0
                • R raddevus

                  I'm working on a prototype for a friend. We're attempting to turn a leadership exercise / game into an automated thing. Basically you have 5 people who each take a character type (barbarian, elf, thief, wizard or leader) and attempt to make it through a 36 room dungeon. It's currently played on posterboard with some real tokens so we are keeping it very simple. "I could write that up for you as an HTML5 Canvas game," said I. And so it began. I draw a grid of 6x6 (36 rooms). I put in the obstacles users cannot see. I allow them to move their tokens. Things are going along swimmingly in JavaScript and I'm generating functionality quickly. It's only 1000 lines of code. (That's like 4 printed pages. Not bad.) Suddenly I have this bug. It's on line 238 and tells me "room does not have a constructor" and it only occurs if I move a token and then restart the game. What!?! It looks like the following:

                  gameVars.allRooms.push(new room({location:i}));

                  Line 238 has not changed in many iterations (I'm using Git so I can tell). new room({location:i}) just sends in a json object which is used to initialize the object. It's quite simple. But finding the bug is very difficult. After hours of picking it apart line-by-line I find a line of code I suspect that is down in another function and shouldn't affect anything. It's way down on line 756 and the compiler has never said anything about it:

                  function playerMovementHandler(playerTokenIdx){
                  var output = document.getElementById("output");
                  var currentPlayer = gameVars.allPlayers[playerTokenIdx];
                  room = hitTestRoom(currentPlayer,gameVars.allRooms);

                  Do you see that? I accidentally didn't type var. Sure it seems obvious now. If I had named that room variable anything else (different from the name of the function/class) it wouldn't have ever hurt me either. But, but, but... JavaScript compiler why couldn't you have mentioned it? Maybe if I'd had strict enabled or something. It's me shooting myself in the foot, I know. Here's The Terrible Explanation But the deal is that in this case the JavaScript compiler was redefining my room class (which are functions in JavaScript) using the hitTestRoom() function instead of just calling the hitTestRoom() function and returning the room object. So, when I would restart the game after moving a game token the code would return to the top with the room class redefined an

                  N Offline
                  N Offline
                  Nathan Minier
                  wrote on last edited by
                  #40

                  raddevus wrote:

                  ...in this case the JavaScript compiler...

                  That might be your problem, you're compiling and interpreted language! Seriously, though, if you're concerned with size (as mentioned above) just minify the production version.

                  "Never attribute to malice that which can be explained by stupidity." - Hanlon's Razor

                  R G 2 Replies Last reply
                  0
                  • M Member 10731944

                    As with all conventions, there are many: Where I work, we use _ to designate private stuff, and $ to designate DOM objects...

                    F Offline
                    F Offline
                    Forogar
                    wrote on last edited by
                    #41

                    We use $nameGoesHere to indicate jQuery objects rather than just simple variables.

                    - I would love to change the world, but they won’t give me the source code.

                    1 Reply Last reply
                    0
                    • R raddevus

                      I'm working on a prototype for a friend. We're attempting to turn a leadership exercise / game into an automated thing. Basically you have 5 people who each take a character type (barbarian, elf, thief, wizard or leader) and attempt to make it through a 36 room dungeon. It's currently played on posterboard with some real tokens so we are keeping it very simple. "I could write that up for you as an HTML5 Canvas game," said I. And so it began. I draw a grid of 6x6 (36 rooms). I put in the obstacles users cannot see. I allow them to move their tokens. Things are going along swimmingly in JavaScript and I'm generating functionality quickly. It's only 1000 lines of code. (That's like 4 printed pages. Not bad.) Suddenly I have this bug. It's on line 238 and tells me "room does not have a constructor" and it only occurs if I move a token and then restart the game. What!?! It looks like the following:

                      gameVars.allRooms.push(new room({location:i}));

                      Line 238 has not changed in many iterations (I'm using Git so I can tell). new room({location:i}) just sends in a json object which is used to initialize the object. It's quite simple. But finding the bug is very difficult. After hours of picking it apart line-by-line I find a line of code I suspect that is down in another function and shouldn't affect anything. It's way down on line 756 and the compiler has never said anything about it:

                      function playerMovementHandler(playerTokenIdx){
                      var output = document.getElementById("output");
                      var currentPlayer = gameVars.allPlayers[playerTokenIdx];
                      room = hitTestRoom(currentPlayer,gameVars.allRooms);

                      Do you see that? I accidentally didn't type var. Sure it seems obvious now. If I had named that room variable anything else (different from the name of the function/class) it wouldn't have ever hurt me either. But, but, but... JavaScript compiler why couldn't you have mentioned it? Maybe if I'd had strict enabled or something. It's me shooting myself in the foot, I know. Here's The Terrible Explanation But the deal is that in this case the JavaScript compiler was redefining my room class (which are functions in JavaScript) using the hitTestRoom() function instead of just calling the hitTestRoom() function and returning the room object. So, when I would restart the game after moving a game token the code would return to the top with the room class redefined an

                      M Offline
                      M Offline
                      Marc Clifton
                      wrote on last edited by
                      #42

                      raddevus wrote:

                      But, but, but... JavaScript compiler why couldn't you have mentioned it?

                      Isn't "Javascript compiler" a contradiction in terms? A non-sequitur? An oxymoron? A Trump "truth?" A Fox New fiction? Something that doesn't actually exist in this space-time continuum?

                      Latest Article - A Concise Overview of Threads Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

                      R 1 Reply Last reply
                      0
                      • M Marc Clifton

                        raddevus wrote:

                        But, but, but... JavaScript compiler why couldn't you have mentioned it?

                        Isn't "Javascript compiler" a contradiction in terms? A non-sequitur? An oxymoron? A Trump "truth?" A Fox New fiction? Something that doesn't actually exist in this space-time continuum?

                        Latest Article - A Concise Overview of Threads Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

                        R Offline
                        R Offline
                        raddevus
                        wrote on last edited by
                        #43

                        Marc Clifton wrote:

                        Isn't "Javascript compiler" a contradiction in terms?

                        Well, I know it's really an interpreter but if you read a bit about the work that the Angular team did they actually talk about their pre-compiler and how that JavaScript does indeed actually compile the code before it runs. Is JavaScript really interpreted or compiled language? | Void Canvas[^] I also watched pluralsight course Advanced JavaScript by Kyle Simpson (JS guru) (Advanced JavaScript Online Course | Pluralsight[^]) and he is the one where I originally picked up on this. Amazon You Don't Know JS - Kyle Simpson[^] Finally, this StackOverflow has the quotes from Kyle Simpson about it being a compiled language: Javascript - Compiled language? - Stack Overflow[^]

                        1 Reply Last reply
                        0
                        • N Nathan Minier

                          raddevus wrote:

                          ...in this case the JavaScript compiler...

                          That might be your problem, you're compiling and interpreted language! Seriously, though, if you're concerned with size (as mentioned above) just minify the production version.

                          "Never attribute to malice that which can be explained by stupidity." - Hanlon's Razor

                          R Offline
                          R Offline
                          raddevus
                          wrote on last edited by
                          #44

                          See my reply here ==> Some extra details about JS being compiled[^]

                          1 Reply Last reply
                          0
                          • N Nathan Minier

                            raddevus wrote:

                            ...in this case the JavaScript compiler...

                            That might be your problem, you're compiling and interpreted language! Seriously, though, if you're concerned with size (as mentioned above) just minify the production version.

                            "Never attribute to malice that which can be explained by stupidity." - Hanlon's Razor

                            G Offline
                            G Offline
                            GuyThiebaut
                            wrote on last edited by
                            #45

                            Nathan Minier wrote:

                            just minify the production version

                            Minification is a 'brilliant' idea which is generally horrible in practice. Debugging minified code is a pain. Here's a link that may help some people javascript - How to effectively debug minified JS files? - Stack Overflow[^]

                            “That which can be asserted without evidence, can be dismissed without evidence.”

                            ― Christopher Hitchens

                            N 1 Reply Last reply
                            0
                            • R raddevus

                              I'm working on a prototype for a friend. We're attempting to turn a leadership exercise / game into an automated thing. Basically you have 5 people who each take a character type (barbarian, elf, thief, wizard or leader) and attempt to make it through a 36 room dungeon. It's currently played on posterboard with some real tokens so we are keeping it very simple. "I could write that up for you as an HTML5 Canvas game," said I. And so it began. I draw a grid of 6x6 (36 rooms). I put in the obstacles users cannot see. I allow them to move their tokens. Things are going along swimmingly in JavaScript and I'm generating functionality quickly. It's only 1000 lines of code. (That's like 4 printed pages. Not bad.) Suddenly I have this bug. It's on line 238 and tells me "room does not have a constructor" and it only occurs if I move a token and then restart the game. What!?! It looks like the following:

                              gameVars.allRooms.push(new room({location:i}));

                              Line 238 has not changed in many iterations (I'm using Git so I can tell). new room({location:i}) just sends in a json object which is used to initialize the object. It's quite simple. But finding the bug is very difficult. After hours of picking it apart line-by-line I find a line of code I suspect that is down in another function and shouldn't affect anything. It's way down on line 756 and the compiler has never said anything about it:

                              function playerMovementHandler(playerTokenIdx){
                              var output = document.getElementById("output");
                              var currentPlayer = gameVars.allPlayers[playerTokenIdx];
                              room = hitTestRoom(currentPlayer,gameVars.allRooms);

                              Do you see that? I accidentally didn't type var. Sure it seems obvious now. If I had named that room variable anything else (different from the name of the function/class) it wouldn't have ever hurt me either. But, but, but... JavaScript compiler why couldn't you have mentioned it? Maybe if I'd had strict enabled or something. It's me shooting myself in the foot, I know. Here's The Terrible Explanation But the deal is that in this case the JavaScript compiler was redefining my room class (which are functions in JavaScript) using the hitTestRoom() function instead of just calling the hitTestRoom() function and returning the room object. So, when I would restart the game after moving a game token the code would return to the top with the room class redefined an

                              K Offline
                              K Offline
                              KarstenK
                              wrote on last edited by
                              #46

                              There are some checking tools for javascript out there, like lint. Good luck :thumbsup: PS: I got headaches because of some "platform specific issues" of my tool chain and imcomplete binaries. X|

                              Press F1 for help or google it. Greetings from Germany

                              1 Reply Last reply
                              0
                              • R raddevus

                                I'm working on a prototype for a friend. We're attempting to turn a leadership exercise / game into an automated thing. Basically you have 5 people who each take a character type (barbarian, elf, thief, wizard or leader) and attempt to make it through a 36 room dungeon. It's currently played on posterboard with some real tokens so we are keeping it very simple. "I could write that up for you as an HTML5 Canvas game," said I. And so it began. I draw a grid of 6x6 (36 rooms). I put in the obstacles users cannot see. I allow them to move their tokens. Things are going along swimmingly in JavaScript and I'm generating functionality quickly. It's only 1000 lines of code. (That's like 4 printed pages. Not bad.) Suddenly I have this bug. It's on line 238 and tells me "room does not have a constructor" and it only occurs if I move a token and then restart the game. What!?! It looks like the following:

                                gameVars.allRooms.push(new room({location:i}));

                                Line 238 has not changed in many iterations (I'm using Git so I can tell). new room({location:i}) just sends in a json object which is used to initialize the object. It's quite simple. But finding the bug is very difficult. After hours of picking it apart line-by-line I find a line of code I suspect that is down in another function and shouldn't affect anything. It's way down on line 756 and the compiler has never said anything about it:

                                function playerMovementHandler(playerTokenIdx){
                                var output = document.getElementById("output");
                                var currentPlayer = gameVars.allPlayers[playerTokenIdx];
                                room = hitTestRoom(currentPlayer,gameVars.allRooms);

                                Do you see that? I accidentally didn't type var. Sure it seems obvious now. If I had named that room variable anything else (different from the name of the function/class) it wouldn't have ever hurt me either. But, but, but... JavaScript compiler why couldn't you have mentioned it? Maybe if I'd had strict enabled or something. It's me shooting myself in the foot, I know. Here's The Terrible Explanation But the deal is that in this case the JavaScript compiler was redefining my room class (which are functions in JavaScript) using the hitTestRoom() function instead of just calling the hitTestRoom() function and returning the room object. So, when I would restart the game after moving a game token the code would return to the top with the room class redefined an

                                T Offline
                                T Offline
                                TheGreatAndPowerfulOz
                                wrote on last edited by
                                #47

                                you keep saying "compiler" but in JavaScript there's no such thing. JavaScript runs under an interpreter, that's why you're able to have such things as eval("_javascript code here_"). :) The closest thing you may get to a compiler is to using something like jslint. Edit: I've seen your compiler links. Interesting. So yeah, you've a point.

                                #SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun

                                1 Reply Last reply
                                0
                                • M Member 9167057

                                  The heisenbug, a bug disappearing when being looked at. My own experience with such bugs boils down to mostly 2 situations: 1. Timing conditions, the debugger (by principle) slows code down. Solution: Introduce a Sleep(300). 2. Code design to behave differently under a debugger. I remember inheriting a piece of code written like that, cursing loud enough to get asked WTF is going on my several colleagues, throwing this piece of trash away and reimplementing the same functionality anew.

                                  T Offline
                                  T Offline
                                  TheGreatAndPowerfulOz
                                  wrote on last edited by
                                  #48

                                  Member 9167057 wrote:

                                  heisenbug

                                  :thumbsup::thumbsup: :laugh: :laugh:

                                  #SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun

                                  1 Reply Last reply
                                  0
                                  • G GuyThiebaut

                                    Nathan Minier wrote:

                                    just minify the production version

                                    Minification is a 'brilliant' idea which is generally horrible in practice. Debugging minified code is a pain. Here's a link that may help some people javascript - How to effectively debug minified JS files? - Stack Overflow[^]

                                    “That which can be asserted without evidence, can be dismissed without evidence.”

                                    ― Christopher Hitchens

                                    N Offline
                                    N Offline
                                    Nathan Minier
                                    wrote on last edited by
                                    #49

                                    GuyThiebaut wrote:

                                    generally horrible in practice

                                    I can't agree. I think that, as you said, debugging it is painful, but that's why you only minify production.

                                    "Never attribute to malice that which can be explained by stupidity." - Hanlon's Razor

                                    A 1 Reply Last reply
                                    0
                                    • R raddevus

                                      I'm working on a prototype for a friend. We're attempting to turn a leadership exercise / game into an automated thing. Basically you have 5 people who each take a character type (barbarian, elf, thief, wizard or leader) and attempt to make it through a 36 room dungeon. It's currently played on posterboard with some real tokens so we are keeping it very simple. "I could write that up for you as an HTML5 Canvas game," said I. And so it began. I draw a grid of 6x6 (36 rooms). I put in the obstacles users cannot see. I allow them to move their tokens. Things are going along swimmingly in JavaScript and I'm generating functionality quickly. It's only 1000 lines of code. (That's like 4 printed pages. Not bad.) Suddenly I have this bug. It's on line 238 and tells me "room does not have a constructor" and it only occurs if I move a token and then restart the game. What!?! It looks like the following:

                                      gameVars.allRooms.push(new room({location:i}));

                                      Line 238 has not changed in many iterations (I'm using Git so I can tell). new room({location:i}) just sends in a json object which is used to initialize the object. It's quite simple. But finding the bug is very difficult. After hours of picking it apart line-by-line I find a line of code I suspect that is down in another function and shouldn't affect anything. It's way down on line 756 and the compiler has never said anything about it:

                                      function playerMovementHandler(playerTokenIdx){
                                      var output = document.getElementById("output");
                                      var currentPlayer = gameVars.allPlayers[playerTokenIdx];
                                      room = hitTestRoom(currentPlayer,gameVars.allRooms);

                                      Do you see that? I accidentally didn't type var. Sure it seems obvious now. If I had named that room variable anything else (different from the name of the function/class) it wouldn't have ever hurt me either. But, but, but... JavaScript compiler why couldn't you have mentioned it? Maybe if I'd had strict enabled or something. It's me shooting myself in the foot, I know. Here's The Terrible Explanation But the deal is that in this case the JavaScript compiler was redefining my room class (which are functions in JavaScript) using the hitTestRoom() function instead of just calling the hitTestRoom() function and returning the room object. So, when I would restart the game after moving a game token the code would return to the top with the room class redefined an

                                      U Offline
                                      U Offline
                                      User 14070906
                                      wrote on last edited by
                                      #50
                                      1. Use a proper IDE with linter /thread
                                      1 Reply Last reply
                                      0
                                      • N Nathan Minier

                                        GuyThiebaut wrote:

                                        generally horrible in practice

                                        I can't agree. I think that, as you said, debugging it is painful, but that's why you only minify production.

                                        "Never attribute to malice that which can be explained by stupidity." - Hanlon's Razor

                                        A Offline
                                        A Offline
                                        AFell2
                                        wrote on last edited by
                                        #51

                                        I've done a few node.js projects...develop in TypeScript, transcode to js, and minify the transcoded js. It's a couple lines in your build script, and the file size (if you keep all the files in your build chain for those few times when you question whether the TypeScript transcode was problematic) is negligible. When you deploy, the deployment script only lifts the minified js.

                                        N 1 Reply Last reply
                                        0
                                        • R raddevus

                                          I'm working on a prototype for a friend. We're attempting to turn a leadership exercise / game into an automated thing. Basically you have 5 people who each take a character type (barbarian, elf, thief, wizard or leader) and attempt to make it through a 36 room dungeon. It's currently played on posterboard with some real tokens so we are keeping it very simple. "I could write that up for you as an HTML5 Canvas game," said I. And so it began. I draw a grid of 6x6 (36 rooms). I put in the obstacles users cannot see. I allow them to move their tokens. Things are going along swimmingly in JavaScript and I'm generating functionality quickly. It's only 1000 lines of code. (That's like 4 printed pages. Not bad.) Suddenly I have this bug. It's on line 238 and tells me "room does not have a constructor" and it only occurs if I move a token and then restart the game. What!?! It looks like the following:

                                          gameVars.allRooms.push(new room({location:i}));

                                          Line 238 has not changed in many iterations (I'm using Git so I can tell). new room({location:i}) just sends in a json object which is used to initialize the object. It's quite simple. But finding the bug is very difficult. After hours of picking it apart line-by-line I find a line of code I suspect that is down in another function and shouldn't affect anything. It's way down on line 756 and the compiler has never said anything about it:

                                          function playerMovementHandler(playerTokenIdx){
                                          var output = document.getElementById("output");
                                          var currentPlayer = gameVars.allPlayers[playerTokenIdx];
                                          room = hitTestRoom(currentPlayer,gameVars.allRooms);

                                          Do you see that? I accidentally didn't type var. Sure it seems obvious now. If I had named that room variable anything else (different from the name of the function/class) it wouldn't have ever hurt me either. But, but, but... JavaScript compiler why couldn't you have mentioned it? Maybe if I'd had strict enabled or something. It's me shooting myself in the foot, I know. Here's The Terrible Explanation But the deal is that in this case the JavaScript compiler was redefining my room class (which are functions in JavaScript) using the hitTestRoom() function instead of just calling the hitTestRoom() function and returning the room object. So, when I would restart the game after moving a game token the code would return to the top with the room class redefined an

                                          P Offline
                                          P Offline
                                          peterchen
                                          wrote on last edited by
                                          #52

                                          That would make it a good habit to always prefix your variale names with "v", and have class factories not start with "v". Contains the damage a bit. Also, your variable is now vroom!

                                          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