Byref and ByVal part II

Long ago I wrote about byref & byval
Apparently this wasnt widely read not even by some long standing members of the community as I still see completely wrong explanations of bevel & byref persist.

First you have to understand that there are two types of VARIABLES.
VALUE types and REFERENCE types.
With a VALUE type the compiler sees there is space in memory set aside when your program runs to hold a value – a number a floating point value etc. The thing IN that spot IS the actual data.
With a REFERENCE type whats in that spot isnt the data directly – it s the address of the data.

Normally when you pass a value you pass it BYVAL
This is the default

So what exactly does this mean ?

I literally means that the value that is held by whatever type of variable is passed in can’t be altered.
If you pass in an integer, IN the method you can change it however you want, but those changes WILL NOT be preserved in the calling code.

Something like

Sub Opening
  dim I as integer = 100

  system.debuglog str(i) // prints 100

  foo(i)

  system.debuglog str(i) // prints 100
end sub

sub foo ( I as integer )
  I = 500
  system.debuglog "in foo " + str(i) // prints in foo 500
end sub

Would print 100 and 500 as indicated. The value would not be preserved from the call to foo. So when we return the next time I is printed in the caller it prints 100.

This is the easy case for a VALUE type.

If we switch to a REFERENCE type its EXACTLY THE SAME ! The trick is “the value” that is preserved is the pointer, or reference, that is preserved. NOT THE data referred to. Let me illustrate

Sub Opening
  Dim d As New date
  System.debuglog d.SQLDateTime
  foo(d)
  System.debuglog d.SQLDateTime

End Sub

sub foo ( d as date )
  
  d = New date(d.year - 2, d.month - 4, d.day - 6, _
    d.hour - 8, d.minute - 10)

  System.debuglog "in foo = " + d.SQLDateTime
end sub

Note that if you run this you will see that d in the main calling routine before & after the call prints the SAME date. This despite the fact that in the called routine, foo, we altered the date that d referred to.
What this shows is that what is being passed by VALUE is the REFERENCE (pointer or address)

And again IN the routine we called we can do whatever we want to change what the REFERENCE is by creating a new one and that change wont stick when we leave.

  • there IS a thing that many people referen to as “byref” that ISNT
    SEE THE END OF THIS ARTICLE

No wit we switch to using BYREF to make it so “changes to the value held” are preserved we get

Sub Opening
  dim I as integer = 100

  system.debuglog str(i) // prints 100

  foo(i)

  system.debuglog str(i) // prints 500 !!!!!!!!!!!!
end sub

sub foo ( byref I as integer )
  I = 500
  system.debuglog "in foo " + str(i) // prints in foo 500
end sub

The change to the value held IS preserved !
BYREF allows us to alter what the variable held

And for BYREF with a reference type its much the same

Sub Opening
  Dim d As New date
  System.debuglog d.SQLDateTime
  foo(d)
  System.debuglog d.SQLDateTime // prints THE SAME as from foo !!!!

End Sub

sub foo ( byref d as date )
  
  d = New date(d.year - 2, d.month - 4, d.day - 6, _
    d.hour - 8, d.minute - 10)

  System.debuglog "in foo = " + d.SQLDateTime
end sub

BYREF lets you change what the VALUE of the passed in variable is.
But, it depends on what kind of value is passed in to see what the effects are

SOME people incorrectly refer to the following as “byref”

Sub Opening
  Dim d As New date
  System.debuglog d.SQLDateTime
  foo(d)
  System.debuglog d.SQLDateTime // prints THE SAME as from foo !!!!

End Sub

sub foo ( d as date )
  
  d.hour = d.hour - 12

  System.debuglog "in foo = " + d.SQLDateTime
end sub

Bu this is NOT “byref”
We haven’t change the REFERENCE ( the actual instance) being referred to

We HAVE altered one of the properties of the item passed in – that happens to be a reference type

I hope this clears up the confusion

Silent code breaking changes :(

Was helping a fellow Xojo user to try & sort out why updating to a new version of Xojo broke their code.

The code still compiled fine. But it just didnt work as expected any longer.

And it turns out that in some classes Xojo changed a get/set pair of methods, which can be overloaded by a subclass, into actual computed properties, that cant be.

They had subclassed the Xojo class and overloaded the method pair to do some custom things. And now, since properties are NOT virtual, all their customizations no longer work.

The trouble with this change is that it IS a silent behavioural change.
And it has the effect I wrote about some time ago – Virtual dispatch for properties

Worst of all there appears to be NO release note or change notice that this was done in the 2022r3.2 release cycle.

Here’s a tiny example of the issue

For starters this is the entire code in a console apps RUN method

Dim c As Class1MethodPair

c = New CustomClass1MethodPair

// given our current set up where Storage is a METHOD this will return the SUBCLASS value 

System.debuglog c.Storage


Dim cp As Class1AsProp

cp = New CustomClass1AsProp

// and now ?????????

System.debuglog cp.Storage

The ONLY difference between these sets of classes is the first implements STORAGE as a get/set pair of methods, which the cubclass CAN properly overload.

And the second Storage is a computed property.

The results wont be what you expect by looking at the code !

The change xojo made is exactly the same, changes behaviour silently, and appears to be undocumented

Fixing code by not touching it follow up

In the case I described the code is in a subclass a Xojo class

The idea here is to INSERT a new subclass between the existing subclass and the new one. And the newly inserted subclass will expose things in a way the OLD existing code wont break

So we never touch the old code
We just modify the inheritance chain in a way we can then alter how things behave

So in his case we can add a new subclass of EmailMessage that exposes the Source as a Method pair ( get & set) and then make the existing class inherit from our new class

And the existing code will then JUST work without ever having had to alter any of it

Next time you have an issue like this consider that as an option !

YAY !!!!!!!!!!!!!

For the past 3 days I’ve been on a training course and today I got my certification as a CSIA level 1 instructor !!!!!

Fixing code by not touching it

The other day I was helping a friend with some code that worked fine in several versions of Xojo but then in a newer one wouldn’t compile

Seems he found a compiler regression Whether this _should_ have been caught by regression tests etc is an entirely different question.

It exists. And now his large project doesn’t compile.

The code this affects is old and has worked for many years.
And he’d rather NOT have to alter all of it to fix the issue.

Since the code in question is in a subclass he was not looking forward to making significant changes to it and having to retest all his changes

So how can he fix this compiler issue and NOT have to touch all the code that suddenly doesnt compile ?

There are several options

Of course he could “fix” the code in the class directly – not something he relished

Another option is to just NOT use a new version of Xojo that breaks things this way – not a great option if he wants to support Ventura & newer

There is at least 1 more that is fairly simple, testable, and does fix this without actually modifying the code in the original class 🙂

I’ll let you noodle on that until tomorrow.



Never had to think about this before

Was chatting with a potential client. And they are new to Xojo.

When I mentioned that I had worked at Xojo Inc for more than 10 years they didn’t believe me. And they asked for some proof. I had never encountered this before.
So here’s a quick few references where you can see that I was once a member of their development team.

Xojo XDC 2018 Ask the Engineers
Thats me on the far right

XDC 2016 Highlights
Geoff, the CEO, specifically names me (about 44 seconds in)
Later on thats me at far right

XDC 2018 Highlights Video

Later on thats me at far right

Posts like, and this one and this one saying “Norman fixed …”
Thats me

Announcements about the FIRST Xojo developer to go to Germany for the MBS Conference

And in the new bug tracking system issues under @normanpalardy1
Xojo gave me a new account when I departed and renamed my existing one, to normanpalardy1, so as a non-employee I no longer had access to the same cases I did as an employee (Makes sense to me)
(They have done the same with other former employees like Greg O’Lone)
Cases like this one

You’ll see this issue is marked as FIXED by normanpalardy1 – thats me
And there are lots more like that

And I’m sure if you ask in the forums that many users would reply that yes I worked there
An I expect Xojo’s staff would as well

JUST to archive the things I wrote while I worked there – a list of URLS

https://blog.xojo.com/2019/02/27/binary-magic-with-signed-integers/
https://blog.xojo.com/2019/02/12/how-code-one-liners-can-make-debugging-harder/
https://blog.xojo.com/2019/01/28/if-vs-if-and-conditional-compilation/
https://blog.xojo.com/2019/01/24/some-follow-up-regarding-byref/
https://blog.xojo.com/2019/01/23/byref-vs-reference-types/
https://blog.xojo.com/2018/12/12/what-kind-of-variable-are-you/
https://blog.xojo.com/2018/12/04/are-your-macos-apps-ready-for-64-bit/
https://blog.xojo.com/2018/06/03/which-dlls-can-i-move-and-where/
https://blog.xojo.com/2018/05/14/getting-the-mysql-server-version/
https://blog.xojo.com/2018/03/14/code-tip-be-careful-with-loops/
https://blog.xojo.com/2018/02/12/setting-constants/
https://blog.xojo.com/2018/01/25/supporting-multiple-cores/

Other links that show I was engaged byXojo
https://blog.xojo.com/2016/10/11/xdc-2016-recap/
alternate – https://web.archive.org/web/20161117055842/https://blog.xojo.com/2016/10/11/xdc-2016-recap/

https://blog.xojo.com/2015/03/11/xojotalk-009-its-my-dog/
alternate – https://web.archive.org/web/20230324163333/https://blog.xojo.com/2015/03/11/xojotalk-009-its-my-dog/

https://blog.xojo.com/2014/09/10/6-years-and-still-ticking/
alternate – https://web.archive.org/web/20201204173921/https://blog.xojo.com/2014/09/10/6-years-and-still-ticking/

XojoScript debugging

if you’ve EVER tried to debug a Xojo Script its truly a pain in the rear end

Since one of my current projects requires a lot of Xojo Script that became really apparent and really annoying

So, for this project, we made a XojoScript debugger 😛
You can run & single step. And with each step the values of all variables in scope will be reported; where possible. Since there’s no introspection in XojoScript I cant make it dump out the values of properties of classes or other reference types 🙁

But – here’s what it looks like so far 😛

INN

Over the last week I’ve been asked repeatedly about INN’s status
So I’ll post the same answer I’ve give n out several times

It seems to have been a series of bad luck & timing

Garry was in the process of transferring operation of INN to me
Just as  I was going on holidays

And apparently Digital Ocean had a node failure and thats where INN was housedAs far as I know Garry hasn’t investigated or invested any time to get it back up and running since he was moving away from being the admin anyway

And I’ve been on hotel wifi so couldn’t get anything done

The intent IS to get the domain transferred and the discourse instance back up and running as quickly as possible

UPDATE : I am HOPING that once the domain transfers that INN will be back up
That could be later this week after Nov 23
Fingers crossed !