|  | |
05-20-2009, 05:14 AM
|
#11 (permalink)
|
Electrical Systems Design Join Date: Jun 2008 Location: Maine, USA Posts: 1,603
| Re: the tricky business of programming ^ If you are using a compiler. For Javascript you can use Notepad, and some people do. Javascript doesn't get compiled, like the other languages mentioned. The browser "renders" it, but Javascript doesn't get compiled. It is not a stand-alone application, just code used within HTML in the form of a script.
^^ Yes the moral of the thread is be careful, but don't let it end like that. I was just trying to think of some obvious mistakes. Quote: |
Things that aren't technical errors, but aren't what you want to do (like the = and == functions)
| ^ Yes that would be an error, if you try to say:
If (someVariable = someOtherVariable) {
// the code here wouldn't work if, if "someVariable were equal
//to 5 and someOtherVariable = 5 as well.
}
That is because the code is NOT COMPARING the two values. It is trying to make
someVariable receive the value of someOtherVariable, not compare the two.
What would be needed in this case would be the == .
So you are wrong, Soulphire. Sorry. Unless you can show me what you mean, with an example.
Last edited by oldskool; 05-20-2009 at 05:58 AM.
|
| |
05-20-2009, 08:16 AM
|
#12 (permalink)
|
Join Date: Feb 2007 Posts: 6,346
| Re: the tricky business of programming Thing is i can go back an correct not only my posts but your posts too
__________________ I am not here for long I am deploying soon so please don't expect anything long winded. |
| |
05-20-2009, 09:27 AM
|
#13 (permalink)
|
Join Date: Jul 2005 Location: England Posts: 2,035
| Re: the tricky business of programming Quote:
Originally Posted by oldskool ^ If you are using a compiler. For Javascript you can use Notepad, and some people do. Javascript doesn't get compiled, like the other languages mentioned. The browser "renders" it, but Javascript doesn't get compiled. It is not a stand-alone application, just code used within HTML in the form of a script.
^^ Yes the moral of the thread is be careful, but don't let it end like that. I was just trying to think of some obvious mistakes.
^ Yes that would be an error, if you try to say:
If (someVariable = someOtherVariable) {
// the code here wouldn't work if, if "someVariable were equal
//to 5 and someOtherVariable = 5 as well.
}
That is because the code is NOT COMPARING the two values. It is trying to make
someVariable receive the value of someOtherVariable, not compare the two.
What would be needed in this case would be the == .
So you are wrong, Soulphire. Sorry. Unless you can show me what you mean, with an example. | What soulphire is saying (and he is right) is that Code: if (something = another)
is not a syntax error, put that into a compiler and it will be fine (which is what makes it is so tricky). If the compiler produced an error as in the case of a syntax mistake eg. a missing '}' or ';' then it wouldn't be such a problem.
Interestingly enough, according to standards (note that I have not read the standard myself to verify this) javascript does not require semicolons though they are considered good practice. And while you are right to note that javascript is an interpreted language and as such is not compiled, you can usually set the browser to pop up with an error if there is a problem.
EDIT: if anyone wants an example of why this isn't a syntax error (although arguably it should be) then I would be more than happy
__________________ MSI P43 Neo|Enermax Pro82+ 425W|E5200|silent 8500GT|250GB Samsung spinpoint F1|Samsung SATA DVD RW|4GB Corsair|Antec SOLO|openSUSE11 
There are in order of increasing severity: lies, darn lies, statistics, and computer benchmarks. - diskinfo man page
Last edited by kmote; 05-20-2009 at 09:34 AM.
|
| |
05-20-2009, 09:36 AM
|
#14 (permalink)
|
Join Date: Feb 2007 Posts: 6,346
| Re: the tricky business of programming Kmote pal - I think any example you can post would be helpful to newbies **** i am learning stuff from it I am a self taught coder so I have a few bad habits an didn't realise i did until i saw this thread.
__________________ I am not here for long I am deploying soon so please don't expect anything long winded. |
| |
05-20-2009, 03:09 PM
|
#15 (permalink)
|
Join Date: Jul 2005 Location: England Posts: 2,035
| Re: the tricky business of programming Ask and ye shall receive, here is a fairly lame example of why the single = is legal in an if. In c: Code: #include <stdio.h>
#include <stdlib.h>
#define LIMIT 14
int doSomething()
{
return 11;
}
int main(void)
{
int aNumber;
if((aNumber = doSomething()) > LIMIT)
{
printf("%d is greater than %d", aNumber, LIMIT);
}
else
{
printf("%d is less than %d", aNumber, LIMIT);
}
return EXIT_SUCCESS;
}
and because the inequality operators "return" a boolean the same applies to java: Code: public class Main {
private static int LIMIT = 14;
public static void main(String[] args)
{
int aNumber;
if((aNumber = doSomething()) > LIMIT)
{
System.out.format("%d is greater than %d\n", aNumber, LIMIT);
}
else
{
System.out.format("%d is less than %d\n", aNumber, LIMIT);
}
}
private static int doSomething()
{
return 20;
}
}
__________________ MSI P43 Neo|Enermax Pro82+ 425W|E5200|silent 8500GT|250GB Samsung spinpoint F1|Samsung SATA DVD RW|4GB Corsair|Antec SOLO|openSUSE11 
There are in order of increasing severity: lies, darn lies, statistics, and computer benchmarks. - diskinfo man page |
| |
05-20-2009, 03:45 PM
|
#16 (permalink)
|
Wizard Techie Join Date: Feb 2006 Location: Maine Posts: 3,681
| Re: the tricky business of programming Quote:
Originally Posted by kmote Interestingly enough, according to standards (note that I have not read the standard myself to verify this) javascript does not require semicolons though they are considered good practice. And while you are right to note that javascript is an interpreted language and as such is not compiled, you can usually set the browser to pop up with an error if there is a problem. | You are correct, Javascript does not require semicolons. I believe it treats a new line as an end of the previous statement. However I always use semicolons, just out of habit from other languages.
And you are also right again, Javascript problems can be debugged with the browser. If you are using Firefox I highly recommend the Firebug extension. You can step-by-step crawl Javascript code, insert breaks, and so on to debug and find out where things went wrong.
__________________ Need website help? PM me! |
| |
05-20-2009, 03:46 PM
|
#17 (permalink)
|
Electrical Systems Design Join Date: Jun 2008 Location: Maine, USA Posts: 1,603
| Re: the tricky business of programming Yes, however....
I gave the example of Javascript where that would not work, I can prove it when I get time. Quote:
Originally Posted by CrazeD You are correct, Javascript does not require semicolons. I believe it treats a new line as an end of the previous statement. However I always use semicolons, just out of habit from other languages. | Wel I have had code go all haywire without them, and I know that was it because when I put the semicolons in it all worked ok.
Last edited by oldskool; 05-20-2009 at 03:50 PM.
|
| |
05-24-2009, 12:15 AM
|
#18 (permalink)
|
01001100011011110110110 Join Date: Mar 2007 Location: Perth, Australia Posts: 1,870
| Re: the tricky business of programming Quote:
Originally Posted by Saxon Thing is i can go back an correct not only my posts but your posts too  | now that truly IS godlike
__________________ "As a result of all this hardship, dirt, thirst, and wombats, you would expect Australians to be a dour lot. Instead, they are genial, jolly, cheerful, and always willing to share a kind word with a stranger, unless they are an American." -- Douglas Adams Click this if I helped you >>>> <<<< |
| |
05-25-2009, 04:38 AM
|
#19 (permalink)
|
Electrical Systems Design Join Date: Jun 2008 Location: Maine, USA Posts: 1,603
| Re: the tricky business of programming Well apparently semicolons are not necessary as I went back and tried a few things after posting here. Thing is, I know in the past I have had problems not putting them in ... I suppose it must have been a different reason other than a missing semicolon. |
| |  | | | Thread Tools | | | | Display Modes | Linear Mode |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | |