MALOC 0.1
|
public double Foo::bar(int i, double d)
would be declared as
double Foo_bar(Foo *thee, int i, double d)
where VEXTERNC
is a compiler-dependent macro, the underscore _
replaces the C++ double-colon ::
, and thee
replaces the this
variable implicit in all C++ classes. Since they do not appear in public header files, private functions could be declared in any format pleasing to the user, however, the above declaration convention should generally be used for both public and private functions. Within the source code, the public and private function declarations/definitions are prefaced by the macros VPUBLIC
and VPRIVATE
, respectively. These are macros which reduce global name pollution, similar to encapsulating private data withing C++ classes.
public void Foo::Foo(int i, double d)
would be declared as
Foo* Foo_ctor(int i, double d)
which returns a pointer to the newly constructed Foo
object. Likewise, a destructor declared as
public void Foo::~Foo()
in C++ would be
void Foo_dtor(Foo **thee)
in Clean OO C.
#define
statements in the public header file. See any of the MALOC header files for more examples on the Clean OO C formalism.Tabs and spaces ==> Probably the most important rule: NO TABS!
Use ONLY SPACES, NO TABS, in source code. When indenting a code block, ALWAYS USE EXACT 4 SPACES, no more, no less. While this single anal rule seems excessive, in my experience it is the single most useful code formatting guideline one can impose, in terms of producing code written by many different developers that can be read and understood quickly by other developers using the same convention. If four spaces (rather than two or three) forces you to use more than 80 columns for nesting loops/etc, then your routine is too complex to be read by someone else anyway and it should be split into two or more routines.
#define VTRUE 1 #define VFALSE 0 #define VABS(x) ((x) >= 0 ? (x) : -(x))
UpperMixed ==> Class name, or class constructor or destructor. Examples:
C++: class Mesh { ... }; Mesh(void) { ... } ~Mesh(void) { ... }
Clean C: typedef struct Mesh { ... } Mesh; void Mesh_ctor(Mesh *thee) { ... } void Mesh_dtor(Mesh *thee) { ... }
NOTE: The "this" pointer is implicitly used in C++. We simulate this coding style with the "thee" pointer in Clean C. By using a name different than "this", we continue to have a legal C++ program.
lowerMixed ==> A class member function or generic function. Examples:
C++: Class Mesh { ... void print(void) { ... } ... } void Mesh::plot(void) { ... }
Clean C: void Mesh_print(Mesh *thee) { ... } void Mesh_plot(Mesh *thee) { ... }
_private data ==> Pre-fixed with an underscore, such as: vint _dim.
I don't always adhere to this, but it helps make it clear when you are doing something unsafe with private data that you should have written an accessor member function to handle. (UPDATE: I no longer allow this practice in MALOC, because symbols beginning with an underscore often conflict with internal compiler symbols in GCC and other ANSI-C compilers.)
Datatypes ==> Use only standard or compatible datatypes.
Beyond the stuctures used to define classes, only standard datatypes are used as primitive types in MALOC, such as char, int, float, and double.
Core structures ==> Refer to headers vel.h and ves.h in the GEM library for examples.
if (cond) { }whereas I find the following usually more readable:
if (cond) { }However, for complete routines I do follow Richard's approach:
void func(void) { ...stuff... }If something is very simple then I break all rules:
int myId(void) { return id; }
MALOC = < Minimal Abstraction Layer for Object-oriented C > Copyright (C) 1994--2000 Michael Holst <mholst@math.ucsd.edu> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.