B4J Question What is the B4 equivalent of a Xojo Interface or a Swift Protocol?

Markus Winter

Member
Licensed User
What I am missing is a high-level introduction for people coming from other languages.

Even something like a simple table showing what is equivalent or can be used instead of would be helpful, eg

Swift - Xojo - B4
Var - Dim / Var - Dim
Let - Const - Const
Protocol - Interface - ???

Does this exist somewhere, and I'm just too blind to find it?

And what is the B4 equivalent to a Protocol / Interface? I was looking through the booklets but could not find whether B4 has something like Protocols or Interfaces.
 

aeric

Expert
Licensed User
Longtime User
The only comparison I ever seen is a Cheatsheet for VB6 programmers.

 
Upvote 0

Markus Winter

Member
Licensed User
Some programmers are very used to Object Oriented Programming (OOP) concepts
I wouldn't say I'm very used to all of them, but Interfaces / Protocols turned out to be one of the most useful. Basically every time you want different objects (from different classes) to do the same thing (like show them on a map. draw them on a canvas, save/load/… them in a database, etc) it scream for an interface.
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
To achieve this, I usually create a class with methods and properties common to the classes that have to use them.
Within the classes in question I create an instance of the common class. This way it can also make it act differently based on the calling class.

I don't know if I was able to explain myself in a simple way because I am in translation and sometimes the meaning is not always clear.
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
Hi Markus,

You may know me (Alain Bailleul, Alwaysbusy) from the Xojo and ifNotNil forums. We both had bad experiences with Xojo, their forum and their rigid management, so I understand your defensive reaction, believe me. However, let me say, none of this is applicable to B4X.

Unlike Xojo, we do not do name calling here. I know 'troll' is probably word of the year introduced by Xojo Inc. themself for a couple of years on their forum , but let me assure you, no one on this forum is, so there is no reason to start using it here. This kind of bad 'vibe' has given many (me and probably yourself included) experienced users the final push to leave Xojo and look out for something better.

@LucaMs is sometimes very direct and has (if I may say so, LucaMs) sometimes a weird kind of humor. Really, you both have those things in common . He is one of the oldest members here, and is most respected. In his unique way, he is pointing out that indeed such a list does not exist. Especially one with an exotic language like Xojo (which is probably unknown to 99.999% of programmers).

Unlike Xojo, which changes syntax appearance every few releases (sometimes they think they are Basic, the next one .NET and nowadays JavaScript 'dim -> var'), B4X is a language on its own, and its path is very clear and well though of (no breaking code for the sake of 'change' here). Erel had made some unique language introductions (the WaitFor construct! ) that makes it sometimes somewhat harder to compare directly with another language.

I do sometimes miss some things like Interfaces or Inheritance too, but the decisions Erel made are there for a reason. He does not want to be 'yet another copy' of some other language, and for novice programmers, those concepts may be way over their head and even make them hesitant to start using the language. B4X uses Composition, which does you to get used to if you've been using Inheritance in other languages. But it requires very little explanation and anyone new to programming can read it and understand it. As an experienced user, it is just a 'switch' you have to make in your head. I haven't come across anything I couldn't write with Composition.

You will see this forum is very helpful and there are no stupid questions. Unlike with Xojo, there is no beating around the bush here by its developer in a try to justify some decision. It is a programmers forum by programmers for programmers.

So let me end with welcoming you here! It is great to see some familiar faces from the old days and I hope you will bring your valued input with you ?

Alwaysbusy
 
Last edited:
Upvote 0

Markus Winter

Member
Licensed User
You may know me (Alain Bailleul, Alwaysbusy) from the Xojo and ifNotNil forums.
Sure do - it's your fault I'm pestering people here … ?

Thanks for the welcome. I'm still undecided if I go for B4 or jump straight to Java. B4 should be easier, but Java is more widespread and potentially more powerful (though I heard you can use Java and ObjC code in B4). My problem is that currently I have no feeling for where the strengths and limitations of B4 are - which is something you need to know when you make a decision.

So I'm going to ask a lot of stupid questions, and as I like teaching might write some tutorials or even a book aimed at beginners like me at some point - and I find comparisons between languages useful as each have their strengths and weaknesses, and the comparisons can teach you a LOT about the language that you might never realise otherwise (eg looking at Swift has changed my whole perspective regarding Xojo - the MapKit alone is as big as the whole of Xojo).

As I learn best when trying to solve a problem, I might just start with one of my many pet ideas and start digging into it.

P.S. Markus with a k - the German spelling
 
Last edited:
Upvote 0

Markus Winter

Member
Licensed User
I don't know if I was able to explain myself in a simple way because I am in translation and sometimes the meaning is not always clear.
For translations I highly recommend the free to personal use DeepL - MUCH better than Google Translate or Microsoft's Translator. The German / English translations are so good that I hardly ever have to correct anything.

You can use the website, download an app for your computer (mine lives in my menu bar) or mobile, or use a browser plug-in.
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
Upvote 0

Markus Winter

Member
Licensed User
Especially one with an exotic language like Xojo
P.S. In my opinion Xojo is going the wrong way, and if they don't fix their "we are introducing more bugs each release than we can fix" problem (and I don't see them doing that) then B4 will be the logical escape route (and it was the maturity and stability of the underlying Java that convinced me to give it a try).

But B4's has a big downside (in my opinion): its IDE. It is neither cross-platform nor as polished as it could be.

Given that the "big guns" (Microsoft, Google, even Apple) have started to seriously gun for the cross-platform market, this will not only be a problem for Xojo, but will also become a problem for B4 (and I get a sense of deja vu, like when I warned REALbasic that the Rapid Release Model is really not a good idea as it will turn REALbasic into a beta quality product over time).

Another threat is Python - if they ever get their shlt together and get a decent cross-platform visual IDE and compiler, they would seriously clean up (especially considering their position in artificial intelligence and machine learning … and they are REALLY big in Science, especially Biology).
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
straight to Java
I still write a lot of things in Java too. B4X is the fast and 'easy-to-use' glue. For example, for BANano, Inheritance in Java has saved me many hours to write the framework. It would've been perfectly possible to write it in B4X itself, but as of the size of the lib, I decided to write it in Java anyway. And now I can just make full use of this framework in B4X, which speeds up programming considerably compared with having to do it ALL in Java.

So, on one hand Java was faster to write the framework, but using it for our clients apps is a lot faster in B4X. The fact that B4X allows such 'hybrid' design makes it so powerful. I tried to follow the same 'hybrid' philosophy in the BANano framework and even allow inline JavaScript and CSS too.

Alwaysbusy
 
Upvote 0

Markus Winter

Member
Licensed User
How would that work with my CanDrawItself example with cHeader, cDepartment, and cEmployee classes? You can add an instance of the "common class" (let's call it CanDrawItself) to the cHeader, cDepartment, and cEmployee classes, but how do you make them act differently? As far as I understand you can only override a method in a subclass. Or does your "common class" method accept any object as a parameter, and you have a long select case statement on what to draw for each cHeader, cDepartment, and cEmployee class etc that might be passed in as parameter?

That might work - a lot less elegant and less encapsulated than interfaces, but a nice idea nonetheless. You might have to consider limits on the length of methods and split the code into sub-methods that you call (eg DrawIDcard, DrawList, Draw…) from the common method (I know that Xojo had a 32k character limit on methods, which I actually DID hit at times).
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
It is neither cross-platform nor as polished as it could be.
Being cross-platform would definitely be an asset and Erel has explained it has to do with some .NET components it uses. Hopefully one day this can be done and it may convince some Mac/Linux users to make the jump. I would however prefer it doesn't if that would mean we (on Windows) would loose functionality. The IDE may look a bit 'spartan' but if prefer it every day over the clickety-click IDE of Xojo (my poor wrists! ? ). I'm very used to the Eclipse IDE in Java so in my case it is seemingless to switch between them. I even changed the color schemes to be the same.

Microsoft, Google, even Apple
Those are indeed forces to be reckoned with, but (unlike Xojo) B4X has always been on top of things with the big boys. It being so light-weight, extremely stable and reliable I'm not worried at all: It will not go into the same spiral of doom like Xojo's REALBasic to Xojo transition. Your prediction with RB was spot on and I also was very glad we did the move for Xojo to B4X right before everything went into smithereens.
 
Last edited:
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
But B4's has a big downside (in my opinion): its IDE. It is neither cross-platform nor as polished as it could be.
You are looking for a cross platform development environment and you do not want to lose your existing program code. There are people who only program for Android smartphones in B4A. There is nothing wrong with that, but there lies the challenge to also keep those people "on board" while offering others who do have a need for it a cross platform development environment.

I think it's great that B4X offers that possibility to write and modify program code in the B4J IDE and that, after one time in B4A, I can see the insurmountable differences that exist between Windows and Android, without having to edit the code. Customize the program can test on an Android phone.

All this while the inveterate B4A only programmers can continue their developments unchanged in their IDE environment. Precisely because, like you, she finds it a pity that after years your program suddenly no longer works and while Google Android is constantly making adjustments. So a lot of balls are kept in the air at the same time and new function is added.

Started around 1978 with TRS-80 level I basic and Z80 machine language in the most spartan development environment with virtually no documentation, I am very comfortable with the IDE during my code development. Undoubtedly, what I don't know applies here, I won't miss it until it's added. I also regularly see that smart things are added without old solutions no longer working and can still be used.

The B4X environment is becoming more mature, but still allows the use of Java code to exchange information between B4X and Java and you can easily reuse your own pieces of code in other program solution(s). The only thing is that you have to think in advance where and how you put program code files. This gives the opportunity to work in a team and to add extra program options very quickly. I do recognize what I call a "tech-savvy" approach, it's all there, it functions fine, yes, but maybe it could have looked a bit slicker in the IDE.

As with any programming language, you must first read and learn a lot from the mistakes of and the solutions from another to realize its beauty. And most importanted there is a Bugs & wishlist where everyone can do their part to make the B4X environment even more beautiful.
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Or does your "common class" method accept any object as a parameter, and you have a long select case statement on what to draw for each cHeader, cDepartment, and cEmployee class etc that might be passed in as parameter?
This is my idea.

I also have another idea but less simple and less 'elegant' but working ... now I cannot describe it, I will do it in a later place as soon as I have more time available
 
Upvote 0

Markus Winter

Member
Licensed User
"common class" method accept any object as a parameter,
Actually, as the code is in the object anyway, it might be better to pass two enums, one of the type of class (eg enumObjectsThatCanDrawThemselves or enumDrawingObjects or enumPainters), another for what to draw. That would prevent invalid objects being passed in, but still confer the same information.

P.S. I'm known for my very long descriptive names - makes code MUCH more readable in my opinion (especially when others have to look at or use that code)
 
Last edited:
Upvote 0

Markus Winter

Member
Licensed User
As for the usefulness of the proposed list: nobody here could explain to me whether B4 has implemented the equivalent of interfaces in Xojo or protocols in Swift.

I got the answer on the IfNotNil forum instead.

A Xojo interface / Swift protocol is called Polymorphism in B4 - see https://www.b4x.com/guides/B4XBasicLanguage/?page=131



So a simple

Xojo
Swift
B4
Interface​
Protocol​

would have been enormously helpful (despite the differences in the capabilities of each implementation - it is a starting point for exploration).
 
Last edited:
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
Firstly welcome to the forum. Hopefully you'll stick around long enough to see all of the advantages of this great community of developers.

So I'm going to ask a lot of stupid questions,
Secondly there no such thing as a stupid question in this community, just another question.

Unlike other forums where I've seen more advanced/expert developers answer new members questions in a derogatory way which is uncalled for, there absolutely no reason to ask or give answers in such a way on this forum, just to be clear

@alwaysbusy has given you the best advice as well as @Erel and @Star-Dust.

The B4X ide is actually very simple to use and we'll designed for both novice and more advanced developers. The IDE works extremely well and if you're looking for a huge complicated IDE like from M$, Google, Apple or Eclipse create then you will not find that here. M$ cross platform solutions create overly sized bloated apps that takes longer to cold boot and can be sluggish at times because of their dependencies. Actually somewhere on this forum a developer created a a chart showing assembly, app size and apps cold boot time for a simple app comparing IDEs, the results are eye opening. The B4X IDE looks simple and extremely plain but the more you use it the more you will come to realise that it actually has some seriously advanced features built into it and it runs quickly, extremely smoothly with no issues whatsoever, even when using inline code.

In B4X it's possible to develop code in B4A (Android) that runs perfectly fine in B4i (iOS) by starting a new project using B4XPages and by using If #B4A/#B4i as long as you chose cross platform B4X libraries. I've developed an example Invoice mobile app for a client using B4XPages that only used B4X libraries, it works great as I developed the original code in B4A which also works In B4i. Admittedly I had to tweak the text and button colours in the B4i designer but basically very little extra coding was needed to get the B4i app working like the B4A app. Don't forget that B4XPages is basically a cross platform one code fits all solution from Anywhere Software.

You can even create cross platform games using XUI2D, search the forum for XUI2D and see the game example from Anywhere Software. B4X are a set of extremely capable RAD tools that can be used for creating basically anything except for 3D games, I personally use B4X RAD tools for creating apps for my clients.

Bug fixes, well bugs are extremely rare in the B4X IDE and when bugs are reported Anywhere Software fixes them extremely quickly. On the rare occasion if there is a bug it's most probably in a library and an updated internal library will be issued instantly and released to the community fixing any issues or bugs. B4X bugs are rare, even in beta releases (but that's what beta testing is for). If any bugs are found during beta testing by the community, Anywhere Software fixes them instantly before releasing the final updated B4X package, but bugs during beta testing is a rare accurance. Anywhere Software also listens extremely closely to us developers and takes into account any of our suggestions about improvements to the B4X RAD tools.

The one thing that you will learn is that Erel does not mess about, nor does he introduce new bugs to already working concepts, he improves concepts and the community beta tests them thoroughly before final release. Being a beta tester is optional.

If anything you will find that Googles own updates will break apps before Anywhere Software updates ever will.


Enjoy...
 
Upvote 0

Markus Winter

Member
Licensed User
@alwaysbusy has given you the best advice as well as @Erel and @Star-Dust.
Alain explained that B4 uses composition instead of interfaces, so that was certainly good advice (even though it is not completely correct as Interfaces are one elegant way of achieving composition, so they are not separate concepts).

Star-Dust's explanation also pointed to composition.

But Erel's answer to look at Sophisticated sorting with B4XComparatorSort has me puzzled as it has nothing to do with what I asked. Same happened with his answer to my other question in this thread, so I guess he is currently very distracted / stressed … which given the situation in the outside World would be very understandable.
 
Upvote 0

tchart

Well-Known Member
Licensed User
Longtime User
@Markus Winter welcome to B4X. Thanks for providing some context to your questions! I'm the one answering your questions about the JDK versions.

Firstly I dont know much about Xojo so I wont add anything to that conversation but Ive been around long enough to see other cross platform tools come and go (DragonFire, AppForge, Xamarin). The issue with many of those is that you are at the mercy of the developers/company to implement core functionality.

Ive been around the block with PalmOS, Pocket PC, WIndows Mobile etc but I started about 10 years ago with B4A and later shifted to B4J to focus on desktop and web apps. At the time I was frustrated with the Android tooling at the time so tried out B4A and was hooked. As many users (and reviews) mention you can literally create a working app in minutes compared to Eclipse or Android Studio. A great bonus along the way is that Im pretty proficient with Java now,

There have been many discussions on the forum here about the longevity of B4X. The main points for me are that the functionality of B4X is not tied to the IDE or some proprietary framework. As mentioned in the JDK post most innovation etc is via adding open source libraries etc (or updates to the Android SDK for B4A). Java isnt going anywhere as far as Im concerned.

The beauty with that is that even if B4X (the software, forum etc) disappeared you wont be left high and dry as you can still build apps, import libraries, write native code blocks, write/wrap your own Java libraries or "extend" the IDE with custom build actions or IDE links (to scripts) etc.

So the exposure/risk is pretty minimal in my opinion.

Lastly, even though I dont use B4I I bought the product and subscribe to the builder because B4X offers so much value that I cant not support Erel.
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…