#Can we use statics like this? ...

1 messages · Page 1 of 1 (latest)

long anvil
#
function a()
{
    static _struct = {};
    return _struct;
}

function b()
{
    static _struct = a();
    return _struct;
}

b().variable = "hello world";
show_debug_message(a().variable); // = ?
show_debug_message(b().variable); // = ?
fiery badger
#

I've been using statics like this for a couple things

#

I think Sonus lately uses mostly statics

#

Just so I'm not polluting the global name space as much

long anvil
#

yeah people have been bitching at me about that in Scribble so i thought i'd tidy things up

fiery badger
#

It's not as speedy as global alas

#

But far speedier compared to other solutions

azure stratus
#

using a constructor for _struct in a also handles initialisation nicely

long anvil
#

it does indeed

long anvil
#

lol i'm down to one single global remaining

#

oh duh i can move that into the state struct, we're good, zero globals

fiery badger
#

While I'm at it, I should be doing that for a couple other libraries

azure stratus
#

should we do this for Input pugwat

long anvil
#

yeah probably

#

this took basically 8 hours of work so... not looking forward to that

azure stratus
#

seems like it went pretty quick.. o nvm lol

long anvil
#

haha

#

i ground it out

#

Scribble was particularly offensive because it used a lot of variables for shader uniforms

#

Input is pretty bad too though...

azure stratus
#

is debugging the library not a nightmare this way

#

does the debugger surface script scope stuff now

long anvil
#

it does not

#

the structure of Scribble is more conducive to this kind of programming since everything's tucked away inside structs anyway

azure stratus
#

mhm

#

if it works for you, it works

#

not like i spend much time in the debugger either tbh

long anvil
#

we'll see how it goes for Scribble, i'm in no rush to do this conversion for other libs

azure stratus
#

anyway maybe moving out of global and an init review can be a thing... for later

#

scribbles the guinea pig pugward

long anvil
#

indeed!

#

i also find Scribble generally easier to debug than Input i think?

#

guess it's easier to replicate bad situations

#

i ain't no octopus, can't press all those buttons all at once

azure stratus
#

don't need to invent any enemies

long anvil
#

Y2K was a hell of a time

#

i love all the organic shapes

#

i wonder when we'll go back to that

#

i think second time round we'll do it good

fiery badger