+ 1

Is code within a program always location specific?

I've been learning ruby, and it seems like things are very location specific within the text document itself. Example: x = 10 puts x # any code written in between these two lines treats x as 10 x += 10 puts x # any code written after this last line treats x as 20 So I'm imaging myself in the future becoming confused by the fact that WHERE within the document I add code is going to be so important going forward. How does this work, do I get used to thinking of code like this?

2nd Jun 2017, 11:05 PM
AJ Sellarole
AJ Sellarole - avatar
6 Réponses
+ 1
as long as you defined it first before you call an action there will be no problem
3rd Jun 2017, 12:03 AM
Lance Gallardo
Lance Gallardo - avatar
+ 5
it could be better for you if you use comments :)
2nd Jun 2017, 11:19 PM
Lance Gallardo
Lance Gallardo - avatar
+ 1
what do you mean b33
2nd Jun 2017, 11:44 PM
AJ Sellarole
AJ Sellarole - avatar
0
All comments are not seen if you run a program. Example: In HTML <!--this is comment--> every language has its comment bro so that you can note yourself.
2nd Jun 2017, 11:49 PM
Lance Gallardo
Lance Gallardo - avatar
0
Oh I see what you are saying. Use comments to keep things clear. So you are saying this location thing is the way it is? I'm forseeing many potential issues, what if I have multiple variables and want to use a version of a variable that has since been redefined? Can I refer to previous versiins of a variable within the document? Is a variable ever a true variable? Or it just means what it means for a certain number of lines and is otherwise different?
2nd Jun 2017, 11:55 PM
AJ Sellarole
AJ Sellarole - avatar
0
Of course it will be different if you use different set of codes. Ruby probably has code that can redefine a specific variable just like in all languages.
2nd Jun 2017, 11:58 PM
Lance Gallardo
Lance Gallardo - avatar