_Self_._Field_

BlitzMax Forums/BlitzMax Beginners Area/_Self_._Field_

Curtastic(Posted 2005) [#1]
I hadn't coded much OO before now, and my game is getting pretty big and when coding in methods its sometimes confusing what word is the instance's field or if its a global or a local of the method(). So I started using "Self." before each field in each method but that was annoying and there was no guarantee that I remember to put that.
I saw some code that used underscores for fields of a type, and that code looked really scary to me do I didn't do that. I'm wondering whats the best way to do this? What does it mean if there is a underscore after the word? What about 2 underscores, I think I've seen that too.

What if fields required a "." before their name, when coding in methods? Wouldn't that be a good way to solve this problem? Of course I can't make the preprocessor work like that, but I was just wondering.


FlameDuck(Posted 2005) [#2]
Traditionally _FieldName indicates a private field (ie. one that is only accessable within the same class). In BlitzMAX however this is meaningless as there is no such thing.

I'm wondering whats the best way to do this?
Scope your variables carefully. Aviod globals whenever possible (you'd be surprised) and make sure to enforce a low coupling and high coherency in your classes.

Also the Eclipse IDE will show you which fields/variables your types have, and their scopes.


Curtastic(Posted 2005) [#3]
Ok thanks, does anyone normally use underscores before fields in blitzmax? I might do it anyways to make it more clear what I am doing inside methods.



Scope your variables carefully. Aviod globals whenever possible (you'd be surprised) and make sure to enforce a low coupling and high coherency in your classes.

Ya thats good. I should probably put my globals in types. I made an abstract type to hold globals and it worked but it didn't show their values in the debugger so I assumed that I am not supposed to do that. Could be a bug though.

Also a lot of my problem right now is that I have a lot of fields in my types, and when I make locals in methods I have to make sure that there isn't already a field with that name. And when I look at my code I don't instantly know whether a variable is a local or a field.


Also the Eclipse IDE will show you which fields/variables your types have, and their scopes.


Does that mean that when I am coding in a method and I type a word it becomes a different color if it is a field of the type? That would be really good.