I noticed that some built-in procs have names that may commonly be used for variables. Often the compiler gets it right and there's no issue, for example:
world << "A"
var/sleep = 0
sleep = 10
sleep(sleep)
world << "B"
It knows that the assignment "sleep = 10" refers to the local variable, not the proc. However, this next example does give an error:
A/proc/print()
world << "hello, world!"
B
var
A/text = new /A()
proc
print()
// error:text :bad format string
text.print()
mob
Login()
var/B/b = new /B()
b.print()
Since situations like this are usually handled correctly, I'm not sure if this one is a bug. If I reference a member variable of text instead of a proc there is no error.
Whether it's a bug or not, it's fixed by specifying "src.text.print()", but it doesn't seem like that should be necessary.
This is where namespaces come in: If the text() proc was instead referenced as BYOND.String.format(), this wouldn't be a problem. Similar to namespaces in C# or packages in Java, you could declare (for a file) which namespaces you are using. And if the default was to include all namespaces this wouldn't break old code. Since the . operator is used for other things I don't know if it's the best choice here.
When a variable is referenced, the compiler has to check if the name refers to a local variable, a member variable, or a global variable. You'd also need to check for the name in declared namespaces.
This also provides a way to group procs by something more than similarity of their function. For example, I was looking for the copytext() proc but never would have guessed that name (it's substr in most other places, but I'm not bitter, I found it eventually). I found findtext(), whose help page links to findText() but not copytext(). If all string functions were in the BYOND.String namespace, these functions would be easier to find.
By letting users assign global procs to a namespace this would also address problems like this one [link]. Let's hope Mobius doesn't mind:
// library code
proc
RGB()
set namespace = Mobius.Color
// code
// referencing the library
proc
test()
world << Mobius.Color.RGB()
This could be implemented now (minus the set namespace bit) by using global variables, but this could get messy. For example:
var
MobiusNamespace/Mobius = new /MobiusNamespace()
MobiusNamespace
var
MobiusColorLibrary/Color = new /MobiusColorLibrary()
MobiusColorLibrary
proc
RGB()
return 1
proc
test()
world << Mobius.Color.RGB()
Declaring namespaces for each proc makes it easier to code and maintain. Also, having namespace declarations as part of the language would make it very easy to have auto-completion of namespaces in the editor (I'm sure code completion is requested a lot). With code completion, if the current token is "t." you'd need to figure out what kind of object t is and what members it has. With namespace completion you just need to know if "t" is a namespace (or a prefix of a namespace) and what it contains. Since namespaces are declared explicitly you'd have this information.
This would make libraries and built-in procs much easier to use.
I don't understand this. You say there's an issue, you give an example, then you say that "situations like this are usually handled correctly." and then "it's fixed by..." Is there a problem? If so, what is it? Can you provide an example where it is not handled correctly?
Or like C/C++, which Byond is created with.
Or "no namespace." You wouldn't want to require everything to have a namespace. At least, I wouldn't think you would want to.
Byond is based on C++ which uses :
Actually, though I don't visit this section of the forum with great frequency, I don't think I've ever seen anyone request that, which surprises me now that I think about it. Possibly because a lot of Byond users don't have experience with other IDEs and don't know such nifty things exist. In my oppinion though, it gets annoying when autocomplete popups block the view of what I'm working on and sometimes interfere in other ways.
Namespaces would be neat to have. I'm not sure how necessary they are, but it would probably be a nice addition. Probably better would be static functions, then you could have something that worked basically just like a namespace for what you want but was more powerful. That would be awkward with the way Byond does object type references though. Might look something like /string.copytext() or /string:copytext().
Pending that, you could make your own library. I know that would not free up all the functions you want, but it would be a start.
You could put a bunch of stuff like that in a library, even if you only used it for yourself. Then you could include it in all your projects and you could always do String.copytext() and if you wanted a heirarchy of these things, you could do something like