the tricky business of programming - Page 2 - Techist - Tech Forum

Go Back   Techist - Tech Forum > Computer Software > Programming
Click Here to Login
Reply
 
Thread Tools Display Modes
 
Old 05-20-2009, 04:14 AM   #11 (permalink)
Oldie but a goodie
 
oldskool's Avatar
 
Join Date: Jun 2008
Location: Maine, USA
Posts: 1,762
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.
__________________

oldskool is offline   Reply With Quote
Old 05-20-2009, 07:16 AM   #12 (permalink)
Lord Techie
 
Kharn's Avatar
 
Join Date: Feb 2007
Posts: 7,638
Default Re: the tricky business of programming

Thing is i can go back an correct not only my posts but your posts too
__________________

__________________
Visit this and do something for the world!
www.hackersforcharity.org

Want to do even more? Take a look here and join the fight on human trafficking.

Hear and you forget, see and you remember, do and you understand.

Kharn is offline   Reply With Quote
Old 05-20-2009, 08:27 AM   #13 (permalink)
Seg Fault'n
 
Join Date: Jul 2005
Location: The dried husk where America came from
Posts: 5,801
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
__________________


There are in order of increasing severity: lies, darn lies, statistics, and computer benchmarks. - diskinfo man page
"Get your money and let's go to court!" - Craig Mudie, MS
kmote is offline   Reply With Quote
Old 05-20-2009, 08:36 AM   #14 (permalink)
Lord Techie
 
Kharn's Avatar
 
Join Date: Feb 2007
Posts: 7,638
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.
__________________
Visit this and do something for the world!
www.hackersforcharity.org

Want to do even more? Take a look here and join the fight on human trafficking.

Hear and you forget, see and you remember, do and you understand.

Kharn is offline   Reply With Quote
Old 05-20-2009, 02:09 PM   #15 (permalink)
Seg Fault'n
 
Join Date: Jul 2005
Location: The dried husk where America came from
Posts: 5,801
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;
    }
}
__________________


There are in order of increasing severity: lies, darn lies, statistics, and computer benchmarks. - diskinfo man page
"Get your money and let's go to court!" - Craig Mudie, MS
kmote is offline   Reply With Quote
Old 05-20-2009, 02:45 PM   #16 (permalink)
Wizard Techie
 
CrazeD's Avatar
 
Join Date: Feb 2006
Location: Maine
Posts: 3,736
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.
__________________

Intel Q9400 | Gigabyte EP45-UD3P | G.Skill 2x2GB DDR2 1000 | XFX HD5870

Need website help? PM me!
CrazeD is offline   Reply With Quote
Old 05-20-2009, 02:46 PM   #17 (permalink)
Oldie but a goodie
 
oldskool's Avatar
 
Join Date: Jun 2008
Location: Maine, USA
Posts: 1,762
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.
oldskool is offline   Reply With Quote
Old 05-23-2009, 11:15 PM   #18 (permalink)
Lord Techie
 
S0ULphIRE's Avatar
 
Join Date: Mar 2007
Location: Australia
Posts: 8,580
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 sour 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
S0ULphIRE is offline   Reply With Quote
Old 05-25-2009, 03:38 AM   #19 (permalink)
Oldie but a goodie
 
oldskool's Avatar
 
Join Date: Jun 2008
Location: Maine, USA
Posts: 1,762
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, 10:38 AM   #20 (permalink)
It's all just 1s and 0s
 
office politics's Avatar
 
Join Date: Jan 2004
Location: in the lab
Posts: 6,555
Send a message via MSN to office politics
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 Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
The Falcon Programming Language: a brief tutorial Kharn Programming 2 02-27-2009 02:43 AM
Underage Business... and Online Business? commandercup Technology Careers and Education 1 05-14-2008 03:53 PM


Our Communities

Our communities encompass many different hobbies and interests, but each one is built on friendly, intelligent membership.

» More about our Communities

Automotive Communities

Our Automotive communities encompass many different makes and models. From U.S. domestics to European Saloons.

» More about our Automotive Communities

Marine Communities

Our Marine websites focus on Cruising and Sailing Vessels, including forums and the largest cruising Wiki project on the web today.

» More about our Marine Communities


Copyright 2002- Social Knowledge, LLC All Rights Reserved.

All times are GMT -5. The time now is 06:31 AM.


Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2017, vBulletin Solutions, Inc.