[Gambas-user] Distribution of custom shared libraries
Cedron Dawg
cedron at exede.net
Mon Feb 25 15:30:16 CET 2019
The best to learn how to devellop components is to read existing ones from Benoit, or mine. We try to keep a coding noclamenture.
How to naming vars
How arrange code
And some usual way to draw the api.
This is important for the user experience. So he can use your component without learning curve.
I'll keep a look this evening \uD83D\uDE0A
Ps : Benoit and Tobias's code are better than mine \uD83D\uDE0A
Look at
gb.form
gambas/comp/src/gb.form
Regards,
Fabien
=====================================================================
Hi Fabien,
I have a Tobias' gp.joystick, and Benoit's gp.gsl that I have been looking at. Haven't looked at yours yet.
I've been coding for more than forty years, across many platforms/languages and have a coding style that works well in all. I don't care for cryptic names or crammed code. If you can't print it out and tape in on the wall and stand a good distance away and tell which part is which, your formatting is lacking.
Sorry, Hungarian notation sucks. Nor is it universally applied in this code.
Matching arrangement: Check
"And some usual way to draw the api. ": Not sure what you mean.
Naming variables: I'm crazy, you should do it my way.
A variable name should fall into two categories:
1) Simple one or two letter (lower case), extremely local
2) A proper name
A proper name has three parts: prefix + basename + suffix
The prefix gives the scope of the variable and tells you where it is defined
"the" local routine variable
"arg" calling argument, read only
"ret" calling argument, expected to be updated
"my" module level variable, or property
"our" static module level, or class property
The basename is optional or can be compound. It is an occurrence specifier. If only one of a kind is being used, it isn't really necessary. Proper case, no underscores.
The suffix tells you the kind of thing, which also implies its type. For instance, "Count" obviously means an integer, "Name" obviously means a string.
Example:
Typical way, you have a class with a property called lastName (following Java lower case convention):
String lastName;
...
void setLastName( String lastName )
{
this.lastName = lastName;
}
My Way:
String myLastName;
...
void setLastName( String argLastName )
{
myLastName = argLastName;
}
First off, way clearer. Second, and more importantly, now I want to copy it and change it to "FirstName". You do the math.
Parallel Arrays (aka pseudo objects):
theUser_FirstName[]
theUser_LastName[]
theUser_PhoneNumber[]
theUser_EmailAddress[]
theUser_StreetAddress[]
Syntactically, the "_" replaces a "." and then the code appears to be an object. Only difference is the array index is at the end.
Real Object: theUser[u].FirstName
Pseudo Object: theUser_FirstName[u]
If you follow these conventions, your code becomes almost readable as natural language:
return theResult
My two, very experienced, cents.
More information about the User
mailing list