Using D
Ary Borenszweig via Digitalmars-d
digitalmars-d at puremagic.com
Mon Aug 25 10:36:21 PDT 2014
On 8/25/14, 1:26 PM, ketmar via Digitalmars-d wrote:
> On Mon, 25 Aug 2014 16:08:52 +0000
> via Digitalmars-d <digitalmars-d at puremagic.com> wrote:
>
>> Beta was static and compiled directly to asm.
> it's not hard to compile dynamic language to native code. what is hard
> is to make this code fast. this requires very sofisticated compiler
> which can eliminate as much indirect calls as possible. that's why we
> have the ability to create non-virtual methods in languages like D or
> C++. "everything is object" is a nice concept, but it has it's price.
Not at all. In Crystal everything is an object, it compiles to native
code and it's super fast. All methods are virtual (and there's actually
no way to make a method non-virtual).
The trick is to not use virtual tables, but do multiple dispatch (or
only use virtual tables when needed). If you have:
a = Foo.new
a.some_method
then it's obvious to the compiler that some_method belongs to Foo: no
virtual call involved, no virtual table lookup, etc: just a direct call.
If you have:
x = 1.abs
1 is still an object, only it's memory representation is 32 bits, and
the method turns out to be just like a function call.
To me, the real problem with OOP is to automatically relate it to
virtual tables, interfaces, etc.
More information about the Digitalmars-d
mailing list