From: Henning T. <le...@he...> - 2006-11-16 17:05:18
|
On Wed, 15 Nov 2006 swi...@li... wrote: > Message: 1 > Date: Wed, 15 Nov 2006 08:44:50 -0600 > From: David Beazley <dav...@da...> > Subject: Re: [Swig-user] Announce - SWIG-1.3.30 > To: Nitro <ni...@dr...> > Cc: "swi...@li..." > <swi...@li...> > Message-ID: <163...@da...> > Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed > > > Hypothetical question. What if SWIG were completely rewritten in > Python? (or some other widely available modern language not called C > or C++). Discuss. I was always annoyed by SWIGs way of incorporating the disadvantages of C (bad memory management, bad syntax, dynamic type unsafety) and Python (static type unsafety, achieved in SWIG by the DOH library mentioned later in the thread by David Beazley). I was also disappointed by the possibility to traverse the whole syntax tree from each node of the tree. This was considered an advantage by David, but it raises the problem, that every method in principle depends on all the data in the tree. Changes to a particular leaf interfer with transformations of all other leafs in an unpredictable way. I was also confused by the use of methods of the super-classes, because they called other methods of my sub-classes and made it really difficult to control, which parts of SWIG core shall be run and which not. I vote strongly for a re-write, better a successive replacement of modules, as mentioned later in the thread. But - I abandoned Python after some of my projects were grown too much. Due to Pythons dynamically typed nature it is no fun to safely change central data structures. Actually I ported one of my still relevant Python projects to Haskell. I know of several other people who have moved from Haskell to Python. Although Haskell is a functional language and Python is not, people are often attracted by the functional elements of Python, such as 'map', 'filter', list construction syntax. Haskell is the original! More advantages of Haskell: * It is statically type safe. * Type variables allow for much simpler implementation of re-usable code than any template mechanism in other languages. * Garbage collection (of course) * Haskell is lazy. This means for instance, that if the data dependencies allows it, the output is generated as the input arrives. I guess, that the size of header files is not big enough, in order to consider this an advantage. But it counts for modularization: You can implement syntax tree transformations separately. If you put them together, then Haskell won't execute them transformation by transformation, but it will process all transformations simultaneously as the output requires it. > Just to get this going, I will say that I've been thinking about this > in the abstract---especially since I now have all of the tools needed > to do it including a LALR(1) parser generator that can handle the > SWIG grammar (http://www.dabeaz.com/ply). Of course, it might also > just be insane. That never stopped me before however. not to forget * Parsers can be written directly in Haskell very conveniently. |