i'm about to invent another programming language

Moach

Crazy dude with a rocket
Addon Developer
Joined
Aug 6, 2008
Messages
1,581
Reaction score
62
Points
63
Location
Vancouver, BC
my AVM2 frustration is reaching a critical level back here... for those who don't know what that is, AVM2 = Flash for all intents and purposes :rolleyes:

i find that i'm faced with a plethora of situations where i'm working against this tool... this is mostly related to my job, building flash games... but the reasons for my restlessness stems from this little hobby of mine where i make addons for a certain space flight simulator you might have heard about :hmm:


thing is, in my play time, i get to use wonderful C++ - but at work, the nature of how these web-games are deployed forces me to use either AS3 (java-for-babies made intentionally slower) or, more advanced haXe (which although commendable as a one-man-army project, lacks documentation and general resolve in several areas)


what makes me lose most sleep, is pretty much the "way" AS3/haXe (the AVM2 languages) deal with pretty much everything...

let me try to paint you a picture...

one of the most heavily abused data types in any game's development is the all-singing-all-dancing Vec2D, Vector, Point, whatever-you-call-it pair of X/Y floating-point vars for representing positions in cartesian space...

now, this is quite a basic thing right? any working-state game is bound to rely on at least a couple hundreds of those (or more)

say, such a basic thing should be legally obliged to be optimized to the very bones (bytes) if we're gonna put it through the wringer like we do...


ok, so what's my point?

say i need a few of those on my Orbiter addon ship (C++)

if i plan on keeping them for as long as the ship is "alive" inside the sim, i can just toss them into the class definition with a pair of words, like this:

VECTOR3 v1, v2;

and C++, in it's near-poetical glory not only ensures me those WILL BE THERE when i need them, they will also be contiguosly positioned in the class' memory footprint... awesome right?

or say, if i just need a toss-about vector to hold some temporary data during the course of a function, after which it's needed no longer, i can just throw an exactly-alike line inside said function and again, i'm guaranteed i'll have them ready to go (you'll see the alternative shortly, and it's grim) - and i'll have a clear mind that the memory where they were will be free as soon as i decide it should...


now... why is that a thing?


look what i have to deal with in Flash:

if i want a few vars worth of vectors in my class, i must define them like so:

var vee:Vec2D = new Vec2D(42, 42);

not too bad? well, for once it's redundant... tho that's ok... haXe will even let you skip the type declaration whilst maintaning type-strictness from the "inferred" type... ok then...

but then it hits ya... "vee" is NOT a Vec2D-shaped lump of memory - nooo, far from it, is it a reference to a Vec2D, then? well, that's the thing - WHO KNOWS??


apart from the actual layout of the memory used by that class being miles deep under the sea of undefined, the thing that bears most resemblance to what "vee" actually bears, in a C++ sense, is a pointer...

a pointer... huh, is that bad?
shouldn't be... but they managed it somehow... and even genius-boy Nicolas and his powerful haXe language don't seem mighy enough to fix it...

the reason this is bad is quite simple to grasp, if you know C++

a "pointer" is a distinct memory address holding another memory address, which "points" to the thing you want...
in C++, there are a number of times where those are quite useful, even non-optional, depending on your goals


but those are about one or two in every ten times you need a variable for anything....
yet Flash forces "pointers" implicitly and unrevokably for every data-type more complex than the built-in "Int" and "Float"

theres absolutely no way one can bypass this....


and this is what this imples, not having a "pointer-free" option:


thing 1: the "null" menace...
since a pointer isn't really the data itself, it can very well not point to it at all... and guess what, i Flash by default, it wont!

all variables of non-primitive types default to "null" unless assigned to... and guess what - there's no compile-time checking for that, millions of AVM2 opcodes are wasted every second around the world checking for possibly "null" vars... vars that under no circumstance were intended by the authors to read "null"

it's a segfault-guarantee - by default, it's build to break on ya.... and if you don't watch out, it most certainly will.... but not on your watch - "null" is only catchable in run-time, which means your USERS will find it for you!

beautiful! bravo! they've done it! :facepalm:*1e20


as if that was all that's wrong with it....


of course it doesn't end there.... lets see what else...




thing 2: the "new" imposition

as if things weren't slow enough with interpreted bytecode, get this -- every time you need a non-primitive var to be other than "null" (gasp) - you gotta instantiate something and/or assign to it...

yet "new" is THE ONE SLOWEST piece of code you can have in Flash - the class constructor function, i mean... from what i read, Flash will always re-interpret and "manually" build up your class, which then it allocates into crudely-managed memory (which you may know nothing of)

it returns you a "pointer" to fill up that "var".... relieving it from the ghost of "null"

but that's only at runtime...

you see, 'till then, every member field of a class is set on being "null"... and "null" it shall remain untill the "new" debacle takes place and fills up this bug-hole that adobe dares call a variable....


sad really, but that's the least of it....




thing 3: the best worst way to clean up this mess


ok, so what's gonna go down when i need a Vec2D var to use in a function? (which in C++ we do without even giving it much though)

we still gotta use "new" - there's no such thing as a "stack declaration" in Flash... nooo that would be "hard for us"

so, to have it all be the same, "new" is the way to create every new variable... including those that are needed for not more than a couple of cycles inside a function.... well, what happens to those allocated bytes after no more vars remain "pointing" to it - if this was C++, we'd have a nasty memory leak

but this is Flash - it "takes care" of "complicated things" like that.... (adobe takes another shovel-load at the digging of their own graves)


a complex "garbage collector" systems keeps track of every var you "new"... this, of course means overhead when creating these objects, and some more to get rid of them later...

all so you could absent-mindedly forget to add a "delete" later on... *cringe*




which leads to thing 4: "hey, wait! i was gonna use that!"

not fewer than a whole bunch of times, i had to somehow "overprogram" something just to prevent the GC from killing data i had further plans for...

yep, it's quite capable of that - if it THINKS you can't access that object - it kills it dead!

and nope - it ain't telling you about it... isn't debbuging what end-users are for anyways?


so that leads to further complications... now we gotta ensure that we always have something pointing to our vars, even when doing so would be madly inconvenient...

at this point, i'd like to raise attention to the asynchronous coding model used by Flash....
since stopping code at any time is deemed "foul" and most unmanageable by the very architecture of the AVM2, a "clever" event-driven model is forced upon us poor flash-monkeys...

long story short, there's absolutely no stopping a function for ANYTHING - even if nothing can/should be done before that thing is complete (i.e. loading a file, or receiving socket data)
so Flash constrains us to structure our programs in some what thay permits the terminating of every running scope before the "event" can be triggered... sigh... ok then, let's pretend we don't mind....

first problem... the vars declared in the function that called for the event are lost... the garbage-collector is having it's way with them by now...

second problem, whatever way we choose to preserve that data, implies the risk of a MEMORY LEAK


OMG... we need more facepalm :facepalm:



WHY ON THIS GOOD EARTH THEY WENT TO ALL THIS "NULL-NEW-GC" TROUBLE IF WE END UP WITH THE SAME PROBLEMS AS WITHOUT IT???

actually much worse, really... because without ANY way to explicitly remove a previously instantiated object, (the GC should "take care" of that, remember?) we can only make feeble attempts to satisfy the requirements for something to be considered "garbage"...

and no, you're not told if it works or not... it's erm... "automatic" :suicide:



so lets see.... in C++ we have to decide how to instantiate an object... options are global-memory, class-member, function-scope or "manually" via "new" and ensuring that there's a "delete" later...

seems tough, Flash should be MUCH easier, being all "automatic" and stuff...

in Flash we have to...

-redundantly declare "var" followed by the data type... then mind that until "new" comes along, that variable is defaulted to "NULL" (i can't even... urgh)
- add a myriad run-time checks to ensure that "null" vars don't get where real data is needed
- then we gotta ensurethat we don't lose the pointer to that object, lest the GC-boogieman takes it 'round back and beats it a'ground
- then we gotta make sure that member-vars are reset to "null" before a parenting class is disposed of (which you don't know when it is)

- somehow deal with the fact that low-level memory management must be done "against the machine" in bytecode interpreted language



so let me ask of you... given these considerations - API's aside, which is harder to work with - C++ or
Flash?


well, one is used for "play" while the other is "work"... makes sense, no?



oh, the humanity :uhh:


next post will be about my conceptual solution to this cataclysmic series of mis-features that plague my tool-of-the-trade... i shall call this: "aXiom"



:cheers:
 

N_Molson

Addon Developer
Addon Developer
Donator
Joined
Mar 5, 2010
Messages
9,290
Reaction score
3,258
Points
203
Location
Toulouse
And I found C++ complex... Those memory allocation procedures within Flash seem absolutely insane :lol:

Good luck, seem you need it ! :hailprobe:

(BTW I was wondering why Flash games are so slow given they use only 2D graphics, now of course if everything is checked 3 times and you still have memory leaks at the end, I understand better...)
 

Moach

Crazy dude with a rocket
Addon Developer
Joined
Aug 6, 2008
Messages
1,581
Reaction score
62
Points
63
Location
Vancouver, BC
Spacethingy;bt2962 said:
Real nooby programming question here, but is there a way you could have a "C++ player" on a webpage, like a "Flash player"?
:


oh boy, i only wish....

there are a few much more evolved options, such as unity, which works with C#.... but many similar problems are still unnacounted for...

i honestly don't know what sort of corporate-dwelling bug bit the developers that though "garbage collection" was the way to go...


seriously, what's easier - making sure you clean up after yourself, or jumping through a million hoops to ensure things aren't cleaned up in a way that (most likely) doesn't work for you?


and that's the reason i don't fancy having a cleaning lady at home very much :lol:


its MY mess - i know what my things are and where i left them... interpreted languages are creating an army of dull-minded programmers who think C/C++ is "black magic"

if only they gave us the option to turn off this ridiculous set of schemes they market out to "simplify our work"... but no, they know better, dont they?

i blame this all on Java :compbash:
 

ky

Director of Manned Spaceflight
Joined
Jan 22, 2011
Messages
1,409
Reaction score
0
Points
0
Location
Boynton Beach
That is the longest blog post i've ever seen.Flash does sound scary.All those racing games ,flying games i've played take that much work.........
 

PennyBlack

Altea Development Team
Addon Developer
Joined
Jun 17, 2010
Messages
713
Reaction score
5
Points
0
Location
Infront of my PC
Website
pennyblack.yolasite.com
The more they over come the plumbing, the easier it is to block up the system... Scotty.

To me, and I only got to learn BBC and Qbasic... but it sounds like the flash programe lacks the ability to multi-task within itself. It doesn't remember a variable string and it's value unless being used within a current function or proceedure. Can't you programe a memory allocation externally from the program and store the data there and call on it later. I hope I understood your post correctly. I understand there are many different languages, but the principles I think are the same, or should be when handleing variable and strings.
 

Moach

Crazy dude with a rocket
Addon Developer
Joined
Aug 6, 2008
Messages
1,581
Reaction score
62
Points
63
Location
Vancouver, BC
yeah well... that's pretty much it...
flash doesn't know what you're up to until it gets there itself... and in the meantime, it goes on as if it did...


unfortunately, FlashPlayer is pretty much sealed airtight in a most Mac-like manner... so one cannot "add" any features to it.... and plus, since it's a rather abstract dependency that must bbe sorted out on the users end ("flash player must be installed to view this page" - how many times have we not seen this?), trying to moodify it is an excercise in futility...


what i CAN do, is write a pre-compiler...
there are a number of workarounds to the problems mentioned here that can be accomplished, as long as one is willing to throw readability out the window...

so while i like my code to be understandable by human beings, i have started work on an IDE-plugin that grinds over C-like code and automatically generates the needed kludges to make that work transparently in flash...

i guess this could have been called "MacGyver-Matic" or "KludgeMaker300".... but i found more impactful to call it: "AXIOM" (Advanced eXperimental Inline Object Model)

a few alter-ego acronyms have come to mind as well...

Alternative eXtended Interpreted Object Memory
Attachable haXe Instancing Overhead Mitigator

to name a few....


well, it's gonna find an alternative type of notation (more similar to C++, less like Javascript) in your code and substitute fitting kludges to accomodate your ideas in a more processor-firnedly manner...

it just might be that this is a major override of the whole FlashPlayer memory system... but i don't see we have any alternative... gamers expect more and more of flash games, but we've reached the limits of what this tool can deliver years ago... still only a few developers have taken action

and i don't feel like waiting for them to figure something out....

so stand back, i'm gonna try SCIENCE :blink: :lol:
 

PennyBlack

Altea Development Team
Addon Developer
Joined
Jun 17, 2010
Messages
713
Reaction score
5
Points
0
Location
Infront of my PC
Website
pennyblack.yolasite.com
Visual basic allowed for multi function/multi tasking via window form programming. I had a look at it once and unlike old Qbasic where line for line was followed in the program and only allowed you to jump via goto line or call proc, it seemed a waste of computing power so I looked into it when it came out. VB allowed for many opperations at once via the main programming window whilst the main program ran. I know, every body hates VB and I don't know why. It offered a user, I wouldn't say friendly but a compatable interface within the windows enviromewnt to work in. I enjoyed tatting with it and it had no problems with remembering unused strings and variables that where tied to them. I enjoyed it, but lost interest as I found programming a task and half. It's all very well the computer remembering a value, but with string names, I just couldn't remember which one was tied to which and what it did after a few hours. Skinning is way less brain tasking for me.

I wish you luck sir in evolving your idea to operate outside that tight box modern developers like to tie you to. They may be the same developers that programmed the Windows miscillanious software update.
And you should go for the "MacGyver-Matic". Or even "Moach-Matic" let your ego burst out m8. :thumbup:
Sounds like your going to earn it.
 

HarvesteR

Member
Joined
Apr 22, 2008
Messages
386
Reaction score
15
Points
18
The main problem with these ECMA-Script based languages is that they treat anything beyond the most basic data types (ints, floats, bools) as referenced types.

So yes, when you declare an intance of your class you have to mentally put a & sing in front of it, because that's what you're getting: a reference.

And from that shall rise a whole array of trouble, and most infamous among them, is the Null Reference Exception.

This horrible, horrible non-error creeps up on you when you least expect, and forces you to pretty much table-test the entire call stack from where the error came in up to where it's really at. It's pretty much like trying to find a needle in the haystack, in the dark, with people poking at you :facepalm:

And it's a non-error. Why is that? because it goes against common logic... you'd EXPECT things are working right, but they're inexplicably not... and now you have to either dig around for the source of the problem, or cram your code full or error trapping waste logic, which only serves to further convolute and complicate your code.

Furthermore, if you've ever worked with Tweens in Flash, you've probably seen this gem here: You CAN declare a new anonymous tween and just let it run and do it's thing... but then, the shady GC will creep up on it, at random, undetermined times, and wipe it off and it stops where it was when the GC murdered it. So what to do? it seems you need to declare variables to hold it... FOREVER... even long after the tween was done and isn't needed anymore, it will still be there, hogging the little memory the FlashPlayer allows you. The solution? This is probably one of the ugliest hacks you get do, in any language... You declare a Dictionary, which is a list that uses objects as keys... and you use your new tween as the key to a bool, which you just set to true... the fact that the tween is now listed as a reference to something, will be enough for the GC to skip over it as it rampages through your data.

This leads to most excellent constructs, like this pretty thing:
Code:
tweens[ new Tween(this, xValue, yValue, Time, somethingElseIForgot).Start() ] = true;


A simple thing to do to resolve the problem would be to add the option to declare structs in place of classes... In C# at least (it's also managed, I know, but it's better at it), structs are the same as class definitions, only they are value types, instead of referenced types... so you don't get a &myVar when you declare a variable somewhere, you get the real thing.

Oh well... I guess we could stay here and bash the shortcomings of ECMAScript languages forever... so I'll just [/rant] here.

Cheers
 
Last edited:

Moach

Crazy dude with a rocket
Addon Developer
Joined
Aug 6, 2008
Messages
1,581
Reaction score
62
Points
63
Location
Vancouver, BC
it's actually a common misconception that flash returns a &reference to vars... it's syntax is akin to that of &ref's, but you can verify that it's in fact a "pointer" by reviewing a few giveaway facts:

-- if you pass an object as a function parameter, that function can modify the values inside it
-- if you try to modify the parameter variable itself (make it point to another object) the original "var" remains unaffected :hmm:
-- references, as per internationally-standardized conventions, cannot be initialized with "null" (and actually cannot be "redirected" either)


so, those "vars" aren't &references at all - that would be oodles less bad - those are syntax-omissive *pointers
that does a very effictive job of combining all the drawbacks of pointers and value-copies into a big mash of ugly :facepalm:

the tween-hack is a very nice example to help my case against garbage-collection in general...
did you notice one thing about your code? YOU HAVE A MEMORY LEAK (give it a "Graham's Number" facepalms :facepalm:)

aint that why GC exists? to avoid those? -

with this - my case against the existance of this most foul apparatus can prove itself [ame="http://en.wikipedia.org/wiki/Axiom"]axiomatically[/ame], since for all effects:
you have a memory leak BECAUSE you have GC


i'm not gonna sit around ans bash ECMA-script languages as if it were some unsurmountable fatality... i'm gonna do something about it :stirpot:


my new language (a HaXe precomplier, actually) shall be called AXIOM - in large part because of the epic amount of FAIL evidenced here... but it really means (Acronym eXchangeable Interpreted Object Markup)
 
Last edited:

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,635
Reaction score
2,352
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
:lol: Making programming languages seems to become some sort of sport today. I currently refine the virtual machine "bytecode" of the Black Dart, which will later be programmed by an Ada dialect... this VM is optimized for GNC software, because I got terribly upset out slow Lua can be when doing linear algebra. The bytecode now is especially designed for doing such stuff as multiplying two matrices or load an I/O program into one channel processor.

Could maybe one day get cast into a MFD for general purpose stuff, but for now it is inside my own personal candidate for the vaporware of the decade award.
 

Moach

Crazy dude with a rocket
Addon Developer
Joined
Aug 6, 2008
Messages
1,581
Reaction score
62
Points
63
Location
Vancouver, BC
well, luckily for me, i'm not coding a VM... too many of those out there already (it's becoming a problem)
i'm just on the process of devising a pre-compiler, which should generate otherwise "conventional" HaXe language code by injecting a set of clever snippets build from an adapted C-like declaration syntax...

so it's more a lexical than a logical problem.... still a problem, nonetheless :lol:
 
Top