DesktopWindow's Implicit Instance should be turned off by default

Look. You all are arguing about behavior that isn’t going to change.

I’ve believed for a very long time there should be no implicit instance because it leads to subtle errors and major confusion from users in some circumstances. I feel that’s always bad. However, Xojo feels that implicit instance is ‘a good thing’ so it’s staying.

My reasoning is this:
If you were to use a DateTime object and you did this:
Var d as DateTime
and then attempted to do anything with d you would get an immediate nil object exception. Since the beginning of DateTime you had to initialize it some way such as:
Var d As DateTime = DateTime.Now or
Var d As DateTime = new DateTime( anotherDate )

Why is window different? Why is it special? It’s still an object. And you can still new a window regardless of implicit instance. So why have this one thing be different than the rest of the ENTIRE framework? It’s only because Xojo wants it so and it’s been like that since I started 20+ years ago. It’s staying in.

In the past I argued about it, and someone said “A Window in Xojo is a different kind of animal…”, I guess that behind the scenes there are more things than we should expect about “this special kind of” object.

I guess this differentiation comes from some decision from the past, and maybe it is unique to Xojo.

But this would solve all users preferences:

Here is the link to the documentation:
https://documentation.xojo.com/topics/advanced_features/setting_default_values_for_xojo_framework_class_properties.html#setting-default-values-for-xojo-framework-class-properties

From docs:

Create a file named <ClassName>.defaults in either <SharedDocuments>/Xojo/Overrides or <Documents>/Xojo/Overrides

In case of having both, what’s the precedence? This info should be there.

One would hope the User folder would override the All users option.

2 Likes

But Xojo does not think it‘s a good thing, from their documenation:

To avoid these limitations, you can disable implicit window instances for a window by turning the Implicit Instance property to OFF in the Inspector for the window. As this behavior is preferred, Implicit Instance will default to OFF in a future version of Xojo.

https://documentation.xojo.com/topics/user_interface/desktop/windows.html

So there is hope?

3 Likes

We use implicit instance on all our windows to great effect. We actually find it to be very convenient.

I think there are 3 kinds of users, not just 2.

  • Beginner - don’t even think about implicit instance and enjoy being able to refer to their windows by name.
  • Intermediate - start to trip over implicit instance and need a little guidance from the community.
  • Advanced - understand the nuances of implicit instance and code accordingly.

Just another data point. I don’t think this is likely to change any time soon.

5 Likes

As I’ve said, I’m not trying to remove the option or change the way people that know what they’re doing work. Simply to help people in your lower two cases from shooting themselves in the foot.

The moment that accessing things by name becomes a massive problem is if you have a document editing application that allows more than one window. At that point access via name is going to fall appart as you could have two of almost any window open at once. Class name isn’t going to work at that point.

The really nice thing about Xojo is it is really really easy to extend your application to work with more than one window of the same type at a time, but you really are going to have a very hard time if you use Class names.

The behavior from some other RAD systems is implicit on, visible=false (hidden), and instead of close(), people are used to show() / hide() cycles as:

win.Show()  // Instantiation, visible
win.Hide()  // invisible
win.Show()  // visible
win.Hide()  // invisible

The problem some people have in Xojo is using as:

win.Show()  // instantiation
win.Close() // destruction
win.Show()  // instantiation
win.Close() // destruction

In other tools, this kind of property is determined by the chosen template when creating a new project.

Show() Hide() works perfectly well in Xojo.

The problem you have is that:

win.show() // will open a window and show it, but only if it isn't already open

@Ian_Kennedy

You’re fighting an un-winnable battle. Since very early on Xojo has wanted a brand new user to be able to start a project, press Run and have an application with a window appear with no coding required. The only way to do that is with implicit instances.

1 Like

I think it is already explained on this thread that the Default Window, even if the implicit instance is off, will appear when you Run.

Maybe you mean something else?

I think that he meant that this kind of thing will make newcomers confuse:

They aren’t used to it.

He didn’t write “add another window” or something to that effect. We don’t know what he really meant. I know about Window2.Show as I posted that screenshot in this thread before.

As a new user, I can download Xojo, create a Desktop project, add buttons and other controls to the window that Xojo is showing, hit Run and it will show the Window with the controls with 0 code added, even if implicit instance for the Window is off. As mentioned before here.

He said:

and you are saying:

How a new user is not used to do something if he is talking about ‘brand new’ user?

This is a Xojo inconsistency. Implicit Instance off for all except if it is the default window.

It was already discussed, including a potential new user showing what he is used to.

Not all new users are coming from VB. I don’t know if some, many or most, used VB before (at this point, I guess the ratio was bigger 5, 10 years ago).

Anyway, I’m asking Greg what he means and not what you think he means. Thanks.

2 Likes

Sorry, but it does work without implicit instance turned on. All that would be required is for the standard app initialisation code to include

// pseudocode
if DefaultWindow <> none then
    oWindow = New (DefaultWindow)
    oWindow.Show()
end if

// rather than
if DefaultWindow <> none then
    (DefaultWindow).Show()
end if

It does not require implicit instance to occur. It works for window that it is turned off for. Why would that change if the default was changed. You certainly know better than me what is hidden in the Framework at the present time, but there is certainly no reason it couldn’t be handled in an explicit way, still with zero code.

As Thomas has pointed out the Documentation states:

To avoid these limitations, you can disable implicit window instances for a window by turning the Implicit Instance property to OFF in the Inspector for the window. As this behavior is preferred, Implicit Instance will default to OFF in a future version of Xojo.
Windows — Xojo documentation

Which explicitly states that they wish to change it to OFF (their emphasis not mine) in a future version.

So I think you’ll find that the Window that is set as the default window automagically has its Implicit Instance property set back to true for the compiled app. You can test that by adding a button to the window and writing the code Window1.show. if it were not an implicit instance, you’d get a compile error.

So yes, you could turn off implicit instance and still get Window1 to work, but it would still be confusing for that same new user when Window2 and Window3 didn’t work the same way.

Just to be clear, when I worked there, I argued for this same change several times because in my opinion, it allows for lazy programming practices that require a huge refactor later. But if Xojo wants to be a learning platform forever, I’m afraid that Implicit Instance is here to stay.

Now, what Xojo could do would be to make it a preference for new projects which defaults to True. When the user reaches a point when they want it to be off by default, then it’s off, there’s no more automagic code being run and you’d need to finish the App.Open event with:

Dim w as new Window1
w.show

I could even imagine a Shared Method on each Window class that works like this:

Shared Function Show() 
    dim w as new Window1
    w.show
    Return w
End Function

Which (except for the return value) would be the exact same behavior. A possible problem would be that the compiler might not be able to figure out which one to call from within the class if it needed to.

1 Like