Or “write code like you immediately forget what you wrote” so it’s not a guessing game to figure out why you wrote what you wrote way back when.
What do I mean by that ?
Write code CLEARLY. Use constants liberally and give them good meaningful names.
So instead of writing a line like
If asc(key) = 16 or asc(key) = 204 then
where 16 and 204 are not obvious to everyone maybe write this as
Const ctrlP = 16
Const F5 = 204
if asc(key) = ctrlP or asc(key) = F5 then
And then even when you go back and look at this code in 6 months even you won’t have to guess what 16 and 204 mean.
This question isnt asked that often. But I think it should be.
When you create classes, modules, layouts or anything else in Xojo you should make everything as private as it needs to be. And no more. And as public as it needs to be. And no more.
But exactly what does that mean ?
I would say that you should normally start with most things in classes being protected.… Read the rest
On the forum there was a suggestion that a person should use a container control that had a few controls embedded in it at design time. And then when using that container control that they should skip providing an API that the container presented and just reach inside the container and manipulate the controls it contain directly.… Read the rest
When you create a custom control from a canvas, container control or some other base class its not unusual to use raise event to create new events like “BeforeButtonPressed”, “AfterButtonPressed” or to just make it so you;r control can implement normal events like Open, Close, etc and pass then along.
You’ll see code using raiseevent to cause these events to be raised on any instances.… Read the rest
An interesting question posed by a relatively new user came up on the forums. It had to do with how the Array() function worked and how he could force it to return an array of variants to call his method.
His method was defined like
BuildMenu( base as menuitem, params() as variant)
And he would call it like
Result = BuildMenu (base, Array ("Run", False, "Edit", "Rename", "Delete") )
and this would build up a menu from the base item and append menu items to it.… Read the rest
Not for your children (although that is important too since kids can be incredibly harsh and will pick on kids with names that they think sound different or odd)
This is to do with naming methods, properties, and just about everything else in your Xojo projects.
A good name indicates a number of things to anyone who reads the code.… Read the rest