You would be perfectly right if Firebug was a parser/compiler and a
debugger. The parser could tell you about the syntax errors.
But in this case the parser is Firefox. Firebug arrives quite later,
when the code actually runs.
But you all know that.
As I had to face this kind of issue myself many many times, I found a
quite obvious solution: Lint. Or jslint, in this case. A tool that will
parse your code, tell you about syntax errors, and, if you feel like it,
about coding style issues that could affect maintainability, readability
or maybe compacting tools.
Since I use lint tools, I wouldn't say my coding style greatly improved,
but it became more uniform, and I never sworn again against a missing
bracket.
For javascript, I took jslint from http://www.jslint.com/, adapted it to
my needs and integrated it in my preferred text editor. A few editors
(such as notepad++ on Windows) even have it already integrated.
The firebug error messages become increasingly meaningful when the code
is syntactically correct, except in rare cases where a DOM exception
isn't trapped correctly.
HTH
Regards
NH
On 2013-05-29 11:41, [email protected] wrote:
I find debugging javascript frustrating, even with the benefit of
Firebug. It is likely that I haven't yet learnt to get the full
benefit of Firebug's features.
A single wrong character can make complex code stop working
altogether, with Firebug displaying error messages which are untrue -
or true in a very narrow sense - such as messages that 1) the function
named such and such is not defined or that 2) there is no javascript
on the page. What I think the messages really mean is that Firebug
isn't smart enough to figure out that 1) you've messed up some syntax
somewhere, with the result that your function is no longer
syntactically correct, or that 2) you've forgotten to put in, or have
accidentally removed/messed up, a <script
type="text/javascript"></script> pair (though, in that case, you're
readily alerted to a problem when your javascript code shows up in the
text on the webpage; maybe there are some more subtle errors which
also generate the no javascript on page error(?)). When I say "Firebug
isn't smart enough" I don't mean to imply that it really ought to be,
as I acknowledge that making sense of code and trying to figure out a
programmer's intention is non-trivial, but, ideally, Firebug would
help me locate the causes of these errors. Messages claiming that
functions don't exist or that the page contains no javascript, seem to
me to be saying, in effect, "Your code has problems which are too hard
for me to figure out. You're on your own!"
I'm unsure whether the message about a function not being defined can
have a cause outside of the function named as not being defined. I
currently have a feeling that it can. I think I'm probably getting
this error saying one function is not defined when the code I've just
messed up is actually in another function and when I haven't actually
made any change to the named function.
At present I'm repeatedly getting that message (about a function not
being defined) after making editing changes. What I usually do then is
visually inspect the code, looking for syntax errors, including
clicking after complexly nested {s and }s (which, in my editor
(SuperEdi), results in { } pairs being displayed in bold). I often
annotate close braces with comments noting the if or else clause which
the close brace is closing. I'm not presently convinced that the
Console tab in Firebug helps me with finding the syntax problem in the
case of "function not defined" or "no javascript on page" errors,
though I admit I am not thoroughly familiar with using the Console
tab. I think it's the case that, sometimes at least, it is necessary
to click twice on the Console tab to see the line(s) of code which
is/are causing problems. There may be times when helpful information
is there but I'm overlooking it.
I try to format my code to show the structure of if ... else clauses.
I try not to make a lot of changes before saving under a different
version number and retesting the code because it's important to be
able to remember what I've done recently for the frequent occasions
when my code substantially or totally stops working because of a
recent change. It would be nice if Firebug included or integrated well
with 1) pretty print software and 2) version control software (though
it may well be that I'd find the learning curve for version control
software daunting). Short of integrating version control software, I
wonder if Firebug could feasibly be improved so that it cached the
immediately previous version of code and could highlight the
differences between the current version and the immediately previous
version to help the programmer locate the newly introduced error(s).
I think there is functionality in Firebug for executing code and
seeing the changing contents of variables as it executes but I haven't
so far been able to use it really successfully. There's a video
recorder style play button to resume a script after an error but I'm
not sure that I've seen a button for executing just the next line of
code. I sometimes succeed in setting Watches on variables but other
times Firebug insists that a variable doesn't exist or isn't
defined/declared - I don't recall which. I appreciate that, during the
execution of code, variables can properly appear and disappear as they
come into and go out of scope. It seems to me that Firebug sometimes
tells me that particular variables don't exist and that they never
appear in the Watch window with values, even though the code
successfully executes using such variables. I guess I need to
persevere and gain more experience. There doesn't seem to be help
integrated into Firebug, though the getfirebug.com webpage includes
useful links e.g. to Firebug Tips & Tricks
<http://www.softwareishard.com/blog/firebug-tips/>. --
--
--
You received this message because you are subscribed to the Google
Groups "Firebug" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
https://groups.google.com/forum/#!forum/firebug
---
You received this message because you are subscribed to the Google Groups "Firebug" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.