Android Tutorial [B4X] Public variables, custom types, ...

What I'm about to write would be more suitable for Erel's thread: [B4X] "Code Smells" - common mistakes and other tips, but it's just my opinion and I don't know if he agrees.

I'll give you an example right away:



clmn is a B4XTableColumn; what its InternalSortMode is? What values should I assign to it? (create constants, for this; better an Enum). There is no comment.

The lack of a comment may not be due to the author's lack of time or laziness (the author is Erel ? He will kill me for this, or he will block me forever?), but to having used a public variable to which it is not possible to associate comment lines.

It is also not possible to associate comments with the elements of a custom type.

Also for this reason, it is preferable to create Properties ("special" public Subs) rather than public variables in your classes.
For the same reason, it is preferable to create classes rather than custom types.

The comments are useful to everyone, even to the author himself who, over time, will forget what a certain member of a class that he himself wrote is for.
 
Last edited:

Mahares

Expert
Licensed User
Longtime User
Sorry. I could not tell if your thread is a wish, example or tutorial, or if you are addressing it to Erel or everyone else. But, sometimes the choice of words in the properties or methods makes it difficult to tell what you need to follow it with. In this case: Instead of: c.InternalSortMode , I would have used: c.InternalSortOrder. In the SQLite doc, DESC and ASC are referred to as sort order.
 

LucaMs

Expert
Licensed User
Longtime User
I could not tell if your thread is a wish, example or tutorial
Tip? Hint?

or if you are addressing it to Erel or everyone else
To everyone, including me.

The name of variables, class members, views, etc. it is important but it will never be exhaustive, it will not always be enough to make you understand exactly what they are and, in the case of properties, what values to assign to them.

The one in the image is just an example; I could publish hundreds of them.
 

RB Smissaert

Well-Known Member
Licensed User
Longtime User
I think this is a very good idea and will apply that.

RBS
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Custom types are very useful and I wouldn't automatically prefer classes over types. Custom types are lighter, can be serialized and are very "simple". A custom type is a bag of fields with zero logic. You know what you are getting. This can be an advantage.

Properties vs. public variables is a matter of taste and you can't be wrong with properties.

The "Internal" fields are indeed a workaround for the lack of visibility scope in this case. Nothing is perfect
 

LucaMs

Expert
Licensed User
Longtime User
Just last Monday I suggested using custom types ?
(https://www.b4x.com/android/forum/threads/ottimizzazione-routine.158075/post-970574)

They have advantages and disadvantages compared to classes.
In this case, the disadvantage I'm referring to is the impossibility of showing contextual help in the editor; same thing for variables (public, instead of properties). Maybe some time ago I suggested you try implementing "viewable comments" for variables as you can achieve with Subs (am I remembering correctly?). I don't know if you tried or not.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…