Reality drives me to write less clean code, sorry for mistakenly posting in D.announce
davidl
davidl at 126.com
Thu Oct 11 03:58:44 PDT 2007
First practice:
char[] text;
char* p;
char* end;
Version1:
p=text.ptr;
end= text.ptr+length;
we use p to scan over the text, and end as a mark.
Version2:
text[blah] to scan over the text.
Obviously version 2 is cleaner, but slower.
Second practice:
version 1:
enum basictype
{
tint,
tint32,
tunsint32,
tlong,
tuslong32,
tcomplex,
tcomplex64,
tcomplex80,
timaginary,
timaginary64,
timaginary80,
}
class Type
{
basictype bt;
}
we do some switch-case to test what on earth this type is in this case.
version2:
class Type{}
interface TypeReal:TypeComplex{}
interface TypeImaginary:TypeComplex{}
interface TypeComplex{}
interface Type32bit{}
interface Type64bit{}
interface Type80bit{}
interface TypeUnsigned{}
class TypeNumber:Type{}
class TypeUSInt:TypeNumber, Type32bit, TypeUnsigned{}
class TypeInt:TypeNumber,Type32bit {}
class TypeComplex64:TypeNumber,TypeComplex, Type64bit {}
class TypeComplex80:TypeNumber,TypeComplex, Type80bit{}
class TypeImaginary:TypeNumber,TypeImaginary {}
class TypeImaginary64:TypeNumber,TypeImaginary, Type64bit{}
Honestly, I prefer version2 a little bit more to version1.
But, version2 gets too much runtime penalty.
Ideas?
--
使用 Opera 革命性的电子邮件客户程序: http://www.opera.com/mail/
More information about the Digitalmars-d
mailing list