Data Models
Posted: Wed Mar 11, 2015 9:19 pm
I have some basic questions for the experts here.
How do you handle data models? In traditional programming you have structs and objects; with functional programming you have lists and a vast array of functions to perform on those lists; Livecode has an associative array and custom properties of an object. How do people do things like stacks, queues, linked lists? How about sets or trees?
I also wonder how most people represent objects-- does everyone really create a button and start setting its properties every time they need a new object X?
For instance, my app will involve the concept of a user and a bunch of data associated with that user. It will communicate with a server and get several user's and their data. An associative array seems less than ideal for many use cases, such as organizing my users into groups. Lots of my app code will operate on the data model itself, which has nothing at all in common with buttons, which are the default objects, if you will. So how do you create a new User, assign it some data, maybe pointers to another object (that user belongs to a team and has XXXX permissions to access stuff, each of which can be changed), etc. You can, I know, create a massive "everything lives inside this one User button" but that totally is not DRY (don't repeat yourself). Plus it means updating a ton of things when all I want to do is make the User do something differently. And how can I have a collection of Users; as far as I can tell you can't really stick a bunch of buttons into a LiveCode array.
And that brings up my next basic question: how does LiveCode handle the composition scenario? Behaviors satisfy the is-a test (this car is a vehicle) but how do people satisfy the has-a test (this car has an engine)? The only thing resembling a pointer is the long id, which as I understand it is rather fragile and varies between stacks and running of the program, so you cannot really save an object relational graph.
Is the only solution to drop down into a SQL db of some sort and let it keep track of the relations between objects?
How do you handle data models? In traditional programming you have structs and objects; with functional programming you have lists and a vast array of functions to perform on those lists; Livecode has an associative array and custom properties of an object. How do people do things like stacks, queues, linked lists? How about sets or trees?
I also wonder how most people represent objects-- does everyone really create a button and start setting its properties every time they need a new object X?
For instance, my app will involve the concept of a user and a bunch of data associated with that user. It will communicate with a server and get several user's and their data. An associative array seems less than ideal for many use cases, such as organizing my users into groups. Lots of my app code will operate on the data model itself, which has nothing at all in common with buttons, which are the default objects, if you will. So how do you create a new User, assign it some data, maybe pointers to another object (that user belongs to a team and has XXXX permissions to access stuff, each of which can be changed), etc. You can, I know, create a massive "everything lives inside this one User button" but that totally is not DRY (don't repeat yourself). Plus it means updating a ton of things when all I want to do is make the User do something differently. And how can I have a collection of Users; as far as I can tell you can't really stick a bunch of buttons into a LiveCode array.
And that brings up my next basic question: how does LiveCode handle the composition scenario? Behaviors satisfy the is-a test (this car is a vehicle) but how do people satisfy the has-a test (this car has an engine)? The only thing resembling a pointer is the long id, which as I understand it is rather fragile and varies between stacks and running of the program, so you cannot really save an object relational graph.
Is the only solution to drop down into a SQL db of some sort and let it keep track of the relations between objects?