How would you call a static class?

Community Forums/General Help/How would you call a static class?

ziggy(Posted 2013) [#1]
I'm designing a language (nothing serious) but as I'm facing the AST structure's, I find that the idea of a "static class" is somehow a contradiction in itself. If it's static, it should not be a class in the first place.
As I'm writing what's suposed to be an OO languge, I understand how having those "static classes" could be considered somehow wrong, but I do think it can be useful in some scenarios, such as having a centralized place with all standard i/o functions, or having a single place with all standard math functions, etc.
In some ancient basic dialects, I recall this being called MODULE, but I'm already using this keyword for sort-of compilation clusters and also, I don't think it is clear.

so... as my English skills are shrinking day by day, any suggestion for a self-explanatory single word? I would like to "name" a place with a collection of static members (functions and globals only in a BlitzMax language).

This is not vital nor important, but I like when languages are easy to read and understand without having to get a manual in the first place.


Yasha(Posted 2013) [#2]
C++ and C# call this "namespace". Java on the other hand doesn't bother and just has everything in classes, object or not (it does have "packages" but they're tied to the file organisation, probably not what you want). You can easily go either way, basically depends how you feel about reserving more keywords. "Context" is another good word.


If you're interested in "weird" language design, also check out ML's "structure" and "functor" (not in F# which is more like C#). Structures are namespace objects that exist at compile-time, same as in other languages; functors are compile-time functions operating on these, that accept a bundle of types/globals/functions and programmatically build new namespaces (like C++ templates on speed).


ima747(Posted 2013) [#3]
I've come to like the singleton approach. It's still a proper object, but it's just a single instance of that object that anyone can access. It has a little annoyance in that you have to call up the reference to the singleton to use it, but it keeps everything clear regarding ownership. I use them from time to time for managerial tasks e.g. I have a list of space ship objects. I want to be able to load the ships as needed to conserve memory, but I need to be able to search through them for ships that belong to a particular species. I make a singleton called ShipManager. Ship manager has 2 methods GetShip and ShipsForSpecies. If you call get ship it handles all the ship loading, if it's already loaded it just uses the one in memory, etc. FindShipForSpecies iterates through all the ship files by calling GetShip (thus re-using as much as possible) and returns and array of the matching ships. This way from any other class (say from races, space stations which are a subclass of space objects, etc.) I can pull in ships and only have to worry about the loading in one place, and I can wrap that loading with internal memory management and caching stuff.

Another example would be for simplified file IO. You should have a file IO class, but perhaps you want an abstracted file that handles the games settings and configuration. A singleton class for settings could provide simple methods for specific settings, map those to data management, and handle loading and saving of the data invisibly in the background.

These are more sort of case by case things, rather than whole language scope, though there may be a lot or a little overlap depending on what you're going for...


Gabriel(Posted 2013) [#4]
If you're looking for a word that will have the most name recognition among English-speaking programmers, I agree with Yasha that namespace is a word most will know.

I'm also a fan of the singleton pattern, but singletons are really something for an application, not for the language. If a language's features were contained in something called singletons, I would be wondering whether I need to instantiate them, or destroy them, whether there was any cost to doing so, when I should do so. It would be pretty ambiguous. Namespace has none of those connotations.


ziggy(Posted 2013) [#5]
Thanks!
I also like the Context word. Namespace sounds very weird to me. Has ir any other meaning out of coding environments?


D4NM4N(Posted 2013) [#6]
it does have "packages" but they're tied to the file organisation, probably not what you want
True, however packages work in a similar enough way as namespaces except "best practice" enforcement is strict, where as .net is not.
VS will nag you with warnings if this is not done and when using "new class" etc.. the auto-icomplete will namespace in ref to the file's location.