Re: On the benefits of reflection

Douglas Cox <[email protected]> Tue, 19 Mar 2013 17:17:05 -0400
Newsgroups gmane.games.devel.sweng
Message-ID <CA+i4re6Kp=zN1e6r=n3Be-sneHj23bt5hzqjiDm_TySZatmHjQ@mail.gmail.com>
--===============0619998535==
Content-Type: multipart/alternative; boundary=e89a8ffbae5b9a112604d84da02a

--e89a8ffbae5b9a112604d84da02a
Content-Type: text/plain; charset=ISO-8859-1

> You use reflection to implement your own garbage collector? This is C#
> right? Does your GC just collect resources that aren't needed anymore
> or does it actually do a better job of managing memory etc?
>

That was not exactly C# despite what it looks like -- it's our own variant
and compiler.  The GC uses minimal reflection in the sense that our type
information includes a small bit of information (provided by the compiler)
useful for tracing through object references.  It's a multi-generational
GC, a bit tailored to our needs.  It supports finalizers, deals with
multiple threads, etc.  It is used pretty much like the one in C#.

Honestly, after 12 years we just got tired of C++'s issues (see this thread
for a good example), and so far love how clean it is to write the new code.
 When we need to write some C/C++ code it's as easy as:

void Foo()
{>
   // c++ code goes here.
<}

It may sound like a pain to get working, but if you look at some of
runtime-recompile work, and then realize that most of the annoying parts of
that can also be hidden behind a 'pre-compiler', it isn't as bad as it
sounds.  Especially when you know the data layout of your own vtables and
can run through all allocations fixing up pointers, etc.


> To add to the discussion about benefits of reflection:
>
> Coming from Ruby I'm always looking for ways to make things easier to
> express using reflection. I think serialization/deserialization is
> just one usecase for this. For example C# is a language that's more
> geared towards object oriented architecture than to entity systems,
> but using reflection you can generate the code that links your
> components together at runtime so there's not a lot of boilerplate
> code required for every component.
>

Yup.

Sort of related to reflection, recently I made a game as an academic
> exercise in javascript using an aspect oriented programming library.
> AOP has a similar philosophy of taking separation of concerns to the
> next level. It worked out very well, you can have the game engine
> drive the views without having any hooks or view related code in the
> engine. Granted ofcourse this was a javascript exercise, not at all as
> resource constrained as a big console game.
>

Sounds cool. Do you have some specific examples?

-Doug

--e89a8ffbae5b9a112604d84da02a
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><div class=3D"gmail_extra"><div class=3D"gmail_quote">=
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex">You use reflection to implement your own gar=
bage collector? This is C#<br>

right? Does your GC just collect resources that aren&#39;t needed anymore<b=
r>
or does it actually do a better job of managing memory etc?<br></blockquote=
><div><br></div><div style>That was not exactly C# despite what it looks li=
ke -- it&#39;s our own variant and compiler. =A0The GC uses minimal reflect=
ion in the sense that our type information includes a small bit of informat=
ion (provided by the compiler) useful for tracing through object references=
. =A0It&#39;s a multi-generational GC, a bit=A0tailored=A0to our needs. =A0=
It supports finalizers, deals with multiple threads, etc. =A0It is used pre=
tty much like the one in C#.</div>
<div style><br></div><div style>Honestly, after 12 years we just got tired =
of C++&#39;s issues (see this thread for a good example), and so far love h=
ow clean it is to write the new code. =A0When we need to write some C/C++ c=
ode it&#39;s as easy as:</div>
<div style><br></div><div style>void Foo()</div><div style>{&gt;</div><div =
style>=A0 =A0// c++ code goes here.</div><div style>&lt;}</div><div style><=
br></div><div style>It may sound like a pain to get working, but if you loo=
k at some of runtime-recompile work, and then realize that most of the anno=
ying parts of that can also be hidden behind a &#39;pre-compiler&#39;, it i=
sn&#39;t as bad as it sounds. =A0Especially when you know the data layout o=
f your own vtables and can run through all allocations fixing up pointers, =
etc.</div>
<div style>=A0<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0=
 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
To add to the discussion about benefits of reflection:<br>
<br>
Coming from Ruby I&#39;m always looking for ways to make things easier to<b=
r>
express using reflection. I think serialization/deserialization is<br>
just one usecase for this. For example C# is a language that&#39;s more<br>
geared towards object oriented architecture than to entity systems,<br>
but using reflection you can generate the code that links your<br>
components together at runtime so there&#39;s not a lot of boilerplate<br>
code required for every component.<br></blockquote><div>=A0</div><div style=
>Yup.</div><div style><br></div><blockquote class=3D"gmail_quote" style=3D"=
margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Sort of related to reflection, recently I made a game as an academic<br>
exercise in javascript using an aspect oriented programming library.<br>
AOP has a similar philosophy of taking separation of concerns to the<br>
next level. It worked out very well, you can have the game engine<br>
drive the views without having any hooks or view related code in the<br>
engine. Granted ofcourse this was a javascript exercise, not at all as<br>
resource constrained as a big console game.<br></blockquote><div><br></div>=
<div style>Sounds cool. Do you have some specific examples?=A0</div><div st=
yle><br></div><div style>-Doug</div></div></div></div>

--e89a8ffbae5b9a112604d84da02a--

--===============0619998535==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Sweng-Gamedev mailing list
[email protected]
http://lists.midnightryder.com/listinfo.cgi/sweng-gamedev-midnightryder.com

--===============0619998535==--