This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 24 - Pages: 2 [ Previous | 1 2 ] - Last Post: 4 May 22, 13:28 Last Post By: JeffTucker Threads: [ Previous | Next ]
RobM

Posts: 4,171
Registered: 4-Aug-2006
Re: Bug, or just changed behavior?
Posted: 29 Apr 22, 16:26   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
JeffTucker wrote:
Let us know when you come up for air.
Gulp, https://jalbum.net/api/se/datadosen/jalbum/JAlbumContext.html#getConsoleInstance()
Return a context that isn't bound to any user interface

Maybe
context.getExplorer().getConsoleInstance().getRootFolder();

Well, it looks good but no idea if it works or makes a difference.
JeffTucker

Posts: 8,148
Registered: 31-Jan-2006
Re: Bug, or just changed behavior?
Posted: 29 Apr 22, 16:30   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
Worse. Blows up even when you are running from the regular app!
RobM

Posts: 4,171
Registered: 4-Aug-2006
Re: Bug, or just changed behavior?
Posted: 29 Apr 22, 16:46   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
JeffTucker wrote:
Worse. Blows up even when you are running from the regular app!
It was a long shot, a very long shot.

Edited by: RobM on 29 Apr 2022, 15:47
Maybe it should have been context, console context explorer rootFolder
JeffTucker

Posts: 8,148
Registered: 31-Jan-2006
Re: Bug, or just changed behavior?
Posted: 29 Apr 22, 16:53   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
All far too byzantine. What's really needed is:
if(isGUI()) do it this way;
else do it the other way;
ETA: But there's a long, proud tradition of coders using error traps for this kind of stuff. It's the lazy man's if/else clause.
RobM

Posts: 4,171
Registered: 4-Aug-2006
Re: Bug, or just changed behavior?
Posted: 29 Apr 22, 17:01   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
JeffTucker wrote:
All far too byzantine. What's really needed is:
if(isGUI()) do it this way;
else do it the other way;
ETA: But there's a long, proud tradition of coders using error traps for this kind of stuff. It's the lazy man's if/else clause.
Fortunately no one has, I’m sure, run any of my tools using rootFolder or currentFolder from the command line, so that only leave a couple of skins to not worry about :)
ctwist

Posts: 710
Registered: 27-Sep-2003
Re: Bug, or just changed behavior?
Posted: 29 Apr 22, 18:11   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
In console mode, "context.getExplorer()" is null (unsurprisingly).

Workaround:
AlbumObject vRootFolder;
JAlbumExplorer jAlbumExplorer = context.getExplorer();
vRootFolder = (jAlbumExplorer == null ? rootFolder : jAlbumExplorer.getRootFolder());
JeffTucker

Posts: 8,148
Registered: 31-Jan-2006
Re: Bug, or just changed behavior?
Posted: 29 Apr 22, 19:04   in response to: ctwist in response to: ctwist
 
  Click to reply to this thread Reply
Ah, yes, of course.

But in the interests of conciseness, I prefer:
if(context.getExplorer() == null) checkObjects(rootFolder);
else checkObjects(context.getExplorer().getRootFolder());
No need for declarations or new variables.
ctwist

Posts: 710
Registered: 27-Sep-2003
Re: Bug, or just changed behavior?
Posted: 4 May 22, 06:10   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
JeffTucker wrote:
But in the interests of conciseness ......
My philosophy is to avoid calling a method twice with the same parameters, since this usually has a higher overhead than declaring an extra variable to hold the method's original result. Also, maintenance is slightly simpler, since there is one call to be maintained instead of two.

Of course in this situation (just one pair of calls), performance is not a concern, but in different circumstances it could be a consideration.
ctwist

Posts: 710
Registered: 27-Sep-2003
Re: Bug, or just changed behavior?
Posted: 4 May 22, 07:03   in response to: ctwist in response to: ctwist
 
  Click to reply to this thread Reply
Here is one more related problem that I fixed.

In onload.bsh, I instantiate the MgSkin class:
new MgSkin(engine);
This is visible to init.bsh.

While testing console mode in jAlbum 27, an exception occurred in init.bsh because a variable in MgSkin was null. This was all very reasonable, because onload.bsh had not been processed. I fixed it by adding
if (context.getExplorer() == null)
{ new MgSkin(engine);
}
to init.bsh.

However I did not see this problem in the previous version of Mirage in the previous version of jAlbum. I have made lots of changes, so I may have caused this.

However, my point is: "If you do some initialisation in onload.bsh, you may have to redo this in init.bsh if you are running in console mode."

I have usually ignored console mode, so maybe I am preaching to the choir.

Edited by: ctwist on 4 May 2022, 01:41
JeffTucker

Posts: 8,148
Registered: 31-Jan-2006
Re: Bug, or just changed behavior?
Posted: 4 May 22, 13:28   in response to: ctwist in response to: ctwist
 
  Click to reply to this thread Reply
ctwist wrote:
My philosophy is to avoid calling a method twice with the same parameters, since this usually has a higher overhead than declaring an extra variable to hold the method's original result.

Especially for the things in init.bsh, which are usually one-shots, I go for readability. The overhead difference is probably in the sub-millisecond range. When it comes to "parsing the whole AO tree," it might pay to think about overhead. But even then, unless you're making one of those "holy crap," tens of thousands of images albums, the difference is probably tough to detect.

I'm also inclined to fall back on the fact that BeanShell is much less fussy about declarations and data typing than real Java. If I'm not compiling, it's just easier. It does give rise to bad habits, of course. ;)
Legend
Forum admins
Helpful Answer
Correct Answer

Point your RSS reader here for a feed of the latest messages in all forums