How to add new features? (syntax, user API)

General discussion for topics related to the FreeBASIC project or its community.
Juergen Kuehlwein
Posts: 284
Joined: Mar 07, 2018 13:59
Location: Germany

How to add new features? (syntax, user API)

Post by Juergen Kuehlwein »

There have already been discussions about how new features should be added to the language.
I can see two positions:

1.) don´t add new keywords to the main namespace, put everything new into an include file into it´s own namespace in order not to enlarge and "pollute" the main namespace.
2.) add new keywords to the main namespace, because having to use the namespace prefix all the time, is laborious and makes the code look ugly.

- position 1 requires including the include file + "using <namespace>" (which will become complicated, if you need several additions having their own namespaces), or using the namespace as a prefix all the time
- position 2 means extending the main namespace in an unacceptable way in the long run.


Maybe i can offer a compromise, which requires adding only one (or very few) new keywords to the main namespace for a whole bunch of new (related) features.

For example the array features i wrote (could basically be applied to other features too):

Everything is inside an include file, so as long as this file isn´t included, nothing is added to the main namespace. By including it one main macro ("array") is added to main namespace. Everything else is in a namespace ("array_") or prefixed with "array_" or "ax_" + <very unusual name>. As a result what´s exposed to the user offers a nice and clear syntax without the need for "using <namespace>" or using the namespace prefix.

A typical use of it would be:

array(sort, <additional parameters>)
array(insert, <additional parameters>)
array(delete, <additional parameters>)
result = array(scan, <additional parameters>)

The first word after "array" specifies, what to do with an array. The list of words (sort, insert, delete, scan) could be expand at will. These words can be used everywhere else in code without conflict, it is even possible to use otherwise reserved words. Oviously the only thing you cannot have is a #define (or #macro) with one of these words, procedures, enums, variables, constants are not affected.

Code: Select all

namespace xyz
...
private function abc(...)
...
end namespace

#macro array(a, b, c...)
    xyz.##a(b, c...)
#endmacro


array(abc, arg1, arg2, ...)
Variations of this approach are possible, even nesting such macros for obtaining an even more flexible syntax, without "polluting" the main namespace.


An audio extension (Angros47´s sound features ?) could be implemented like this:
audio(control, ...)
audio(set, ...)
audio(play [, ...])
audio(midi, ...)
audio(sound, ...)
...

maybe some more like:
audio(stop)
audio(pause)
audio(record)

requires the word "audio" in the main namespace, all the rest is hidden in a namespace

And the same syntax could be re-used for a video extension (or any other future extension)

video(play [, ...])
video(stop)
video(pause)
video(record)
...


Summary: only one single new keyword in the main namespace ("array", activated by including the corresponding include file) allows for an expandable new feature set for arrays (or other new features), without the need for the explicit namespace syntax. Nevertheless all new functions, constants, etc. live in their own namespace.


JK
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: How to add new features? (syntax, user API)

Post by fxm »

I do not see any fundamental differences with a classic namespace usage:
array.sort(<parameters>)
array.insert(<parameters>)
array.delete(<parameters>)
result = array.scan(<parameters>)
.....

idem for
audio.xxx()
audio.yyy()
audio.zzz()
.....
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: How to add new features? (syntax, user API)

Post by MrSwiss »

I don't see the reason for this discussion, because coderJeff has made it pretty clear,
that he wants it, as in your option 1).

Btw: I'll support him on that, all the way ...
Juergen Kuehlwein
Posts: 284
Joined: Mar 07, 2018 13:59
Location: Germany

Re: How to add new features? (syntax, user API)

Post by Juergen Kuehlwein »

- "array.sort" looks too much like object syntax to me, not so much like (procedural) BASIC syntax. Maybe i´m a traditionalist.

- second reason is, that you cannot do with it, what i can do implementing macros. Please, have a closer look here (https://github.com/jklwn2/fbc/tree/Array)
marcov
Posts: 3455
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: How to add new features? (syntax, user API)

Post by marcov »

(3) as (1), but have some option to automatically add additional namespaces to the default namespace. Preferably in some order (e.g. to disallow or allow the added namespace to override keywords in main)

This is what usually is done. Typically USING, USES or IMPORT is use. (if IIRC resp C#/Pascal/Java and Modula2)
Juergen Kuehlwein
Posts: 284
Joined: Mar 07, 2018 13:59
Location: Germany

Re: How to add new features? (syntax, user API)

Post by Juergen Kuehlwein »

I do not see any fundamental differences with a classic namespace usage:
added to what i already posted above:

If i got it right, then the namespaces´ name is unavailable (blocked, reserved, consumed) for any other use in the same code. That´s the same as for a macro. But a macro offers a much more versatile syntax than a function does. So if we don´t loose anything, why not make use of it?
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: How to add new features? (syntax, user API)

Post by MrSwiss »

coderJeff wrote:FreeBASIC Namespace Project

Postby coderJeff » Oct 20, 2019 10:56
Imortis wrote:it was mentioned in the community thread, and I have seen it multiple times over the years on the forum. EVERYONE who is against adding new keywords/features to the compiler will eventually say it is because we already have too many keywords cluttering up the namespace and thus should not add any more.
Agreed.
marcov wrote:I think a first step would be to do what you can do to modularize the RTL and the default namespace, and then enable some implicit namespace for the existing language modes so that the result remains transparent to the user.
My thought as well. Key being that result is transparent to the user.
angros47 wrote:Are you suggesting, perhaps, to put the sound features under a specific namespace?
Yes.
Still need more evidence on how things should be done?
Juergen Kuehlwein
Posts: 284
Joined: Mar 07, 2018 13:59
Location: Germany

Re: How to add new features? (syntax, user API)

Post by Juergen Kuehlwein »

I´m asking two questions:
If i got it right, then the namespaces´ name is unavailable (blocked, reserved, consumed) for any other use in the same code. That´s the same as for a macro.
Is this true (i cannot have a procedure, a variable, a constant, an enum with the same name as a namespace used in my code)?
But a macro offers a much more versatile syntax than a function does. So if we don´t loose anything, why not make use of it?
If the first question must be answered with yes, why should i limit myself to a method with less possibilities, when i have a method with much more possibilities, which doesn´t cost more (in terms of word consumption)?
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: How to add new features? (syntax, user API)

Post by MrSwiss »

I'm asking another question entirely (previous questions are pointless, IMO):

@JK, can you implement any of your ideas, without adding a single new key word to 'global namespace' ?

The answer to my rethorical question (above) is definitely "NO".

Therefore, I consider your implementation methods "not acceptable".

-----

Acceptable: a mandatory #Include "blah.bi" and a namespace "blah".

This means:
no namespace name wasted, without the #Include "blah.bi" (problem of namespace name solved).

You want it all in 'global namespace' after the include?
using "blah" (eliminates namespace prefix use, another problem solved).

Within the namespace, you can add whatever you fancy, without cluttering up 'global namespace'.

Anything else? I don't think so.
Juergen Kuehlwein
Posts: 284
Joined: Mar 07, 2018 13:59
Location: Germany

Re: How to add new features? (syntax, user API)

Post by Juergen Kuehlwein »

@JK, can you implement any of your ideas, without adding a single new key word to 'global namespace' ?

The answer to my rethorical question (above) is definitely "NO".
The answer to your question is definitely "YES"


If you had made the effort of reading the opening post thoroughly and maybe followed the link in post #4 you should have realized that.
Therefore, I consider your post "not acceptable".


For the record (from my first post)
...Everything is inside an include file, so as long as this file isn´t included, nothing is added to the main namespace...
MrSwiss, you seem to be a very knowledgable person, why this "ich bin dafür, daß wir dagegen sind" (i favour beeing against it) attitude?


JK
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: How to add new features? (syntax, user API)

Post by fxm »

I think I understood from the beginning that your proposal is a file to include, containing a macro allowing to call different procedures in a namespace.
Juergen Kuehlwein
Posts: 284
Joined: Mar 07, 2018 13:59
Location: Germany

Re: How to add new features? (syntax, user API)

Post by Juergen Kuehlwein »

I think I understood from the beginning that your proposal is a file to include, containing a macro allowing to call different procedures in a namespace.
Yes!!!

@fxm,
you definitly weren´t the addressee of my previous post. I know you got it right from the beginning.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: How to add new features? (syntax, user API)

Post by MrSwiss »

@JK,
Juergen Kuehlwein wrote:... why this "ich bin dafür, daß wir dagegen sind" (i favour beeing against it) attitude?
you seem to be the one, that changes the mind with the wind ... in Audio library ... thread.
I'm considering whatever you said, wherever you stated it and build an average, in order to
gauge your real position on current issues. (I'm not fooled by a single post!)

Since, you seem to support adding NEW key words to 'global namespace', at times at least,
I don't really know, what your ultimate goals are. The reaction to that is of course:
"rather safe than sorry". (Don't allow a precedence case, to start with!)

Punch line: I'm only against, as previously clearly stated: ADDING new key words to 'global
namespace
'. Appart from that, you are free to do as you please ...
Juergen Kuehlwein
Posts: 284
Joined: Mar 07, 2018 13:59
Location: Germany

Re: How to add new features? (syntax, user API)

Post by Juergen Kuehlwein »

The reaction to that is of course: "rather safe than sorry". (Don't allow a precedence case, to start with!)
... with you as the Guardian of the ultimate truth!

To me it seems this is becomming more and more a matter of "religion", than of arguments and facts...

I accept your point of view, so please accept, that in general i would prefer having it some other way than you do. But this thread is about a compromise. I don´t know how to put my goal any better than in fxm´s last post.
I don't really know, what your ultimate goals are
My ultimate goal it to make FreeBASIC better. i hope we can agree at least on this. FreeBASIC lacks unicode support for I/O operations, it lacks a dynamic unicode string type and (apart from some bugs) it lacks support for other topics like array, string processing, audio, video and network (just to name, what comes to my mind first).

- I wrote code for a better integration of José´s dynamic wide string type (most of the type´s code is his work, except for some bug fixes of mine), which resulted in "EXTENDS WSTRING". Jeff wanted a more generic approach than mine, which was specifically written for José´s type, so he applied changes and bugfixes and finally merged it.
- I wrote functions for basic array processing, which currently sit as a PR on Github.
- I wrote code for real unicode support of I/O functions in Window. Needs some polishing, but currently sits as a PR at Github
- I´m writing string processing functions (extract, parse, replace, remove, etc.) for all kinds of strings types (including the new dynamic wide string type). The goal is to be able to have embedded nulls in this new type just as it´s possible in STRINGs including all existing and new functions. Of course none of this will break existing code.

That´s, what i do in my spare time ultimately
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: How to add new features? (syntax, user API)

Post by jj2007 »

The array.insert() syntax looks oop, while array(insert, args) looks odd. What about
ArrayInsert()
AudioOpen()
AudioPlay()
NetConnect()
NetTransmit()
etc? I would not be worried about namespace problems as long as it is consistent and Google doesn't find hits for FreeBasic ArrayInsert etc...
Post Reply