Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » the tricky business of programming
Reply
Old 05-20-2009, 05:14 AM   #11 (permalink)
oldskool's Avatar
 
Electrical Systems Design

Join Date: Jun 2008

Location: Maine, USA

Posts: 1,646

oldskool has a spectacular aura aboutoldskool has a spectacular aura about

Default 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.
oldskool is offline   Reply With Quote
Old 05-20-2009, 08:16 AM   #12 (permalink)
Saxon's Avatar
 

Join Date: Feb 2007

Posts: 6,362

Saxon is just really niceSaxon is just really niceSaxon is just really niceSaxon is just really nice

Default 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.

Saxon is offline   Reply With Quote
Old 05-20-2009, 09:27 AM   #13 (permalink)
 

Join Date: Jul 2005

Location: England

Posts: 2,151

kmote has a spectacular aura aboutkmote has a spectacular aura about

Default Re: the tricky business of programming

Quote:
Originally Posted by oldskool View Post
^ 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.
kmote is online now   Reply With Quote
Old 05-20-2009, 09:36 AM   #14 (permalink)
Saxon's Avatar
 

Join Date: Feb 2007

Posts: 6,362

Saxon is just really niceSaxon is just really niceSaxon is just really niceSaxon is just really nice

Default 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.

Saxon is offline   Reply With Quote
Old 05-20-2009, 03:09 PM   #15 (permalink)
 

Join Date: Jul 2005

Location: England

Posts: 2,151

kmote has a spectacular aura aboutkmote has a spectacular aura about

Default 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
kmote is online now   Reply With Quote
Old 05-20-2009, 03:45 PM   #16 (permalink)
CrazeD's Avatar
 
Wizard Techie

Join Date: Feb 2006

Location: Maine

Posts: 3,683

CrazeD will become famous soon enough

Send a message via AIM to CrazeD Send a message via MSN to CrazeD
Default Re: the tricky business of programming

Quote:
Originally Posted by kmote View Post
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!
CrazeD is online now   Reply With Quote
Old 05-20-2009, 03:46 PM   #17 (permalink)
oldskool's Avatar
 
Electrical Systems Design

Join Date: Jun 2008

Location: Maine, USA

Posts: 1,646

oldskool has a spectacular aura aboutoldskool has a spectacular aura about

Default 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 View Post
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.
oldskool is offline   Reply With Quote
Old 05-24-2009, 12:15 AM   #18 (permalink)
S0ULphIRE's Avatar
 
01001100011011110110110

Join Date: Mar 2007

Location: Perth, Australia

Posts: 1,940

S0ULphIRE has a spectacular aura aboutS0ULphIRE has a spectacular aura about

Send a message via MSN to S0ULphIRE
Default Re: the tricky business of programming

Quote:
Originally Posted by Saxon View Post
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
>>>><<<<
S0ULphIRE is offline   Reply With Quote
Old 05-25-2009, 04:38 AM   #19 (permalink)
oldskool's Avatar
 
Electrical Systems Design

Join Date: Jun 2008

Location: Maine, USA

Posts: 1,646

oldskool has a spectacular aura aboutoldskool has a spectacular aura about

Default 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.
oldskool is offline   Reply With Quote
Old 10-23-2009, 11:38 AM   #20 (permalink)
office politics's Avatar
 
It's all just 1s and 0s

Join Date: Jan 2004

Location: in the lab

Posts: 4,410

office politics will become famous soon enough

Default Re: the tricky business of programming

adding something about array indexes could be appropiate here.

Why am I getting 'subscript out of range' errors?
office politics is offline   Reply With Quote
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
The Falcon Programming Language: a brief tutorial Saxon Programming Discussions 2 02-27-2009 03:43 AM
Underage Business... and Online Business? commandercup Discussion on Computer Jobs, Degrees, Certifications 1 05-14-2008 04:53 PM