Message Boards Message Boards

Objects: object-oriented programming (OOP) in Wolfram Language

Posted 1 year ago

enter image description here

Attachments:
POSTED BY: Kirill Belov
6 Replies
Posted 3 months ago

Thank you so much for the appreciation of my labors! I have read the article you recommended. A lot of things are done there that I would have done myself. Initially I made a very cumbersome code for Objects, where there were a lot of checks. Plus I redefined a lot of things. For example, I also overridden the Dot function, and I also made it so that using SyntaxInformaton, information for autocompletion is added to objects on the fly. But it turned out to be complicated and slow. In the end, I removed all the unnecessary stuff to avoid scaring Mathematica users with things that don't fit the syntax of the language, and tried to keep the objects as simple as possible - they're essentially typed variable associations. It's also like the OOP format from JavaScript. But it's more important than anything else. Our mini-team (me and Kirill Vasin) started to actively use the Objects package in our work and we encountered performance problems. A lot of conditions and checks slow down atomic operations like getting and changing the value of an object field. As a result, now we managed to achieve something more or less useful from the design point of view and almost as productive as built-in lists or associations.

POSTED BY: Kirill Belov

Kirill, thx for posting this and for such detailed descriptions.

Not to detract from your own approach, and it's probably too late for your own work now you have your own recipe for objects, but if you aren't familiar with it already, you might find it interesting to at least see what MTools does: MTools, Object Oriented Programming in Mathematica by Faysal Aberkane

If anyone else lands here, please note I'm not advocating for use of MTools over Kirill's Objects.

POSTED BY: Darren Kelly

As someone who has been working for some time with MTools (and my own Webel Abstract Data Type recipe adapted from a technique by Roman Maeder to include inheritance), I'm a bit surprised to learn about this interesting work, I wish I had known about it much earlier (and before making some recent slides about my own work in the area). I see it also uses the TagSetDelayed approach for "methods" I originally found demonstrated by Maeder.

I landed here BTW completely by chance trying to find out about CreateType after seeing it on this WLJS quick start page: Creating a new type, which has a StateMachine example that demonstrates used of state. Because I was already using MTools (which supports state), for my own variant of the TagSetDelayed ADT recipe I decided to make them pure stateless, that is, I have some projects using MTools that permit use of state, and other separate projects that force me to work with a stateless mindset.

I seem to have re-invented or co-invented some things Kirill has also covered (and in some cases more elegantly), but it's a bit late for me to re-jig some of my applications to include Kirill's approach (at least for now).

Kirill, this is super stuff, thanks for posting.

POSTED BY: Darren Kelly
Posted 5 months ago

Is there a way to have destructor methods implemented? I tend to re-run my notebooks frequently, and I'm worried about memory leaking. ClearAll["Global*"]; doesn't seem sufficient.

POSTED BY: Updating Name

This is amazingly useful stuff, and should be more widely known. Thank you for having implemented this!

POSTED BY: Zsombor Méder

enter image description here -- you have earned Featured Contributor Badge enter image description here Your exceptional post has been selected for our editorial column Staff Picks http://wolfr.am/StaffPicks and Your Profile is now distinguished by a Featured Contributor Badge and is displayed on the Featured Contributor Board. Thank you!

POSTED BY: EDITORIAL BOARD
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract