No no no no no fuck NO!

from

Arrays are NOT passed by REFERENCE

They ARE a reference type which is entirely different

To illustrate

To show its pass by value

Sub FOO( anarray() as integer )

dim anotherarray() as integer = Array(1,2,3)

anarray = anotherarray

system.debuglog anarray.count.ToString


end sub

// and call it

dim original() as integer = array(8)

system.debuglog original.count.ToString

foo(original)

system.debuglog original.count.ToString


Now for the BYREF version where we pass a REFERENCE TYPE BYREF

Sub FOO( byref anarray() as integer )

dim anotherarray() as integer = Array(1,2,3)

anarray = anotherarray

system.debuglog anarray.count.ToString


end sub

// and call it

dim original() as integer = array(8)

system.debuglog original.count.ToString

foo(original)

system.debuglog original.count.ToString


The first gives

1

3

1

The second ?
1

3

3

The entire thread is full of half truths and misinformation about Arrays & how Xojo uses LLVM

And no one on the Xojo team is willing, or able, to step in & correct the incorrect items

Sad

4 Likes

The documentation of other languages (i.e. Swift, #, Java) clearly identify their data types as by value or by reference. Xojo’s documentation is lacking.

2 Likes

If ever you needed an example of ‘Where the ^^$$%$ did ChatGPT come up with that explanation’
It trawls every opinion from everywhere and validates none of it.

Surprised it doesn’t agree that the earth is flat

3 Likes

The misunderstandings continue on this thread

Some are simply because people do not understand the difference between value & reference types

Like this

One is a value type (strings)
The other is a reference type

1 Like

Xojo lacks many features modern languages offer. The ambiguities in Xojo’s syntax and the gaping holes in its documentation are a hellish challenge for the once-coveted citizen developer.

1 Like

In Xojo, all Objects (including Arrays) are passed by Reference.

NO

a REFERENCE type is one where the value is not held in the memory location directly

In C it would be a pointer to the value

A VALUE type is one where the actual value IS, usually, held IN the memory location directly

Xojo does a lousy job of educating people about the difference between these two

An INTEGER variable, when compiled, is assigned a memory location
When a value is assigned to that variable the VALUE is stored at that location
This is a VALUE TYPE

An ARRAY variable, when compiled, is a POINTER to a location where the actual data is stored

When you actually resize or start adding values to this the POINTER is accessed, and the actual location of the data determined and the new values added to the chunk of memory that holds all the data
The same is true for OBJECTS
These are REFERENCE types

And this has NOTHING to do with PASS BY VALUE or PASS BY REFERENCE

Pass by value means that whatever the original value is of the thing being passed WILL be preserved

Essentially a COPY of the item is passed

IF what you pass BY VALUE is a VALUE type then any changes in the subroutine will not affect the original VALUE
If what you pass BY VALUE is a REFERENCE TYPE then any changes to the REFERENCE will not persists - see my example previously where I pass the array, change what array it refers to and that the original array is still there when the routine ends - the ORIGINAL REFERENCE is not altered

NOTE that for a reference type you CAN alter the thing the reference refers to
You CAN add items to an array, or remove them
You can alter and instances member properties
But you have not altered the reference

IF what you pass BY REFERENCE is a VALUE type then any changes in the subroutine WILL affect the original VALUE
If what you pass BY REFERENCE is a REFERENCE TYPE then any changes to the REFERENCE WILL persist - see my example previously where I pass the array, change what array it refers to and that the original array IS altered

That the term REFERENCE has two different meanings IS confusing

1 Like

Remember to breathe and repeat our grounding statement: :prohibited: :monkey_face: :prohibited: :circus_tent:

The misinformation will only come back to bite them in the future :slight_smile:

2 Likes

Just sad to see that

  1. so many thing PASS BY REFERENCE is the same as REFERENCE TYPE

its not

  1. that NO ONE from Xojo has even tried to clear that thread up

The last person out the door: don’t forget to turn out the lights.

2 Likes