space on the class interface you should see a list of method you can override and if I'm not mistaken the interface methods are there too.
If you need an IDE to use a language efficiently it is a bad language
erm doesn't compute really you couldn't access them outside the class anyway.
You can, if they are public
much? how much slower? slower they are.
On my computer:
Class method inlined: 225 ms
Fields access: 255 ms
Class method: 366 ms
Interface method: 451 ms
That means that with a refcounted non interface, the program would run
twice as fast!
(and I am using it in an interpreter for my programming language. So I have a lot of methods doing nothing except basic arithmetic)
program Project1;
{$mode objfpc}{$H+}
uses bbdebugtools;
type
iinc = interface
procedure inc;
end;
{ tc }
tc = class(TInterfacedObject, iinc)
x: integer;
procedure inc;
procedure incin; inline;
end;
procedure tc.inc;
begin
x := x + 1;
end;
procedure tc.incin;
begin
x := x + 1;
end;
var c : tc;
i: iinc;
j: Integer;
k: Integer;
r: Integer;
begin
logging:=true;
for r := 1 to 10 do begin
c := tc.Create;
i := c;
c.x := 0;
startTiming('field');
for j := 1 to 100000000 do c.x:=c.x+1;
stopTiming('field');
c.x := 0;
startTiming('class');
for j := 1 to 100000000 do c.inc;
stopTiming('class');
c.x := 0;
startTiming('class inline' );
for j := 1 to 100000000 do c.incin;
stopTiming('class inline');
c.x := 0;
startTiming('interface');
for j := 1 to 100000000 do i.inc;
stopTiming('interface');
end;
end.
erm as long as the var is a class
Yes, that's why I want it to be a class
yes you can if it is an interface yeah that doesn't work.
Exactly
true inheritance is a problem of course you can have a class that implements the basics and use the implements keyword, in which case it is easy.
Not if you need to inherit from a non-interface
well that is a garbage collection in my eyes though.
More like pretty syntax
Usually garbage collection means neither scopes nor ref-counting, but something like mark-and-sweep stopping the whole program.
1. There is no guard against adding it to something outside the function scope (like a tlist field in the class)
There we just have to be smart
2. The allocation will be active for the whole scope
inline var statements within the begin..end block would also be nice.
With variable available after the var and destroyed at the next end
3. Like ansistring it needs an implicit try finally
Interfaces, too
You need a finally in most cases you uses classes, and most people are not smart and forget it
And IMHO the construct (purely using an object locally in one method) is not that common enough to warrant special syntax.
When I code in C++ I use them probably for around 80% of all variables
Everything except GUI stuff