Hey John! Glad to see you're still digging into details.

C_OBJECT is great, I use it all the time. It's always nice to have more
choices in 4D. (You know more languages than most people, so you
doubtlessly were already missing something like C_OBJECT.) I posted speed
numbers a few days ago with some code that anyone can test for themselves
and how I interpret them. For me, I'll use C_OBJECT when it's easier and
sorted arrays when they're easier. The speed difference between access into
sorted arrays and C_OBJECT is trivial to the point of irrelevance. (Arrays
are quicker to set up, C_OBJECT may be a tiny bit faster for lookups. But
both of those things "depend".)

I like the example you provided and agree it's a perfect case for C_OBJECT.
Web input management is a problem that cries out for a simple lookup
structure. One nice thing about C_OBJECT over sorted arrays is that you
don't have to worry about sort order. One nice thing about arrays is that
the access syntax is better than some of the available C_OBJECT access
options.

As an example of when I find arrays easier, I've got one. Well, I've got
lots, but I've got an interesting one. I like to keep an error stack. This
way I can run a bunch of lines of code to validate inputs, etc. as a block
and then check the number of errors after the block. No errors? Carry on!
1+ error(s), deal with it. Sometimes I want to dump everything, most of the
time all I want is a count or to get the most recent error details. Now
this has nothing to do with arrays and associative arrays per se, but in 4D
arrays inside of objects are a bit of a pain. If I want to count the number
of items I either need to stash a counter in the object and pull it out, or
pull the whole array out and get it's size. If I want the last item, I have
to pull the whole array out and get the item out of the array. So I keep
the data in an array to make counts and item access simple. But what about
a full dump of the whole stack? It's nice to have it all in one object, so
I embed the array into an object. (It's an array of objects, as it turns
out.) I've got some methods around all of this data so the rest of the
world doesn't have to deal with the issues.

So, given the current state of play, I'm using C_OBJECT, ARRAY OBJECT, and
sorted arrays. I'm not using object fields and don't think that I've got
any cases for them in 4D. If I really need to store JSON closer to an
external application, I can pipe it over to Postgres in a 'text' field,
which compresses nicely. (Postgres 'json' and 'jsonb' fields don't sound
like they compress well at all. That makes sense to me for jsonb but not
for json. But what do I know?)
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**********************************************************************

Reply via email to