Wish optional argument and default values

AHilton

Active Member
Licensed User
Longtime User
Use a single map type for your subs' parameter, instead. Far more versatile.
 

AHilton

Active Member
Licensed User
Longtime User
That's why you use comments just above the "Sub" code line to document the parameters that shows up with Erel's 'intellisense' if it's really needed for new programmers.

The revolving team of developers we use both in-house and contract don't seem to have a problem with it. Those that know the code don't need the "document by parameter" approach and those that are new to the code (or have been away from it for awhile), know that there's far more (and better) documentation about those parameters just above the sub (and, of course, in the 'intellisense" popup).
 

MathiasM

Active Member
Licensed User
You're right, those documentation lines above a Sub are very nice.

Well, it's maybe a habit or something. One way or another, it feels 'wrong' for me to do that, because I wouldn't be able to understand those parameters without reading docs, while that is possible with parameters with good naming.

But hey, there is nothing wrong with different styles. And your way of working is indeed a way to get optional parameters.
 

Sandman

Expert
Licensed User
Longtime User
I suppose that implementing it is a problem
My best guess is that it's not a feature aligned with Erel's vision for B4X. I don't think I've ever read the vision anywhere, but from what I gather when I read between the lines, he's very focused on keeping B4X approachable for all users (which is a great focus).

And this obviously also include those that are quite new to programming, which means that more advanced concepts just aren't in scope for B4X. I don't have a link handy, but I vaguely remember a discussion about implementing support for i++ and i--, which was pretty much shot down. And I also doubt the wish of this thread is aligned with the vision.

And just to be super clear: This is all based on my amateurish interpretation of posts in the forum, don't take it any more serious than a mere guess.
 

LucaMs

Expert
Licensed User
Longtime User
Yes, not complicating things is a goal, but in this case there would be nothing complicated for any developer.
It is probably a technical complication (the implementation) or maybe a backward compatibility problem.

I have a feeling that we will know very soon
 

AnandGupta

Expert
Licensed User
Longtime User
Let put a scenario for the very concept of having default parameter value of a function.

I created a function/sub 'ABox' with parameters 'row, col, width, height and fill color'.
Now I used this sub in many places in my project with these parameters. So far so good.

Then I decided to have 'bordercolor' parameters. Changing the function/sub is no problem. But now I must change all the used places for this new parameter.
If I can make a default value for boardercolor, it will not break my code.

I do not know if I can do this in B4A using some code trick, but will be happy to get a code to set default value for missing parameter.

Regards,

Anand
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I do not know if I can do this in B4A using some code trick
Not really a trick but the way to do it is by adding another sub with the additional parameter:
B4X:
Public Sub DrawText(Text As String)
 DrawColoredText(Text, Colors.Black)
End Sub

'or make it DrawText2
Public Sub DrawColoredText(Text As String, Color As Int)
 ...
End Sub

There are advantages for writing it like this and in the long run it is probably easier to maintain than maintaining code with multiple optional arguments.

BTW, I don't have anything against this feature and it could be added at some point.
Generally speaking a programming language is not a bag of random features and the more features you add the less accessible the programming language becomes.
 

AnandGupta

Expert
Licensed User
Longtime User
BTW, I don't have anything against this feature and it could be added at some point.
Generally speaking a programming language is not a bag of random features and the more features you add the less accessible the programming language becomes.
Agree. Also agree that all programming languages has some difference from one another. Seeking similar features in all is wrong, but as a developer we are lazy and tend to like the feature which helps us in doing more work in less code, like 'i++'.

Nevertheless, B4A has more or less robust features and I can adapt myself as I develop in many different programming languages as per my need.

Regards,

Anand
 

LucaMs

Expert
Licensed User
Longtime User
I can agree only if the implementation of some features is very difficult.

I don't think having more features in your bag is a problem, some of you (us) won't use them.
Having a toolbox with 300 tools is better than having only 100.

Furthermore, some things, such as inheritance, for example, would give b4a a more professional "appearance".

My opinion remains that implementing certain things is very complicated, especially a posteriori (retrofitting?), otherwise I would strongly suggest doing so.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…