ID:2033158
 
Not a bug
BYOND Version:509
Operating System:Windows 10 Pro 64-bit
Web Browser:Chrome 48.0.2564.103
Applies to:DM Language
Status: Not a bug

This is not a bug. It may be an incorrect use of syntax or a limitation in the software. For further discussion on the matter, please consult the BYOND forums.
Descriptive Problem Summary:
Attempting to override const variables on objects in the class definition results in a compilation error:

Code Snippet (if applicable) to Reproduce Problem:
/obj/test
var/const/tests = 3

/obj/test/more_tests
tests = 10

test.dm:5:error: tests: re-initialization of global var

Expected Results:
For /obj/test/more_tests to be compiled with tests = 10

Actual Results:
Compilation error.

Lummox JR resolved issue (Not a bug)
Consts aren't meant to work that way.
Then what's the point of global variables, ever?

Defines can do exactly the same as consts can right now (if managed properly, but git grepping the define name before making it isn't hard) and provide much less clutter in game (debug tools).
TBH, there is a significant feature gap here, in the lack of static variables. Right now in DM, everything is either global or an instance property. There's really no such thing as a class property.

The ability to embed overridable static datatypes in the prototype would actually be a godsend for bigger projects like SS13. Particularly if the datum variable lookup optimization ever comes to fruition.

A few days ago, I attempted to implement something that would allow me to implement static variables, but due to a flaw in the way that DM's call()() function works (which I had previously argued was not a flaw) it came out a bit messy:

#define get_static(ref,prop) (istype(ref,/datum) ? static_data[ref.type][prop] : static_data[ref][prop])

var
list/static_data
static_data_manager = new/static_data_manager()

static_data_manager
New()
static_data = list()
var/datum/d
for(var/v in typesof(/datum))
d = v
if(initial(d.has_static_data))
/*How it should work, but doesn't:
d = text2path("[v]/proc/static_init")
call(d)()*/

//How it has to work because the above:
d = new v()
static_data[v] = d:static_init()
static_data_manager = null

datum
var/tmp
has_static_data = 0
proc
static_init()
return list(
"herpderp"=4,
"derpyherp"=/atom/movable
)


The idea being that you could store per-prototype static variables globally in an associative array that would ensure that it could be set up by overriding the static_init() function.

It is a rather strange feature gap considering the particulars of OOP practices.
We do have a static keyword, though. Am I missing something there?
Static keyword isn't actually static AFAIK, I think it's just an alias for global.
Ah, that is true. It'd be nice to support proper static vars. Technically they'd still be global in operation, but having them apply to a type would be useful.
We do have a static keyword, though.

We have a keyword yes. We don't have static prototype variables, though. Not in operation, really.

The static keyword is a lie.