Real Classes and Auto-Properties (like .net)

kanaida

Active Member
Licensed User
Longtime User
Public Class Person
Public Property Name as string
Public Property Address as new address
End Class


Public Class Address
Public Property Addr1 as string
Public Property Addr2 as string
Public Property City as string
Public Property Zip as string
End Class

So we can do things like:

For each p in Persons
Msgbox(p.Name & p.Address.City)
Next

It often feels like i'm blindfolded when I'm programming sometimes because certain vb basic elements aren't existent, I'd say that's the biggest hurdle. Especially coming from VS2010 and using .net 4.0 with LINQ mostly.

Also declaring thins like so tends to make code longer:
Dim a as string
a = "2323"

When you can do: Dim a as string = "asds"
 

francoisg

Active Member
Licensed User
Longtime User
Things that we need in B4A

Actually, the example given is quite simplistic - no methods, no inheritance etc.

If the B4A basic dialect can support true objects at some stage it would make a HUGE difference. After all the language you translate to (Java) does support objects??? So, the compiler can handle it without any issues!

Currently we need to jump through all kinds of hoops to get things done - especially if you are used to working with a proper OOP language!

Don't get me wrong - as a language it is MUCH better (easier) than Java if you ask me but there are a LOT of things that we are missing from the lanuage
- Compiler directives
- Proper objects with inheritance etc
- A way to create B4A libraries directly in the IDE
- Local (private) variables in code modules (maybe already possible?)
.
.
.

Keep up the good work!!!
 

agraham

Expert
Licensed User
Longtime User
A way to create B4A libraries directly in the IDE
I don't see why this is needed. If the code can be expressed in Basic4android then a code module is the equivalent of a library and the performance is only very slightly worse than Java. Libraries are generally needed to add functionality not available in the Basic4android language and hence need to be written in Java which is not a facility to include in the IDE I would think.

Local (private) variables in code modules (maybe already possible?)
Already possible. Process_Globals - visible across modules, Globals - visible within modules, Local variables - visible only with the declaring Sub.
 

corwin42

Expert
Licensed User
Longtime User
Already possible. Process_Globals - visible across modules, Globals - visible within modules, Local variables - visible only with the declaring Sub.

If I'm correct the "Globals" Sub is only available in Activity Modules. Not in code or service modules. Would be nice to have it in the other module types, too.
 

francoisg

Active Member
Licensed User
Longtime User
A few more ...

Hi,
I agree that libraries are mostly to add unavailable functionality - another possible use would be to give users a way to share code without giving away the source code + being able to create libraries using 1 file (not 50 code mudules + services etc)?

For instance I used the HTTP library to write a generic xml web service wrapper (web services created using microsoft .net for instance).

The code currently works great but I don't want to give users (or my other developers) 1 code module + 1 service module with instructions of all the libs that need to be included before they can use my code!

Being able to wrap it all into 1 lib would be perfect! If we could then create objects and expose them for use inside a lib ... say no more ;-)

Anyway,
another few things I would like to see in the IDE:
- A way of deploying code to the device without running it
- A way of compiling / testing the code without deploying it (to see if a change compiles for instance)
- A checkbox (any other way ... settings maybe?) for closing the compile dialog after it has deployed the app to the device

Again,
thank you for a great product. With a few updates this can be a real game changer for Android!!!
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
- A way of compiling / testing the code without deploying it (to see if a change compiles for instance)
- A checkbox (any other way ... settings maybe?) for closing the compile dialog after it has deployed the app to the device
1. You can use Alt + 2 (compile without signing) to compile the code without deploying it.
2. You can use Alt + 3 (compile in the background) to compile without showing any dialog.
 

kanaida

Active Member
Licensed User
Longtime User
I kind of oversimplified my example.

Right now after working with types, I've realized to vb.net they are "Structures" that can only hold values or types

They cannot however do this:

B4X:
  Private _UserSecurity As Credential
    Public Property UserSecurity As Credential
        Get
            Return _UserSecurity
        End Get
        Set(value As Credential)
            _UserSecurity = value
            'Do something else here in code, like update  a database.
        End Set
    End Property

On otherwords, we can't make Functions or Methods from scratch attached to the Type itself like the built in classes.

Example:
B4X:
MyType.GetAllOrdersStartingWith("0123")

Or

MyType.Orders = ListOfOrders
and have it save it to SQLite in one shot, as well as setting that property simultaniously.

In the B4A world they are "libraries", the missing part is creating new libraries purely in B4A, using only things available in B4A.
It's a little strange to me still, seeing as how a class is pretty much an "Activity" if it was a type instead.

Maybe that's the solution.
In an Activity we can create, methods, functions, variables, public properties, but we can't declare it as a standalone object wherever we want.
A code module would be perfect if we could say Dim x as new MyCodeModule, treating it like a class in a library.

Our end code could look like so:

B4X:
Dim p as new person   'This auto initializes all properties
p.Name = "Tom"         'We set a value
p.Save()                   'We call .save wich stores it locally to SQLite for example, or anything else

dim s as Person = p.GetSupervison()       'Can possibly return a newly loaded person from SQlite
p.Punish()                 'Could figure out who it's child people are, and set .Punished = True for himself and others in one shot.
 
Last edited:

kanaida

Active Member
Licensed User
Longtime User
Thanks Erel for your help overall, I'm not trying to turn the world upside down :sign0144: . Just putting stuff in the suggestion box. I've been very impressed by all the things I've actually been able to figure out in a few days since I purchased it.
 

francoisg

Active Member
Licensed User
Longtime User
My sentiments exactly - in the end we all want a development tool that does everything that we want! Not always possible but it won't hurt to ask ;-)
 

francoisg

Active Member
Licensed User
Longtime User
How about maybe considering adding attributes (like in .net) to your basic dialect - can then give us the ability to for instance make certain variables / functions (subs) private to a code module etc ...

For instance

[Private]
sub MyPrivateSub
' *** do something here ...
end sub

' *** By default subs should be public ...
sub MyPublicSub
' *** Call private sub ...
MyPrivateSub ...
end sub
 

kanaida

Active Member
Licensed User
Longtime User
It's not exactly the same, but "code" modules are like doing the following:

Public Module MyModule

'All variables in Sub_Global are:
Private xxx as xxx

'All your methods/subs declared public only.
Public Sub DoSomething()
End Sub

End Module
 

alwaysbusy

Expert
Licensed User
Longtime User
I agree on the class part. A lot of times I want to write an object with properties and functions and I keep turning to java to write the object as a library and then use it in b4a. For the moment, b4a is very nice if the project is rather small, but once the program becomes more 'mature', it needs classes. And I rather don't use java to accomplish this...

I'm sure in time this will all be possible in b4a. After all, it is already a great programming language and I saved a lot of time writing apps for my clients!
 
Top