Here's a specific reason devs hate JavaScript!
-
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 thehitTestRoom()
function instead of just calling thehitTestRoom()
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 anraddevus 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
-
As with all conventions, there are many: Where I work, we use _ to designate private stuff, and $ to designate DOM objects...
-
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 thehitTestRoom()
function instead of just calling thehitTestRoom()
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 anraddevus 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
-
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
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[^]
-
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
-
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
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
-
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 thehitTestRoom()
function instead of just calling thehitTestRoom()
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 -
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 thehitTestRoom()
function instead of just calling thehitTestRoom()
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 anyou 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
-
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.
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
-
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
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
-
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 thehitTestRoom()
function instead of just calling thehitTestRoom()
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- Use a proper IDE with linter /thread
-
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
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.
-
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 thehitTestRoom()
function instead of just calling thehitTestRoom()
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 -
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.
Did you mean to reply to the other guy, or were you just really happy about the node-typescript toolchain...?
"Never attribute to malice that which can be explained by stupidity." - Hanlon's Razor
-
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 thehitTestRoom()
function instead of just calling thehitTestRoom()
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"devs" don't hate JavaScript. Also don't blame someone else for your mistakes (you use a style of JS that was written like 10 years ago; TypeScript is out there since 2012 and you are still not using arrow functions, `let`, strict mode, and other goodies that are there to help you to avoid such mistakes). I am not sure why you "compile" at all when you essentially write ES3 code.
-
Sander Rossel wrote:
'options strict';
Doh! I just tried your
'options strict';
at the top and I set the bad code back (removed var) and it didn't do anything. Same error"room is not a constructor"
Oh, it looks like options strict is a Visual Basic thing. You've outed yourself! You're a VB Dev aren't you? :laugh: So I looked it up and found this: JavaScript "use strict"[^] I added
"use strict";
and now it gives me warnings about undefined items. I think it has changed. :)The Visual Basic instruction is
Option Explicit
. Other environments, e. g., Perl, haveuse strict;
that invokes a package. There might be something like that in Typescript, but I am unaware of anything along those lines for Javascript. On the other hand, I use JS as infrequently as possible, for all the reasons you said, and many others. If you're serious about JS, you really need a good linter and a robust set of rules to guide it, not to mention a decent visual debugger. When necessity requires it, I lean heavily on the Chrome Dev Tools.David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting