...hardwareserial.pas?
I was looking through the attached
hardwareserial.pas file and had some thoughts. Since its content is a translation of C++ code into Object Pascal, you had to work around the problem of the clash of function names:
begin() and
end() (as is known, they clash with keywords in Pascal, but not in C++). You adopted the closest and simplest possible solution, i.e. prefixing the names of both functions with an underscore. To me, these underscores seem a bit inelegant. I think that functions/procedures with names starting with an underscore may seem unusual to some people (not me!), and intended for some special purpose, or to be avoided rather than used (which is of course not true). In any case, these underscores may confuse some people (for example, beginners in programming). This impression may come from the fact that underscores are used quite often in C (and pathologically overused in Python), where they do have some quite specific meanings. So maybe it would be advisable to give these functions different names?
The following approaches come to mind:
- leaving the current solution (the one you used), i.e. function names that conflict with keywords are preceded by an underscore,
- replacing conflicting names with other words that are close in meaning, e.g. Start()/Stop() or Run()/Finish(),
- replacing conflicting names with words that were usually given to old-style Pascal objects, i.e. Init()/Done(),
- replacing conflicting names with words that are often used when accessing a resource (here: hardware) and releasing that resource, i.e. Open()/Close().
Solution 4 would suit me, i.e. using the names:
Open()/
Close(). The benefits are:
- avoiding underscores starting procedure names,
- names will begin with a capital letter.
Of course, changing the names of these functions from
_begin() and
_end() to (let's say)
Open() and
Close(), has the disadvantage that if someone uses code examples coming directly from Arduino (making a change from C++ to Pascal) to write their source code, they will be confused. They may not guess that
begin() and
end() from C++ code should be replaced (in this case) with
Open() and
Close() in Object Pascal code. It seems that there is no ideal solution here.
Anyway, these are just some loose thoughts. Maybe other forum members will comment on this.