Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


"built-in loop" question


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
44 replies to this topic

#1 Malabyte   Members   -  Reputation: 589

Like
1Likes
Like

Posted 13 October 2013 - 08:53 AM

Edit: Questions done, thanks for the answers.

 

-----

Hey guys, I'm planning on some day making a video series on Youtube, where I talk about certain game programming things. Without revealing too much, I'd like to ask you guys a couple of questions now and then, in order to be as accurate with the given topic as possible. I'm self-taught, so there might be some conventional details that I've overlooked.

 

 

So here's my first couple of questions:

 

1. What do you call the default process that automatically loops through the code and updates, whenever the program is ran? You know, the one where the computer tries to look for the Main function and run that, over and over again? Does it have an actual name, or is it fine to just call it a "built-in loop"?

Answered in thread.

 

2. Do all programming languages have a main function/method that the computer will look for and try to run? (I'm thinking it's a necessity, but please correct me if wrong)

Answered by Wikipedia.org

 

3. Do all programming languages (today) cause the computer to loop infinitely through the code by default, unless you control it to do otherwise?

Answered in thread.


Edited by Malabyte, 18 October 2013 - 08:58 PM.

- Awl you're base are belong me! -

- I don't know, I'm just a noob -


Sponsor:

#2 shacktar   Members   -  Reputation: 841

Like
1Likes
Like

Posted 13 October 2013 - 10:24 AM

1. What do you call the default process that automatically loops through the code and updates, whenever the program is ran? You know, the one where the computer tries to look for the Main function and run that, over and over again? Does it have an actual name, or is it fine to just call it a "built-in loop"?

 

There is no "built-in loop". The Main function/method is run precisely once. If you're thinking of the "Main Game Loop", then that has to be inserted by the programmer.

 

2. Do all programming languages have a main function/method that the computer will look for and try to run? (I'm thinking it's a necessity, but please correct me if wrong)
Answered by Wikipedia.org

 

No, not all programming languages require a main function/method. Interpreted languages commonly don't require a Main. e.g. JavaScript, Scheme, Lua

 

3. Do all programming languages (today) cause the computer to loop infinitely through the code by default, unless you control it to do otherwise?

 

It's the other way around. Main is run exactly once. An infinite loop would have to programmed (or caused by a bug).


Edited by shacktar, 13 October 2013 - 10:28 AM.


#3 King Mir   Members   -  Reputation: 2050

Like
0Likes
Like

Posted 13 October 2013 - 10:32 AM

Um, in most languages main is run exactly once. There's no built-in loop.

In native languages main is called fist by virtue of how the compiler structures the executable. In interpreted languages, main is called by the language virtual machine.

#4 Malabyte   Members   -  Reputation: 589

Like
0Likes
Like

Posted 13 October 2013 - 10:37 AM

 

1. What do you call the default process that automatically loops through the code and updates, whenever the program is ran? You know, the one where the computer tries to look for the Main function and run that, over and over again? Does it have an actual name, or is it fine to just call it a "built-in loop"?

 

There is no "built-in loop". The Main function/method is run precisely once. If you're thinking of the "Main Game Loop", then that has to be inserted by the programmer.

 

Ah ok, thanks. I guess it's specific for Java then, as you have to manually terminate the program (e.g. in the IDE console) or declare EXIT_ON_CLOSE for a windowed app.


Edited by Malabyte, 13 October 2013 - 10:44 AM.

- Awl you're base are belong me! -

- I don't know, I'm just a noob -


#5 Pink Horror   Members   -  Reputation: 1228

Like
0Likes
Like

Posted 13 October 2013 - 10:47 AM


Ah ok, thanks. I guess it's specific for Java then, because you have to manually close the process or else the program just keeps running.

 

Java just runs its main once, too. If your program keeps running, you're doing something to make that happen.



#6 Malabyte   Members   -  Reputation: 589

Like
0Likes
Like

Posted 13 October 2013 - 11:15 AM

Java just runs its main once, too. If your program keeps running, you're doing something to make that happen.

 

I'm talking about how the computer reads through the code in the class file. It "scans" through the first line, then the nth line until it reaches the bottom, then goes back to the first line again and reads all lines again. If it ran the code only once, then whenever you start to run the program it would immediately stop running, a millisecond or so afterwards.

 

For as long as I've been using Java, I've never had to explicitly tell the computer to continue to run the program. It will sometimes wait for some input or other change of its state, sure, but the program itself keeps "pulsing" through the class file(s). I've had to specifically tell it to terminate when I want it to. For instance, if you're using Eclipse to make a windowed Java application, then you specifically need to use the following line to terminate the program when you click the X to close the window (else the program keeps running even if the window isn't):

 

-----

window.setDefaultCloseOperation(EXIT_ON_CLOSE); 

-----

 

I'm just very confused right now, I'm not sure what you guys are talking about. Does the Eclipse IDE, or the JFrame class specifically, have some sort of integral method that causes it the program to run continuously?


Edited by Malabyte, 13 October 2013 - 11:37 AM.

- Awl you're base are belong me! -

- I don't know, I'm just a noob -


#7 SimonForsman   Crossbones+   -  Reputation: 6293

Like
3Likes
Like

Posted 13 October 2013 - 11:54 AM

 

Java just runs its main once, too. If your program keeps running, you're doing something to make that happen.

 

I'm talking about how the computer reads through the code in the class file. It "scans" through the first line, then the nth line until it reaches the bottom, then goes back to the first line again and reads all lines again. If it ran the code only once, then whenever you start to run the program it would immediately stop running, a millisecond or so afterwards.

 

For as long as I've been using Java, I've never had to explicitly tell the computer to continue to run the program. It will sometimes wait for some input or other change of its state, sure, but the program itself keeps "pulsing" through the class file(s). I've had to specifically tell it to terminate when I want it to. For instance, if you're using Eclipse to make a windowed Java application, then you specifically need to use the following line to terminate the program when you click the X to close the window (else the program keeps running even if the window isn't):

 

-----

window.setDefaultCloseOperation(EXIT_ON_CLOSE); 

-----

 

I'm just very confused right now, I'm not sure what you guys are talking about. Does the Eclipse IDE, or the JFrame class specifically, have some sort of integral method that causes it the program to run continuously?

 

 

Java closes the application after all threads have finished executing (not when main is finished), main still only runs once though. (When you create a window the window system(Swing or AWT, other window systems may work differently) will have its own thread that keeps the application alive)


Edited by SimonForsman, 13 October 2013 - 11:57 AM.

I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

#8 Malabyte   Members   -  Reputation: 589

Like
0Likes
Like

Posted 13 October 2013 - 12:09 PM

Java closes the application after all threads have finished executing (not when main is finished), main still only runs once though. (When you create a window the window system(Swing or AWT, other window systems may work differently) will have its own thread that keeps the application alive)

 

Ok, sweet. So I guess that, whenever you for instance make a console program with some println string, the string is rendered once and then kept updated by the console (e.g. Eclipse) or command prompt itself and not the program that initially rendered it? (unless, of course, you've explicitly told the program to wait for input or whatever).

 

If so, then everything makes perfect sense. Because then it's part of the IDE or the OS, I guess.


Edited by Malabyte, 13 October 2013 - 12:30 PM.

- Awl you're base are belong me! -

- I don't know, I'm just a noob -


#9 phantom   Moderators   -  Reputation: 7556

Like
8Likes
Like

Posted 13 October 2013 - 12:19 PM

Honestly, based on these questions and your 'understanding' shown in your replies, I don't think you should be trying to teach anyone anything - you clearly don't have the knowledge down at this point to be an authority source on the matter and any attempts to 'teach' others is going to do them more harm than good in the long run.

#10 Malabyte   Members   -  Reputation: 589

Like
0Likes
Like

Posted 13 October 2013 - 12:31 PM

Honestly, based on these questions and your 'understanding' shown in your replies, I don't think you should be trying to teach anyone anything - you clearly don't have the knowledge down at this point to be an authority source on the matter and any attempts to 'teach' others is going to do them more harm than good in the long run.

And you don't think that I will eventually acquire the knowledge, once I'm done with the research?

 

The bottom line is that there's an inconsistency in what I'm actually experiencing when I program, with the logic that has been explained to me in this thread. At least up until the point where SimonForsman elaborated on it.

 

Here's an example code:

class test {
    public static void main (String[] args) {
        System.out.println ("Hello world");
    }
}

"Hello World" will show up in the console and it will keep showing up. No, it will obviously not visually repeat the line, for that you obviously need to create a loop of some sort. There's only a single line popping up. But that one line keeps itself visible on-screen and in Eclipse, the program doesn't terminate unless you specifically click on the terminate button. I'm just asking what causes that to happen, when I know that a screen ultimately consists of x*y pixels that keep updating as long as the PC screen is turned on. And if the program terminates, then what keeps updating the pixels on the screen? It sure ain't a terminated program.

 

You can be a pretty solid amateur programmer and still wonder about these subtle things, especially if you've been learning stuff through the internet (because there's all kinds of programming lingo and methodology that you have to figure out on your own). They are easy to miss, because they don't have much to do with the actual coding at all (assuming that we're talking about Java, which is the language I'm learning). There's a reason why a good University is sometimes superior to the internet.

 

So yes, I agree that I shouldn't be making videos until I know what I'm talking about. Which I'm not planning on doing, either. I just want to make a couple of videos (eventually) that I've yet to find on Youtube, because everyone's focused on teaching syntax and specific algorithms for specific tasks (but not teach people how to invent their own). But if someone else can beat me to it, then by all means. A Professional programmer with solid tutoring skills is a much better conveyor of information, anyways.


Edited by Malabyte, 13 October 2013 - 01:02 PM.

- Awl you're base are belong me! -

- I don't know, I'm just a noob -


#11 phantom   Moderators   -  Reputation: 7556

Like
1Likes
Like

Posted 13 October 2013 - 12:59 PM

So yes, I agree that I shouldn't be making videos until I know what I'm talking about. Which I'm not planning on doing, either.


Good but the key words in my reply were 'authority source' which means that realistically I would say you are still a good couple of YEARS away from being in any position to teach others with any real authority on matters.

#12 phil_t   Crossbones+   -  Reputation: 4092

Like
3Likes
Like

Posted 13 October 2013 - 01:07 PM

The program sends "Hello World" to the console, then exits. The console window (separate program) still keeps displaying what was sent to it.



#13 Malabyte   Members   -  Reputation: 589

Like
-1Likes
Like

Posted 13 October 2013 - 01:08 PM

Good but the key words in my reply were 'authority source' which means that realistically I would say you are still a good couple of YEARS away from being in any position to teach others with any real authority on matters.

 

A valid opinion, but I honestly don't think people care, as long as the data is accurate and I have the ability to make myself understood. Science is not about trusting authority, it's about getting the facts straight. If anything, questioning authority is more akin to science. By your logic, Bucky Roberts @ thenewboston should've never started teaching his now 565 465 Youtube subscribers, because he wasn't much of an authority when he started out. He even dropped out of college. And Mark Zuckerberg invented Facebook, so authority hardly factors into it.

 

Granted, I agree that it helps to have a solid background, for credibility's sake and also if you want to be a general, cross-discipline teacher. A lot of people, if they see two possible sources, will obviously adhere better to the source with the greater authority. That's just human nature. We don't always have the time or resources to learn who or what is truly the more credibly source, so we take a calculated "risk" by trusting a known authority.

 

In either case, I may just follow your advice just a little bit.

 

Edit: I guess I should also point out that I'm talking about a very basic tutorial that just helps people start making something on their own, without getting that writer's block. Nothing complex, albeit abstract and conceptual.

 

 

The program sends "Hello World" to the console, then exits. The console window (separate program) still keeps displaying what was sent to it.

 

I guess I understood Simon correctly then, thanks for the confirmation.


Edited by Malabyte, 13 October 2013 - 01:41 PM.

- Awl you're base are belong me! -

- I don't know, I'm just a noob -


#14 SimonForsman   Crossbones+   -  Reputation: 6293

Like
2Likes
Like

Posted 13 October 2013 - 01:30 PM

 

Honestly, based on these questions and your 'understanding' shown in your replies, I don't think you should be trying to teach anyone anything - you clearly don't have the knowledge down at this point to be an authority source on the matter and any attempts to 'teach' others is going to do them more harm than good in the long run.

And you don't think that I will eventually acquire the knowledge, once I'm done with the research?

 

The bottom line is that there's an inconsistency in what I'm actually experiencing when I program, with the logic that has been explained to me in this thread. At least up until the point where SimonForsman elaborated on it.

 

Here's an example code:

class test {
    public static void main (String[] args) {
        System.out.println ("Hello world");
    }
}

"Hello World" will show up in the console and it will keep showing up. No, it will obviously not visually repeat the line, for that you obviously need to create a loop of some sort. There's only a single line popping up. But that one line keeps itself visible on-screen and in Eclipse, the program doesn't terminate unless you specifically click on the terminate button. I'm just asking what causes that to happen, when I know that a screen ultimately consists of x*y pixels that keep updating as long as the PC screen is turned on. And if the program terminates, then what keeps updating the pixels on the screen? It sure ain't a terminated program.

 

You can be a pretty solid amateur programmer and still wonder about these subtle things, especially if you've been learning stuff through the internet (because there's all kinds of programming lingo and methodology that you have to figure out on your own). They are easy to miss, because they don't have much to do with the actual coding at all (assuming that we're talking about Java, which is the language I'm learning). There's a reason why a good University is sometimes superior to the internet.

 

So yes, I agree that I shouldn't be making videos until I know what I'm talking about. Which I'm not planning on doing, either. I just want to make a couple of videos (eventually) that I've yet to find on Youtube, because everyone's focused on teaching syntax and specific algorithms for specific tasks (but not teach people how to invent their own). But if someone else can beat me to it, then by all means. A Professional programmer with solid tutoring skills is a much better conveyor of information, anyways.

 

 

The console is not a part of the java application, it is a part of the OS and may or may not close after the program has finished running(depending on how it was launched, you can launch a standalone console by typing in cmd.exe in the run dialog in windows.


I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

#15 Malabyte   Members   -  Reputation: 589

Like
0Likes
Like

Posted 13 October 2013 - 01:34 PM

Ok, I guess I got this part figured out. Thanks again, guys. smile.png


- Awl you're base are belong me! -

- I don't know, I'm just a noob -


#16 King Mir   Members   -  Reputation: 2050

Like
0Likes
Like

Posted 13 October 2013 - 01:36 PM

I recommend getting a book instead of relying on internet tutorials. If you do then you'll realize why internet tutorials are woefully inadequate in learning your first language.

#17 phantom   Moderators   -  Reputation: 7556

Like
4Likes
Like

Posted 13 October 2013 - 02:00 PM

A valid opinion, but I honestly don't think people care, as long as the data is accurate and I have the ability to make myself understood.


And there is lies the problem; until you are a well practised and know the subject inside out you don't know if it is accurate. But the people 'learning' from you also don't know if you are right or not, they just assume you are, so if you don't know the subject well then you are going to teach bad things and, frankly, the internet has enough bad information on it as it is and doesn't need more 'noobs' (to use the word from your signature) putting out more information they don't fully understand.

By your logic, Bucky Roberts @ thenewboston should've never started teaching his now 565 465 Youtube subscribers, because he wasn't much of an authority when he started out. He even dropped out of college. And Mark Zuckerberg invented Facebook, so authority hardly factors into it.


I'd never heard of that site before, so I went to check it out and had a look at his second C++ video explaining hello world and, honestly, based on getting 6mins into that video there is probably good cause for him not to have been trying to teach C++.... by 8mins in it was no better... by 9mins, oh god... I mean... oh god... '[main] should always have return 0', 'if you added text here [to cause an error] then it will never make it to [the return statement] so it will never return 0'... I mean, seriously... ugh.

And we aren't talking a small nit picking mistake there either; he fundamentally gets the C++ compilation model utterly wrong.. and not for the first time either... hell, don't get me started on 'all programs must have a main function' and 'your computer automatically knows to start at main' which is just wrong. (Yes, you can avoid the complications of how the OS and runtime do it but not by making statements of absolute truths like that!)

So, yeah, he probably shouldn't be teaching people C++ at least - and just because he has a large number of subscribers doesn't mean he is right, it just means he has a large number of subscribers.

And college has nothing to do with it; I wrote a series of articles for this site back in 2005 or 2006 for OpenGL and the only reason I did it is because I had a very strong background in the subject. At that point I hadn't completed university and didn't have a degree. Same goes for the chapter I wrote on the GLSL many years back.

Zuckerberg has nothing to do with it either; he made a website, he wasn't trying to teach people how to make a Facebook like website.

A lot of people, if they see two possible sources, will obviously adhere better to the source with the greater authority. That's just human nature. We don't always have the time or resources to learn who or what is truly the more credibly source, so we take a calculated risk.


Unfortunately that isn't the case; people see two sources they will take the one which looks easiest or quickest to learn from and go with that.
Given the choice between a correct book and a video which claims to be correct most people will, these days, more than likely take the video.

Of course if the internet wasn't full of incorrect tutorials we wouldn't have this problem but apparently its full of people who think "I've been coding for 20mins I must teach others so I can learn too!" which is just... ugh...

#18 Malabyte   Members   -  Reputation: 589

Like
-2Likes
Like

Posted 13 October 2013 - 03:08 PM

And there is lies the problem; until you are a well practised and know the subject inside out you don't know if it is accurate. But the people 'learning' from you also don't know if you are right or not, they just assume you are, so if you don't know the subject well then you are going to teach bad things and, frankly, the internet has enough bad information on it as it is and doesn't need more 'noobs' (to use the word from your signature) putting out more information they don't fully understand.

 

Data is still data. If you actually know it, especially if it's been confirmed by a seasoned professional, then you know it. You don't need to be a seasoned professional yourself. What you're clearly talking about, has to do with larger (or entire) fields of science where expertise is synonymous to years worth of honing a multitude of different knowledges in order to grasp the full picture. And I can agree that some people indeed claim to know something that they don't.

But I'm talking about simple facts. No more and no less, so I'm just curious as to why you assume otherwise about me, since I haven't been saying anything about what I would specifically be talking about in my series. Learning programming is like learning anything else, you gradually learn more, the more you study. You don't study for X years and then suddenly you come to a point where all the information magically goes from 0-100% in a split second. Knowledge is modular and gradual.

 

In other words, basic scientific literacy. In this thread, I was asking about a very specific thing that's happening under the hood of the program and has nothing to do with the code you're actually writing (because it's happening at default, the program runs once unless you code it to do otherwise, as Simon and the others stated). So as a self-taught, then it's no wonder that I've missed it.

 

 

I'd never heard of that site before, so I went to check it out and had a look at his second C++ video explaining hello world and, honestly, based on getting 6mins into that video there is probably good cause for him not to have been trying to teach C++.... by 8mins in it was no better... by 9mins, oh god... I mean... oh god... '[main] should always have return 0', 'if you added text here [to cause an error] then it will never make it to [the return statement] so it will never return 0'... I mean, seriously... ugh.

 

Well, I'll admit that you've the advantage here of having watched that particular series. But in general, being a good teacher isn't just about telling people correct information. It's also about being sensitive to the student's mindset. The greatest teachers are able to engage their students and even create the illusion that the student have figured something out that the teachers did wrong. In actuality, the teacher did those mistakes on purpose. It's the same when your Drill Instructor screams in your face. Not because he's angry, frustrated or because he hates you, but rather the opposite. The clue is to motivate students and bolster their deeper learning of the subject in whatever way that is more relevant for the given subject. (Now, whether this is true for thenewboston, I can't really say, but it's possible (albeit hard to actually apply).)

 

Dr Robert Sapolsky, for instance, literally teaches his students outright false or outdated information before he makes a complete u-turn and throws it out the window. Almost like when a programmer does something silly in the first video and then refactors it in the next. This is possibly done in order for students to understand the sceptical nature of science, and it's also a solid history lesson that sticks with them.

 

As for Zuckerberg, I used him as an example to point out that authority can risk becoming a fixation with regards to how successful or accurate you are in your endeavours. Mark's not a teacher but, if he were, he would at least know what he's talking about. Even if he too ditched college. tongue.png

 

 

Unfortunately that isn't the case; people see two sources they will take the one which looks easiest or quickest to learn from and go with that.

Given the choice between a correct book and a video which claims to be correct most people will, these days, more than likely take the video.

Of course if the internet wasn't full of incorrect tutorials we wouldn't have this problem but apparently its full of people who think "I've been coding for 20mins I must teach others so I can learn too!" which is just... ugh...

 

How quickly you can learn something is one thing, the credibility of the informatin is another. Both factor in, and there's even more factors involved here, but I won't digress further. I agree on the "...20 mins I must teach others..." syndrome though, it's almost a little creepy to witness at times. That's the Dunning-Kruger effect for you, right there (and it doesn't only happen on youtube or even the internet in general). biggrin.png


Edited by Malabyte, 13 October 2013 - 05:45 PM.

- Awl you're base are belong me! -

- I don't know, I'm just a noob -


#19 ChaosEngine   Crossbones+   -  Reputation: 2499

Like
1Likes
Like

Posted 13 October 2013 - 06:41 PM


Data is still data. If you actually know it, especially if it's been confirmed by a seasoned professional, then you know it. You don't need to be a seasoned professional yourself. What you're clearly talking about, has to do with larger (or entire) fields of science where expertise is synonymous to years worth of honing a multitude of different knowledges in order to grasp the full picture. And I can agree that some people indeed claim to know something that they don't.

But I'm talking about simple facts. No more and no less, so I'm just curious as to why you assume otherwise about me, since I haven't been saying anything about what I would specifically be talking about in my series. Learning programming is like learning anything else, you gradually learn more, the more you study. You don't study for X years and then suddenly you come to a point where all the information magically goes from 0-100% in a split second. Knowledge is modular and gradual.
 
In other words, basic scientific literacy. In this thread, I was asking about a very specific thing that's happening under the hood of the program and has nothing to do with the code you're actually writing (because it's happening at default, the program runs once unless you code it to do otherwise, as Simon and the others stated). So as a self-taught, then it's no wonder that I've missed it.

 

The point is that you don't know how what the data means or how to apply it. Data on it's own is meaningless. Context matters. 

 

The fact that you still think it's something " that's happening under the hood of the program and has nothing to do with the code you're actually writing" shows you are still barely understanding the concept you're asking about and are certainly in no position to teach it. 

 

 


Dr Robert Sapolsky, for instance, literally teaches his students outright false or outdated information before he makes a complete u-turn and throws it out the window. Almost like when a programmer does something silly in the first video and then refactors it in the next.

 

When you're starting out in any field, simple guidelines are a great help. But there is a world of difference between deliberately teaching a simplified (possibly even inaccurate) version of a complex problem and actually believing it oneself. You can only lie to your students if you a) realise it's a lie, b) understand why you're lying and c) know the truth yourself.

 

This is possibly done in order for students to understand the sceptical nature of science, and it's also a solid history lesson that sticks with them.

 

I doubt it. "Don't trust your teacher" is not a useful lesson to impart to beginners. For an intermediate student looking to advance, possibly...

 

I'm not trying to discourage you from programming, and I equally am not trying to belittle your programming knowledge. Everyone was there once and we all had some stupid assumptions. I looked over some of my earlier posts here the other day and cringed. The point is simply that you are really not ready to give anyone any kind of tutorial. 


if you think programming is like sex, you probably haven't done much of either.-------------- - capn_midnight

#20 Malabyte   Members   -  Reputation: 589

Like
-1Likes
Like

Posted 13 October 2013 - 06:49 PM

The point is that you don't know how what the data means or how to apply it. Data on it's own is meaningless. Context matters.

Whether I know what the data means or how to apply it, depends on what data we're talking about and under which circumstance it is used. So yes, context matters.


Edited by Malabyte, 13 October 2013 - 06:49 PM.

- Awl you're base are belong me! -

- I don't know, I'm just a noob -





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS