correct way to create boiler plate code

dmerrio rdmerrio at gmail.com
Mon May 16 15:28:30 PDT 2011


Thanks for the formatting tips. Copy and pasting kind of messed up
the formatting, not that it was good to start with. I am still
developing a coding style.

== Quote from bearophile (bearophileHUGS at lycos.com)'s article
> dmerrio:
> > import main; //class definition of rng
> > import std.math; //trig functions
> > import std.conv; //to!double
> > import std.string; //toupper
> >
> > double transFunc(alias transedentalFunc)(rng aRng){
> > 	try{return(transedentalFunc(aRng.getCellValue().coerce!
> > (double)));} //cellValue stored as a Variant
> > 	catch{return(transedentalFunc(to!double(aRng.getCellValue
> > ().coerce!(string))));} //replicate spreadsheet behavior and
> > convert to a number
> > }
> >
> > //Example 1 of boilerplate code
> > double SIN(double aReal){return(sin(aReal));}
> > double SIN(string aStr){return(sin(to!double(aStr)));}
> > double SIN(rng aRng){return(transFunc!(sin)(aRng));}
> Mine is not an answer that directly helps you solve your
problem. Experience shows that messy code doesn't help you see
your problems, and sometimes it even hides bugs. So I suggest you
to reformat your code in a more human way, use more normal naming
conventions, and use named imports if you want to import just some
names.
> This means writing:
> import std.conv: to;
> Instead of:
> import std.conv; //to!double
> To put a newline before the closing brace, to add spaces and
newlines where they are belong, and so on. This helps a lot.
> Bye,
> bearophile



More information about the Digitalmars-d-learn mailing list