Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Can AGK Tier 1 do functional programming or OOP? What is the best way to code?

Author
Message
hYu
8
Years of Service
User Offline
Joined: 26th Feb 2016
Location:
Posted: 1st Sep 2017 11:49
Hey everyone,

I'm kinda self taught, especially learnt most of what I know back in the days of DarkBASIC 1, anyways, I've been using AppGameKit the past few months...
I think I'm fairly familiar with it, but just in case I missed something,
I'd like to know:
1. Is AppGameKit (Tier 1) capable of functional programming?
2. Is AppGameKit (Tier 1) capable of object oriented programming?
3. What is the best, cleanest and safest coding method to use with AppGameKit Tier 1?

Cheers
Westa
13
Years of Service
User Offline
Joined: 28th Oct 2011
Location:
Posted: 1st Sep 2017 12:47
Tier1 is not really OOP. Though it does have a concept of data structures.

Its not unlike BASIC in its syntax with functions for subroutines.

If you want OOP - then I would personally say go Tier 2 - its a bit steeper learning curve - and more platform specific - but the end results tend to make it worth the effort - especially in terms of performance - you dont have the pcode style interpreter overhead.

Westa
Xaron
10
Years of Service
User Offline
Joined: 3rd May 2014
Location: Germany
Posted: 1st Sep 2017 18:41
Tier 1 is not only "not really OOP" it's not OOP at all.

Tier 1 is not capable of OOP and it's not capable of functional programming. Don't know if you really mean functional programming here or procedural programming. Functional languages are pretty exotic (like F#).

If you go with Tier 1, the safest way is to use #option_explicit which force you to declarate variables before you can use them.
Dybing
13
Years of Service
User Offline
Joined: 12th Sep 2011
Location: Bergen, Norway
Posted: 1st Sep 2017 19:02 Edited at: 1st Sep 2017 19:03
Tier 1 is Procedural. OO is overrated, and Functional isn't programming but an LSD trip using obscure math-magic.

It's ok though. You can achieve anything in Procedural as you can in OO, and do it easier and faster. Just as long as you organize your project properly and avoid mutable globals like the plague. If you get lazy and take shortcuts, you'll soon have an unholy mess on your hands. Though that is a truism no matter what paradigm you program in.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 1st Sep 2017 21:00
Quote: "as you can in OO, and do it easier and faster"

sometimes more, sometimes less.
there are advantages in oop that i will not miss.
AGK (Steam) V2017.08.16 : Windows 10 Pro 64 Bit : AMD (17.7.2) Radeon R7 265 : Mac mini OS Sierra (10.12.2)
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 1st Sep 2017 21:19 Edited at: 1st Sep 2017 21:21
Quote: "2. Is AppGameKit (Tier 1) capable of object oriented programming?"

No but you can use types and pass them by reference to functions so you can get very far with that.
Typed arrays are your friend here. They are global and quite similar to classes, except that you can't use methods.

Quote: "3. What is the best, cleanest and safest coding method to use with AppGameKit Tier 1?"

Stick to a single main loop (DO...LOOP) and loop through it every frame.
Do everything inside functions.
Use finite state machines to control your game.
Use lots and lots of source files.
Use virtual resolution instead of the default percentage system.
tmu
7
Years of Service
User Offline
Joined: 2nd Feb 2017
Location:
Posted: 1st Sep 2017 22:58
There is no OOP and thankfully no "functional programming". Best practice is to simplify, simplify and simplify a bit more. This is what tier 1 forces you to do and is sometimes nice, sometimes frustrating to write the basics from scratch.

Suggest putting your global variables in user defined types, which are like C-style structs. #option_explicit can be useful but I found it bloated my code too much.

Tier 1 is basic. Weird kind of basic where you only have user defined types and the type referencing is totally confusing as you can only reference in function parameters, not within functions. Empty arrays have length of -1. Arrays with single element are length 0. mm'k

But it is still the nicest way I found to write cross-platform games with a good abstraction level. For me tier 1 is fine and good enough so far. Not going to C++ (tier 2), thank you very much .
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 2nd Sep 2017 00:02
Quote: "If you get lazy and take shortcuts, you'll soon have an unholy mess on your hands."


lol, so true.

I tend to draft code, get it functional and working then examine how I can streamline it, when I don't, I regret it!!

and "Do everything inside functions." is sound advice but don't have a function doing 101 different things, keep them specific and function/variable/type names descriptive, this will be helpful when returning to code, also, even with descriptive names use comments, (lots n lots of comments) it may be apparent what's going on at the time of writing but return to code 2 weeks later and you soon forget what you was thinking, prefix globals with g_, types with t_ and local function variables with i,f,s so its clear at a glance what data its holding EG: (g_MyGlobal, t_MyType, sStrValue, iIntNum, fFloatNum)

I also tend to label my functions, a small comment why is was created and where its called from, when revisiting old code these hints are vital to save time reading source code to remember your train of thought.
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 2nd Sep 2017 07:37
Quote: "and "Do everything inside functions." is sound advice but don't have a function doing 101 different things, keep them specific and function/variable/type names descriptive, this will be helpful when returning to code"


So true!

If you keep your functions short and name everything descriptively there is less need for comments.

Also, never write the same code more then once. Make a function instead.
tmu
7
Years of Service
User Offline
Joined: 2nd Feb 2017
Location:
Posted: 2nd Sep 2017 12:53
I prefer to prefix my function names with something referring to the file where it is in. So playerMove() sfxFire() and so on. Helps with namespace pollution and navigation.

I stick every global variable inside a user defined type if in any way possible. Then make a single global variable with that type and reference all variables from that type. This gets the compiler to complain if I change the name somewhere or try to reference a bad variable, even without #option_explicit. Also helps with namespace pollution.

Also commenting around the code where something is done (when it produces an action via shared variables or so), and why something is done is very useful for figuring out what is going on in those thousands of lines of spagettimonster later on..
Alex_Peres
AGK Master
15
Years of Service
User Offline
Joined: 13th May 2009
Location: The Milky Way Galaxy
Posted: 2nd Sep 2017 17:09
The best way to code is OOP, but you need to use tier2. All modern game engines use OOP except AGK. C# was made to use OOP only and it's one of the best coding languages now.
Maybe this will take more time to learn, but then you'll have a much more readable, efficient and reusable code.
Xaron
10
Years of Service
User Offline
Joined: 3rd May 2014
Location: Germany
Posted: 2nd Sep 2017 19:26
OOP is just one coding paradigm and it is definitely one of the better ones but I never would say it's the best way to code. If your only tool is a hammer, every problem looks like a nail.
Alex_Peres
AGK Master
15
Years of Service
User Offline
Joined: 13th May 2009
Location: The Milky Way Galaxy
Posted: 2nd Sep 2017 20:20
IMHO, OOP is definitely better than procedural programming. Procedural programming can be easier only for very and very simple game.
By the way, coding&debuging on Visual Studio waaaaaay better than AGK-tier1!
My experience suggests that if something is very easy to start with - later it will be very hard to do something good with it.
For example:
AGK: very easy to start - hard to do something professional looking (in 3d at least). Leaks many pro-features. Doesn't have built in editor.
Unity: takes more time to learn - easier to get something cool.
UE4: hard to learn - easily to get the best quality.

But this is only my opinion.
MarcoBruti
13
Years of Service
User Offline
Joined: 20th Nov 2011
Location: Caput Mundi
Posted: 2nd Sep 2017 20:47
I would suggest to TGC to replace BASIC with LUA, or add support to LUA.
LUA allows OOP and some important features like closures. I have used it in Corona SDK and I have found it very easy to use and to learn.
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 2nd Sep 2017 20:59 Edited at: 2nd Sep 2017 21:00
A poem can be written in many languages, the better the poet, the better the poem, the language is only a vessel of expression! amazing things can be done with a simple programming language with the right person behind the keyboard, no one is better.

Edit:

Quote: "I would suggest to TGC to replace BASIC with LUA, or add support to LUA."


That I would like to see +100 from me
Alex_Peres
AGK Master
15
Years of Service
User Offline
Joined: 13th May 2009
Location: The Milky Way Galaxy
Posted: 2nd Sep 2017 21:38
PartTimeCoder, you can dig by spoon or you can take a shovel.
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 2nd Sep 2017 23:41
A Spoon is not as useless as you might think!
nz0
AGK Developer
17
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 3rd Sep 2017 02:54
You can use OO principles in T1. I do it all the time and it's kind of normal and essential to make complex game models / situations I think.
I did it in version 1 even before the array extensions. It's second nature to me because of my background, but yes, I can and do develop my games using an OO model in T1.

When I say OO I mean the inheritance model derived from parent->child. e.g. tBullet is a child of tGun etc. and the objects are generated as OO friendly objects and such stuff.

We don't have events and such, but there's nothing to stop us coding T1 in such a style.

I agree with the principle of a state machine for control. It makes so much sense.

Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 3rd Sep 2017 07:18
I agree with nz0, you can use a lot of OO style principles in Tier 1. Personally I can't think of anything I can't do. Sure, some things are more convenient in OO.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 3rd Sep 2017 08:30
Quote: "add support to LUA.""
or Swift

+1

Quote: "you can dig by spoon or you can take a shovel."

Youtube: https://youtu.be/9VDvgL58h_Y
AGK (Steam) V2017.08.16 : Windows 10 Pro 64 Bit : AMD (17.7.2) Radeon R7 265 : Mac mini OS Sierra (10.12.2)
Alex_Peres
AGK Master
15
Years of Service
User Offline
Joined: 13th May 2009
Location: The Milky Way Galaxy
Posted: 3rd Sep 2017 14:08
Markus, LOL!
MarcoBruti
13
Years of Service
User Offline
Joined: 20th Nov 2011
Location: Caput Mundi
Posted: 3rd Sep 2017 16:07
Swift would be very appealing...but it would need TGC to purchase the license from Apple...very bad!
Dybing
13
Years of Service
User Offline
Joined: 12th Sep 2011
Location: Bergen, Norway
Posted: 4th Sep 2017 03:21
OO principles need not be OO. Generally when people talk about OO they mean Classes. Which I am sure Alan Kay is still infuriated over - howling at the top of his lungs "I should have called it message oriented programming instead!!!!!"

So what is OO, and how can you 'fake it' in AGK:

1: Encapsulation

Anyone who have ever done any OO programming know that this just isn't true in practice. For convenience one opens up types and classes all over the place, creating a wonderful web of dependencies that criss-cross the code. Over multiple source-files even, just to make the mess complete.

In this regard, there isn't much difference between OO and AGK. If you control your type instances properly, you have just as much control over your mutable data as in using OO classes.

2: Abstraction

I'll give OO the nod here - at least with regards to data manipulation. You can hide a lot of detail inside private methods. As for just operations, it's just as easy in AppGameKit to abstract out the 'nuts'n'bolts' implementation to underling functions in order to not deal with details of implementation at higher levels of logic-flow.

3: Inheritance

Whilst you can't inherit behaviour in AppGameKit, you can inherit data-structures to make more complex data-structures.

4: Polymorphism

Not an OO exclusive, but it most certainly is missing AGK. Some sort of interface or function overloading would be great in AGK.

---

So for the most part, you don't really need OO - just as long as one keep ones mutable data-structures under strict control.

As for the Basic syntax, it's not ideal. I get the reason for it. Easy to learn, but I'd much prefer a simplified C like syntax. As in Go, which is quite easy to get into if one already know one of the C-like languages. I feel naked without curly-braces. Why I never have gotten into Python

As for the IDE, It's not horrible. Though I'd much prefer if they made a Tier 1 extension for say Visual Studio Code.

My biggest gripe though is namespaces - or rather the lack of it. Make it so that on the top of each file we can declare what module/package namespace the file belongs to, and I'd be a happy camper.
hYu
8
Years of Service
User Offline
Joined: 26th Feb 2016
Location:
Posted: 5th Sep 2017 08:21
Thanks everyone for the replies. Lots of great advice.

Yeah I did a bit more research into functional programming and it does seem like a bit of an lsd trip Definitely something AppGameKit couldn't do and probably doesn't need to be able to do anytime soon.

I haven't really gotten into C++ and object oriented principles. Some day I'd like to but don't really have the time to learn at the moment.

I've been skimming through the AppGameKit official tutorial guide and the way the author structures his/her games is to put basically every variable or type underneath one big game type, and then make that global.
I guess this is a paradigm is kinda imperative with functions and one big global.
Could this be potentially dangerous in the long run as as you all know, globals are generally regarded as bad in programming. And especially if the game is large. What are the things that could go wrong?

The only other way I could think of keeping the code relatively organised yet with no globals is to initialise all game variables and types in main.agc, create functions for all the main procedures/functions in your game that could also have subfunctions of their own, and then pass in the game variables/types by reference.

But I wonder if passing in arguments by reference is any safer than just having globals, which may be easier to implement.

Cheers

ShaunRW
DBPro Developer
16
Years of Service
User Offline
Joined: 7th Jan 2008
Location: Brisbane, Australia
Posted: 5th Sep 2017 09:51
All I would like is function pointers or something like CallFunctionByString( string ).

A bit like this:


I think this will give a lot more flexibility while keeping AppGameKit true to basic.
Supertino
7
Years of Service
User Offline
Joined: 22nd Jun 2017
Location: Behind you!
Posted: 5th Sep 2017 11:11
Having come come BlitzMax\Monkey at first I felt lost without OOP but you soon adapt.
tmu
7
Years of Service
User Offline
Joined: 2nd Feb 2017
Location:
Posted: 5th Sep 2017 11:39
For me C++, Unity etc. are the spoons as there I will spend all my time learning the complexities and details of the framework when I just want to get stuff done. AppGameKit just does all I need with a few simple commands. Then it is up to me to make a game with that and manage the complexities. Sure, I guess it takes much more skill to master complexity with simple tools rather than make a mess with complex tools. Tier 1 AppGameKit certainly misses some key concepts/data structures such as hash maps/sets/dicts that would be useful in many times. But other than that, and some of the weird stuffs I listed before, I like it.

With regards to code structure the only thing I really miss is a better scoping mechanisms to put the functions in different namespaces. I have found polymorphism has very few really good use cases, inheritance similarly.

Maybe it depends on what you are doing, I have done 2D so far and for me AppGameKit is very good abstraction level, exporting to multiple platforms etc.

Some more general programming language might be a fine addition on top of AppGameKit but I doubt it makes financial sense for TGC.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 5th Sep 2017 12:22 Edited at: 5th Sep 2017 12:24
@ShaunRW
Quote: "CallFunctionByString"

my opinion,that will bypass the compiler,cause side effects, the correct way is using a select case.
but the idea will useful for processing scripts with all commands.
AGK (Steam) V2017.08.16 : Windows 10 Pro 64 Bit : AMD (17.7.2) Radeon R7 265 : Mac mini OS Sierra (10.12.2)
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 5th Sep 2017 18:35
Quote: "Could this be potentially dangerous in the long run as as you all know, globals are generally regarded as bad in programming. And especially if the game is large. What are the things that could go wrong?"


As long as you are the only programmer and you name things properly I can't see any harm in this.

It's really hard to do anything without globals when you don't have OO. For example your functions are not part of your classes so they don't have access to any private variables.
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 8th Sep 2017 09:09
Global variables are like guns. Harmless on their own, but dangerous in the wrong hands.
Click here for VR Legend of Zelda stuff

Login to post a reply

Server time is: 2024-11-24 07:49:00
Your offset time is: 2024-11-24 07:49:00