improvements

27 views
Skip to first unread message

kobi2187

unread,
Mar 15, 2015, 12:28:45 PM3/15/15
to ooc-...@googlegroups.com
Hi, me again :-)

the following code fails:
  assert([1] == [1])

how should I fix that?
do I need to extend == for arrays? if so, where is that code.
Thanks alot

Amos Wenger

unread,
Mar 15, 2015, 12:36:33 PM3/15/15
to kobi2187, ooc-...@googlegroups.com
Unfortunately, arrays are kind of a sore spot in ooc right now.

You've got C pointers, e.g.

a: Int* = gc_malloc(10 * Int size)
a[0] = 42 // etc.

If you compare those, it does a pointer comparison

You've also got ArrayLists, e.g.:

a := ArrayList<Int> new()
a add(42)

But `==` is not overloaded on those in a generic way because nothing tells you that the content of the ArrayList is going to be comparable.

And then there's ooc arrays, which are kind of a weird beast, implemented in C with a struct (pointer + length), and they're an endless source of bugs and confusion for new users - and you can't really do anything useful with operator overloads there as well.

ooc arrays implementation (which you use in your code sample) is contained mostly in this file: https://github.com/fasterthanlime/rock/blob/master/sdk/lang/Array.h and the rest is internal compiler logic.

It's a bit weird when coming from languages like Python/Ruby that you're not able to just compare arrays by value, and that they're not that much of a strong built-in in ooc, and that's a shame, but that's the current state of things.

In practice, I mostly use ArrayList<T> whenever I'm not too worried about size/performance, and otherwise I go with either C pointers or ooc arrays, while remaining well aware of their limitations (ie. probably better wrapped in a class or a cover, with some utility methods for comparison and all the things you'd need to do with them).

Cheers,
- A

--
You received this message because you are subscribed to the Google Groups "ooc-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ooc-lang+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages