Maker Pro
Maker Pro

Writing Scalable Code in Delphi 2007, An idea !

S

Skybuck Flying

Hello,

As "we" already explored in another thread called "Flexible Instruction Set
Encoding" intel/amd did not implement a flexible instruction, nor do those
people that replied in that thread think it was an interesting or valuable
idea.

Today I woke up and just had an incredible smart and interesting idea how to
write scalable code in Delphi 2007 !

What I want to achieve is turn some classes which use 32 bit integer math
into generic classes so that they can use 32 bit math or 64 bit emulated
math or even 64 "real" math and now comes the tricky part while maintaining
only one code base for the "generic classes" !

So that when I need to extended or bug fix the classes I only need to do it
at one place !

And now here is the idea which I present to the whole fucking world:

The idea is to:

1. Use Delphi's 2007 operator overloading to implement math classes for
example:

TSkybucksInt32
TSkybucksInt64Emulated
TSkybucksInt64

TSkybucksUint32
TSkybucksUint64Emulated
TSkybucksUint64

2. Make the classes use one of these skybuck math classes. Actually there
should be a generic class or something like that.

Maybe something like:

TSkybuckGenericIntegerClass

Then the rest can be derived from that.

3. Now at runtime the class can decide which math it needs, 32, 64 emulated
or 64 bit and then it can instantie this class.

Sounds good to me.. but will it work ? and will it be fast ? These two
points need to be investigated:

1. Will operator overloading intro call overhead ? (Maybe not)

2. Is it possible ?

Suppose it's all good and possible then the other class can work as follows
for example:

// concept code:

SomeClass := TSomeClass.Create;

if FileSize <= 32 bits then
begin
SomeClass.MathClass := TSkybucksInt32; // full speed 32 bit math ! OH
YEAH !
end else
if (FileSize > 32) and (FileSize <= 64 bits) then
begin
if (Operating System is 32 bit) then
begin
SomeClass.MathClass := TSkybucksInt64Emulated; // slower emulated 64
bit math !
end else
if (Operating System is 64 bit) then
begin
SomeClass.MathClass := TSkybucksInt64;
end;
end;

Some questions remain:

1. Is it necessary to create an instance of skybuck's ints ?
2. Would it be better to pass it via a constructor parameter (Normally I
don't like doing this) ?

These will be explored below:

Open questions remain:

3. Can records be inherited ?

4. Possibly can records be polymorphic ? <- not sure if that is required.

Now SomeClass could be written to use code as such:

type
TsomeClass = class
private
GenericInteger1 : TSkybucksGenericInteger;
GenericInteger2 : TSkybucksGenericInteger;
GenericInteger3 : TSkybucksGenericInteger;
public
procedure DoSomeCalculations;
end;

This class declaration/definetion or whatever shows that these generic
integer possible need to be created before the someclass can be used to
perform calculations, so it might be necessary to initialize these generic
fields. Doing this via a constructor parameter is an option or alternatively
a special initialization procedure.

I don't like passing things to constructor parameters... maybe I'll make an
exception for this case, and yes I think this could be smart so that when
SomeClass is cleaned up it automatically cleans up the generic fields as
well example:

Now things become clear:

TSkybucksGenericMath class need to be a class of classes... as to pass the
type of the required class to this constructor:

So Skybucks generic math class becomes a class of classes declared as
follows:

TSkybuckGenericMathClassess = class of TSkybucksGenericMath; // something
like this ? I am not sure... yes probably.

let's go on:

constructor TsomeClass.Create( MathClass : TSkybucksGenericMathClassess );
begin
inherited Create;
GenericInteger1 := TSkybucksGenericMathClasses.Create;
GenericInteger2 := TSkybucksGenericMathClasses.Create;
GenericInteger3 := TSkybucksGenericMathClasses.Create;
end;

Usage example: (Real easy ofcourse:)

var
SomeClass : TSomeClass;
begin
if filesize > blablabla and blablablabla then
begin
SomeClass := TSomeClass.Create( TSkybucksInt64Emulated );
end else
blablablabla
end;

Looking pretty good, looking much better !

Now what if parts of the code needs only half of the bits ?! to do something
wacky...

Could be nice if the generic math classes could return something...
Excellent !

for example:

TsomeClass = class
private
mHalfGenericInteger1 : TSkybuckGenericMath;

etc;
end;


Now each Skybucks int implementation could have a function which returns a
new class type which represent half of the bits, example:

TSkybucksInt64Emulated = class(TSkybuckGenericMath)
private

public
function HalfGenericInteger : TSkybucksGenericMathClassess;
end;

function TSkybucksInt64Emulated : TSkybucksGenericMathClassess;
begin
result := TSkybucksInt32;
end;


Now SomeClass can simply do it's thing:

procedure TSomeClass.DoSomeCalculations;
begin
mGenericInteger3 := mGenericInteger2 * mGenericInteger1;


// generic classes might have extra functions to return lower or upper
half bits, could be handy !
mHalfGenericInteger := mGenericInteger3.ReturnUpperHalf;

// alternatively type casting might be used but this will create complex
and more code and possibly buggy code... I don't like it... but here
// is some concept
// code:
mHalfGenericInteger1 := MathClass.HalfGenericInteger(
mGenericInteger1 ); // explicit typecast conversion overloaded operator
needed.
end;

as I already explored in the past, Delphi's 2007 explicit typecast
conversion operator overloading is a bit dangerous and might not always do
what the programmers wants... and it's lot s of work to implement all
possible type cast variations.

But it might work... not all typecast operator overloaders needed ;)

There two ways to return half of the bits.

Ofcourse the function idea is preferred... because it can return whatever
you want:

ReturnUpperHalf
ReturnLowerHalf

^^^ very nice !

Well there you have it folks !

Skybuck just presented a concept to the whole fucking world !

How to:

1. Write Scalable Classes with Scalable Math !

2. How to keep the speed incredibly high !

(Math class constructors should be kept to absolutely minimum for maximum
speed)

(User classess should be created/destroyed only once if possible, otherwise
use recycle pools for objects if required)

Is the world ready for Skybuck's concepts ?

Two possibilities:

1. Delphi 2007

2. C++

Questions:

1. Is Skybuck's concept new ? In that case: To fucking bad, now it can't be
patented because I just published it !

Ofcourse there are always people saying no, but those people should read
this concept really carefull.. because some things might look same.. but is
it really the same ?! Carefull reading is required !

2. Can Delphi 2007 currently implement this concept ? This remains to be
seen, I shall explore this myself.

There are two variations of Delphi 2007, .NET and Win32. .NET has better
operator overloading support, I don't use .NET :( I like win32. I NEED IT
FOR WIN32 !!!!!

3. Can C++ implement these concepts ? I would be surprised if it cannot !

This will have to be explored by other people, I don't write code in C++, if
Delphi can't do I might explore C++ but don't count on it !

If Delphi 2007 for Win32 can not implement because of missing operator
overloading support for classes, or because of missing inheritance for
records than clearly the Delphi language would GREATLY benefit from these
features because it allows to do everything I wrote above... and that in
that case a request for these features should not even be necessary.

It should be TOP PRIORITY =D LOL Might even make writing a 64 bit Delphi
compiler much easier !

Might even make changing the VCL to support 64 bit A SNAP !

Only one code bases needed ! and possible even fully runtime scalable !

That last possibility might be over their head.

Borland might simply hard code it for a 64 bit Delphi version:

var
MathClass : TSkybuckGenericIntegerClassess = TSkybuckInt64;

Code changes for VCL:

Replace all integer declarations whith GenericInteger and add a
MathClass.Create statement to VCL constructors !

FUCKING NICE !

Well I am done writing about this new concept.

I shall go exlore after I have fucking breakfast LOL.

HAHAHAHAHA

Oh man another great idea while I woke up.

**** I had some good ideas while lieing in BED.

Fucking Winston Churchile was write... BEST IDEA COME IN BED LOLOLOLOL.

Skybuck's Software Development Company would have an insane ammounts of BEDS
in it's building some PEOPLE CAN SLEEP ON IT =D and have great ideas when
they wake up ! or have a fucking rest !

Me thinks definetly worth it ! ;) :) =D =D =D

Bye,
Skybuck.
 
S

Skybuck Flying

Skybuck Flying said:
Hello,

As "we" already explored in another thread called "Flexible Instruction
Set Encoding" intel/amd did not implement a flexible instruction, nor do
those people that replied in that thread think it was an interesting or
valuable idea.

Today I woke up and just had an incredible smart and interesting idea how
to write scalable code in Delphi 2007 !

What I want to achieve is turn some classes which use 32 bit integer math
into generic classes so that they can use 32 bit math or 64 bit emulated
math or even 64 "real" math and now comes the tricky part while
maintaining only one code base for the "generic classes" !

So that when I need to extended or bug fix the classes I only need to do
it at one place !

And now here is the idea which I present to the whole fucking world:

The idea is to:

1. Use Delphi's 2007 operator overloading to implement math classes for
example:

TSkybucksInt32
TSkybucksInt64Emulated
TSkybucksInt64

TSkybucksUint32
TSkybucksUint64Emulated
TSkybucksUint64

2. Make the classes use one of these skybuck math classes. Actually there
should be a generic class or something like that.

Maybe something like:

TSkybuckGenericIntegerClass

Then the rest can be derived from that.

3. Now at runtime the class can decide which math it needs, 32, 64
emulated or 64 bit and then it can instantie this class.

Sounds good to me.. but will it work ? and will it be fast ? These two
points need to be investigated:

1. Will operator overloading intro call overhead ? (Maybe not)

2. Is it possible ?

Suppose it's all good and possible then the other class can work as
follows for example:

// concept code:

SomeClass := TSomeClass.Create;

if FileSize <= 32 bits then
begin
SomeClass.MathClass := TSkybucksInt32; // full speed 32 bit math ! OH
YEAH !
end else
if (FileSize > 32) and (FileSize <= 64 bits) then
begin
if (Operating System is 32 bit) then
begin
SomeClass.MathClass := TSkybucksInt64Emulated; // slower emulated 64
bit math !
end else
if (Operating System is 64 bit) then
begin
SomeClass.MathClass := TSkybucksInt64;
end;
end;

Some questions remain:

1. Is it necessary to create an instance of skybuck's ints ?
2. Would it be better to pass it via a constructor parameter (Normally I
don't like doing this) ?

These will be explored below:

Open questions remain:

3. Can records be inherited ?

4. Possibly can records be polymorphic ? <- not sure if that is required.

Now SomeClass could be written to use code as such:

type
TsomeClass = class
private
GenericInteger1 : TSkybucksGenericInteger;
GenericInteger2 : TSkybucksGenericInteger;
GenericInteger3 : TSkybucksGenericInteger;
public
procedure DoSomeCalculations;
end;

This class declaration/definetion or whatever shows that these generic
integer possible need to be created before the someclass can be used to
perform calculations, so it might be necessary to initialize these generic
fields. Doing this via a constructor parameter is an option or
alternatively a special initialization procedure.

I don't like passing things to constructor parameters... maybe I'll make
an exception for this case, and yes I think this could be smart so that
when SomeClass is cleaned up it automatically cleans up the generic fields
as well example:

Now things become clear:

TSkybucksGenericMath class need to be a class of classes... as to pass the
type of the required class to this constructor:

So Skybucks generic math class becomes a class of classes declared as
follows:

TSkybuckGenericMathClassess = class of TSkybucksGenericMath; // something
like this ? I am not sure... yes probably.

let's go on:

constructor TsomeClass.Create( MathClass : TSkybucksGenericMathClassess );
begin
inherited Create;
GenericInteger1 := TSkybucksGenericMathClasses.Create;
GenericInteger2 := TSkybucksGenericMathClasses.Create;
GenericInteger3 := TSkybucksGenericMathClasses.Create;
end;

Usage example: (Real easy ofcourse:)

var
SomeClass : TSomeClass;
begin
if filesize > blablabla and blablablabla then
begin
SomeClass := TSomeClass.Create( TSkybucksInt64Emulated );
end else
blablablabla
end;

Looking pretty good, looking much better !

Now what if parts of the code needs only half of the bits ?! to do
something wacky...

Could be nice if the generic math classes could return something...
Excellent !

for example:

TsomeClass = class
private
mHalfGenericInteger1 : TSkybuckGenericMath;

etc;
end;


Now each Skybucks int implementation could have a function which returns a
new class type which represent half of the bits, example:

TSkybucksInt64Emulated = class(TSkybuckGenericMath)
private

public
function HalfGenericInteger : TSkybucksGenericMathClassess;
end;

function TSkybucksInt64Emulated : TSkybucksGenericMathClassess;
begin
result := TSkybucksInt32;
end;


I see I didn't give an example of this idea above here is the example:

The constructor of SomeClass is now extended because the SomeClass need half
of the bits for some reason of the "main" bits:

constructor TsomeClass.Create( MathClass : TSkybucksGenericMathClassess );
begin
inherited Create;
GenericInteger1 := TSkybucksGenericMathClasses.Create;
GenericInteger2 := TSkybucksGenericMathClasses.Create;
GenericInteger3 := TSkybucksGenericMathClasses.Create;

// this creates half of the bits of the main bits above.
HalfGenericInteger1 :=
TSkybucksGenericMathClasses.HalfGenericInteger.Create;
end;

^^^ Nice example should work ! ;) ^^^

Also for those wondering how the math classes would look real simple, for 32
bit and 64 bit emulated simply use delphi's already implemented types since
Delphi is pretty efficient about it, unless you as an assembler think you
can implement a 64 bit emulated multiple and division faster ?!

Example of an operator overloader: (details, not that big of deal, it's the
easiest part I think, but for those that have no clue here it is):

type
TSkybuckInt64Emulated = record
mInteger : Int64;
end;

class operator TSkybuckInt64Emulated.Add( A : TSkybuckInt64Emulated; B :
TSkybuckInt64Emulated): TSkybuckInt64Emulated;
begin
result.mInteger := A.mInteger * B.mInteger;
end;

^^^ Something like that.

Then I'll give one more example... but this one I don't know exactly.. here
is where assembler geniuses might come in handy.. but it's probably not that
big of deal could figure it out myself... maybe it's possible to use rex
prefix opcodes to call 64 bit instructions of 64 bit machine/operating
system:

class operator TSkybuckInt64Emulated.Add( A : TSkybuckInt64Emulated; B :
TSkybuckInt64Emulated): TSkybuckInt64Emulated;
begin
asm
rex mul c.mInteger, A.mInteger, B.mInteger ?????
end;
end;

Would be nice to see an example of "REX" prefix and MUL in action ;)

Even nicer: DIV :)

Prefix field might be able to be code with DB's or so:

DB 66; mul bbla bla seen that before back in the 32 bit days. or 16 bits
days... yeah 16 bit days it probably was.

(Bye Skybuck !)
 
S

Skybuck Flying

Well,

I just quickly tested this idea, records can't be inherited in Delphi 2007
for Win32.

And I already know classes don't support operator overloading in Delphi 2007
for Win32.

Is my idea ahead of it's time ?

I don't think so... C++ has had operator overloading for years, at least 7
years !

Delphi is just lagging, lagging, lagging behind on this.

I am not giving up yet, I shall try and see if I can find another way to
implement it in Delphi 2007 for Win32.

But I am not counting on it.

Oh well.

Bye,
Skybuck.
 
S

Skybuck Flying

A quick google on writing scalable software or code in c++ returned zero
hits.

Apperently C++ programmers have generics so far up their ass they are unable
to write any form of scalable code that scales at runtime.

Apperently this idea is even way ahead of C++ programmers as well.

This idea is just too good I just can't leave it alone.

I shall have to do the unthinkable and write C++ code to test and see this
idea in action THE HORROR !

Bye,
Skybuck.
 
R

Rudy Velthuis

Skybuck said:
I don't think so... C++ has had operator overloading for years, at
least 7 years !

Delphi is just lagging, lagging, lagging behind on this.

No, it isn't. Delphi for .NET has operator overloading already. and
Delphi also had operator overloading for a long time already, but only
for Variants.

You don't seem to be aware of the requirements for operator
overloading. It is impossible to do for reference types (like Delphi
classes) if you don't have garbage collection. Note that in C++, it is
only possible for classes and structs that are used AS VALUE TYPES,
like records in Delphi, and NOT AS REFERENCE TYPES.

If you don't get this, you are the idiot I already thought you were. <g>
 
S

Skybuck Flying

OH JEZUS CHRIST.

THE HORROR HAS ALREADY STARTED.

I can't even create the full project name:

TestWritingScalableSoftwareGenericMath

^^^ Visual Studio .NET 2005 complains, project name length to long ?! OH MY
GOD !!!! ^^^

Me shudders at what is to come !

Bye,
Skybuck.
 
R

Rudy Velthuis

Skybuck said:
A quick google on writing scalable software

It already exists since ages, it just has a different name. It is
called generics, and it is much more than just "scalable".

Look for C++ templates, Eiffel generics, Ada generics, Smalltalk
generics, .NET generics, Java generics, etc.

The coming Delphi for .NET will have generics.
 
Top