Rooting around in the Forum: destructors

Mark Waddingham mark at livecode.com
Tue Jun 6 03:53:33 EDT 2017


On 2017-06-03 18:46, Richmond Mathewson via use-livecode wrote:
> Not having looked at any sort of "serious" programming language since
> about 1989 (I don't think that VB 6 is a serious language),
> I find it hard to understand what a destructor is beyond a way to free
> memory on a system that has constraints in that area.

Depends on your definition of 'serious'. I'd say that a language was 
'serious' if it allows to write full, complete programs. VB6 certainly 
did (after all, it had a huge installed user base for a very long time), 
as was HyperCard, as is LiveCode.

> 1. Does Livecode have something(s) that does the job of a destructor?

Yes.

> 2. If so, where is it and so on?

The 'delete*' messages are destructors for controls.

On a more general note this thread descended into a discussion of 
whether LiveCode is object-oriented or object-based:

   https://en.wikipedia.org/wiki/Object-oriented_programming

   https://en.wikipedia.org/wiki/Object-based_language

As I've said many times before, object-orientation is a methodology of 
programming. Any procedural language which has the equivalent of 
(mutable) structs can be used to program in that style relatively 
easily. Being 'object-oriented' doesn't mean the language can do any 
more than any other, just that it allows you to program in that style 
more easily - with compiler checking via explicit syntax for 
object-oriented formalisms).

LiveCode certainly has the equivalent of structs (assoc. arrays), and 
mutable parameter modes (@ before a parameter). Which means you can do 
object-oriented style programming - just as you can in C - indeed I do 
this a lot:

   command foobarCreate @xSelf
     -- init xSelf as an array with the state for foobar
   end foobarCreate

   command foobarDoSomething @xSelf
     -- use state in xSelf array to 'DoSomething'
   end foobarDoSomething

As to whether one calls a language object-oriented or not is largely 
down to 'what intrinsic features the language gives you to implement the 
object-oriented methodology'. In particular, an important feature there 
is to be able to define classes, with some form of inheritence and 
overriding of methods.

Now, since behaviors were introduced (and then chained behaviors), 
LiveCode has had something which is identical to the fundamental ideas 
of classes. A behavior script defines a class, the behavior chain allows 
inheritence, and the message path along that chain gives you inheritence 
and overriding. So, in that sense, LiveCode is definitely 
object-oriented.

However, one thing (all?) object oriented languages (in the classical 
sense) allow you to do is to define classes, create instances of those 
classes and store them in variables - LiveCode doesn't quite have this 
(LiveCode variables are either numbers/string or arrays), its 
object-orientation is centered around stacks, cards and controls. 
(Putting this on a slightly more abstract setting - LiveCode has 
object-orientation centered around a persistent object-tree, rather than 
transient object instances).

So LiveCode is definitely object-based, but perhaps not quite fully 
object-oriented in the classical sense - but it is certainly not that 
far off it.

Warmest Regards,

Mark.

-- 
Mark Waddingham ~ mark at livecode.com ~ http://www.livecode.com/
LiveCode: Everyone can create apps




More information about the use-livecode mailing list