Programming Style: functional modules or compact engine?

As some people might have read, I plan to script my own "engine" with MV and are currently in early planning.

One of the question that I'm currently thinking about is wether I should write a lot of modular plugins, or try to keep the plugins as compact as possible.


I'll give you one example:

I'll need to add several new values to the actors. Some are attributes for limiting equipment and a few other things ("You need average strangth to use an iron hammer").
A second part would be a modification of TP and adding a fourth point resource (creating a matrix for body/mind and wound/exhaustion), and a few more changes to the actors.

Functionally those changes would be independent on each other as they would affect different parts of the default engine, but they would all end up on a modified status screen (I don't like to go back to the main menu to select a different screen, just to check other data for the same actor).

So one option is to write a different plugin for each area (attributes, energies and the other values each in different plugins), each containing only the code for handling those values.

The advantage would be to make them independently usable and testable, but it would result in modifications to the actor from several plugins and require a mess of conditional codes for the status screen (which of those plugins is currently included and change the display accordingly).

On the other hand, I could combine all into one actor plugin. That plugin would not need the conditional checks for other plugins, and would be a lot easier to write and maintain - but the different changes would be combined and could not be used independently from each other.

I have to admit that I haven't decided if I will make the engine available publically or not - if I use it only for my own games, the engine type writing would be a no-brainer, but I consider making it available to others, and then the modular division into several plugins might have advantages. Another point is that writing as a complete engine is probably less work than adding the modularity.

What are your Opinions on this?
http://forums.rpgmakerweb.com/index.php?/topic/43935-maybe-dont-make-complex-scripts/

This is related to your question, I guess. 🙂
yes and no - I'm talking about a different sort of complexity. Splitting the functions into smaller, independent plugins would actually make the functions more complicated than keeping everything in a large script with many functions.
So one option is to write a different plugin for each area (attributes, energies and the other values each in different plugins), each containing only the code for handling those values.


The advantage would be to make them independently usable and testable, but it would result in modifications to the actor from several plugins and require a mess of conditional codes for the status screen (which of those plugins is currently included and change the display accordingly).


On the other hand, I could combine all into one actor plugin. That plugin would not need the conditional checks for other plugins, and would be a lot easier to write and maintain - but the different changes would be combined and could not be used independently from each other.
I would do something in between: provide a core script that would allow you to write all of the other plugins separately.


The core script would modify the common class so that you don't need to perform too many conditional checks.


It depends on what your intent is with each plugin: if they are unrelated, I would not put them in the same script.


If they are all somewhat related, you may consider to just bundle it together.


Now let's say each plugin might do something different if another plugin exists.


For example you have plugins A and B, and A might do something different if B exists.


In this case, I would create a third plugin C that would handle those cases.


That is how I end up with runaway scripts, where every possible combination of scripts results in a new script being written to handle it (instead of just hardcoding conditions directly)
Maybe a compromise is in order.  I would make one script that has all the components, but allow the individual components to be turned on/ off and only worry about conditions that determine which ones are on/ off.  It would still be some work, but you wouldn't need conditions to determine if the other scripts were being used at least.  Plus since you can turn things on/ off you could still get the advantage of being able to test individual parts.
for my own engine I spare everything's in big Functions

and each function can be active and inactive 

but I have ONE big core who handle all the datas it's not modify every part it's just "collect all the datas" and put them in var (this.variable) so I can extract them by using inheritance ....let's show how works my  stuff '3'

Enigma.prototype.get_data = function() { this.k_actor_id = "futur data for actor id"; this.k_event_id = "futur event_id"; this.k_map_id = "futur_data for map_id"};it's handle the datas i

but if you check my  another function  "AWAKE"

Awake.prototype.get_data = function() { Enigma.prototype.get_data.call(this); this.range_x = 0; this.actor_range_x = 0; this. actor_range_y = 0; this.range_y = 0; this.multiplier = 0; this.trigger = null;};it's get the default datas  but also add new datas who can get  used by other function since we all know it's more easy to get datas in JS than Ruby '3'! 

I do think it's a good ways to not get forced to do everything's in ONE big function who can get less organised '3'

EDIT : if you find better ways for doing inheritance then show me ...this the only one I learned via a friend who showed me how to do lol)
I prefer if you take the time to learn the ins and outs of Javascript. Most people are writing javscript such that they import x from y; or they var className = require('./file_name')

You can write some very module code. For example:

 

var ClassName = { someFunctionName: function(param) { console.log('Hello ' + param); }};modules.export = ClassName;// Assume the above was saved in a file called 'class_name.js'.// In a new file, in the same directory lets import it and extend it using Underscore (for this example) you can use ES6 classes and its extend functionality but thats beyond the scope of this example.// Underscore Extend: http://underscorejs.org/#extendvar ClassName = require('./class_name');var NewClassName = _.extend(ClassName, { someOtherFunction: function(param) { console.log('I am happy about: ' + param); }, // Note the comma above. This is more of an "object" then a true class. But youll // see that we can use it like a "class" anotherFunction: function() { ... }});// Now we can do the following, in the same file:NewClass.someOtherFunction('RPG Maker MV'); // => I am happy about: RPG Maker MV// But wait theres more:NewClass.someFunctionName('World'); // => Hello World// We cant do:ClassName.anotherFunction(); // We don't know about this function its undefined.// But we do know about: ClassName.someFunctionName('Julius'); // Hello Julius The above example would require knowledge of modular design patterns either ES6 or Babel to compile what I just wrote you would also need to make sure that underscore JS was loaded above everything in order for the _.extend method to exist.

The above also shows how to write more modular and cleaner code. It also allows you to write components you can use else where.
I prefer if you take the time to learn the ins and outs of Javascript. Most people are writing javscript such that they import x from y; or they var className = require('./file_name')


You can write some very module code. For example:
While that is interesting to read, it's also besides the point.
I wasn't talking about program modules and reuse of code, but about game modules and work needed to make game functions optional.


If I write one plugin for adding new stats, and one plugin for adding new energy points - both will affect the status screen, and a third plugin for that screen would need to check "are the plugins for X and Y present? If yes change those parts or those parts".


That is more work than writing a single plugin adding both new options and rewriting the status screen to make both changes.


But if I do split the code over several plugins, that will make it easier for OTHER people (especially non-scripter) to use only part of the engine that I'm writing.


That is the modularity I was talking about - not how to make functions modular, because those other people will never even see the code.
While that is interesting to read, it's also besides the point.

I wasn't talking about program modules and reuse of code, but about game modules and work needed to make game functions optional.

If I write one plugin for adding new stats, and one plugin for adding new energy points - both will affect the status screen, and a third plugin for that screen would need to check "are the plugins for X and Y present? If yes change those parts or those parts".

That is more work than writing a single plugin adding both new options and rewriting the status screen to make both changes.

But if I do split the code over several plugins, that will make it easier for OTHER people (especially non-scripter) to use only part of the engine that I'm writing.

That is the modularity I was talking about - not how to make functions modular, because those other people will never even see the code.
You can split the configuration section for users as well.

This is not uncommon for plugin-based software to do so: you would design your API in such a way that you can

1. add new functionality separate from your "base" scripts

2. allow users to determine how that new functionality will be used

So for example, you have 3 scripts that add new stats using a standard status screen design of your choice. You would then allow users to choose the order that the stats will be displayed, or where they will appear, and so on.

Let's say you decided to store it in some arbitrary format:

<Stats List> <Stat name="atk" x="100" y="150"> <Stat name="Custom 1" x="100" y="200"> <Stat name="Custom 2" x="100" y="250"></Stats List>Users could then add/arrange new stats to that list, assuming they are defined (via plugins).If you look at the code for handling Effects or Features, they simply take a number and then map it to a method. You could then add your own codes and your own methods and now you've effectively created a plugin system.

This would be harder for you to write because depending on much flexibility you want to give to the user, you might be doing more work in the end.
While that is interesting to read, it's also besides the point.

I wasn't talking about program modules and reuse of code, but about game modules and work needed to make game functions optional.

If I write one plugin for adding new stats, and one plugin for adding new energy points - both will affect the status screen, and a third plugin for that screen would need to check "are the plugins for X and Y present? If yes change those parts or those parts".

That is more work than writing a single plugin adding both new options and rewriting the status screen to make both changes.

But if I do split the code over several plugins, that will make it easier for OTHER people (especially non-scripter) to use only part of the engine that I'm writing.

That is the modularity I was talking about - not how to make functions modular, because those other people will never even see the code.

you need the concept of immutable programming then. You essentially have a state in one "script" (I hate the word script in conjunction with javascript - regardless of if its in the name or not) that is only affected by the goings on in that script and one state in another.

I suspect that RPG Maker will make use of global variables.  You should not manipulate these, you should set them into some kind of state and then update that state when you need to. http://www.sitepoint.com/immutability-javascript/

This way you can have two scripts affecting the status screen and neither are affecting each other.

If you split the code over sever plugins you make it easier for your self to develop as you have reusable modules.
@Kalacious:


I already know several ways on how to do that (Master Degree in Computer Engineering), that isn't what I was asking for.


I wanted to hear opinions if I should do that or if the added work is not worth the flexibility for others, especially if the single components are from an engine that wouldn't be used separatedly often.


It's been a while since my last big program (worked more technical support instead of software programming) and I wanted opinions on how much more work does it take to make such modular sequences compared to making it a compact system.


@Tsukihime:


Yes, that would be one option - or something similiar to how LUNA Engine handles the screen design with config files instead of notetags.


But as you said, that is much more work. I think I need to make a grafical mockup of all planned additions and then check how they would fit the screen.


I would much more prefer to have the added components in fixed places and only activated by the presence of their function, but that would have the screen look strange if they're not present.


Unfortunately it looks like my choices will be to either go all-out for variable screens similiar to your idea, or to make a compact engine that has no optional parts.


Your idea is a lot more work, but it would also spread the plugins more. I'll have to think about that.


I think I'll wait until after I could see the MV code before deciding which way to go.
You can always compromise customizability.

Also, it's up to the devs themselves to figure out what looks good, so it would actually be less work on your part because once you write some code to read their config, the rest is up to them.

For example

Code:
<Stats List>  <Stat name="atk" x="100" y="150">  <Stat name="Custom 1" x="100" y="200">  <Stat name="Custom 2" x="100" y="250"></Stats List>
This allows users to choose where they want it to display
Code:
<Stats List>  <Stat name="atk">  <Stat name="Custom 1">  <Stat name="Custom 2"></Stats List>
This allows them to choose which ones they want to display, and in what order, but the positions are defined in the script.
"I already know several ways on how to do that (Master Degree in Computer Engineering), that isn't what I was asking for.

I wanted to hear opinions if I should do that or if the added work is not worth the flexibility for others, especially if the single components are from an engine that wouldn't be used separatedly often.

It's been a while since my last big program (worked more technical support instead of software programming) and I wanted opinions on how much more work does it take to make such modular sequences compared to making it a compact system."
If you want to throw your masters at my masters let do it. "Raises Masters for epic fight"

You should know by your masters how to write modular code then. Do not treat MV as a scripting platform, treat it as a platform  that is used to build smaller components on top of it.

Compact Systems are more harder to debug, they have there own issues where as modular systems are easier to test, debug and distribute and have components you can re-use, but a masters should know that ... right?
Compact Systems are more harder to debug, they have there own issues where as modular systems are easier to test, debug and distribute and have components you can re-use, but a masters should know that ... right?
I understand completely what you mean, and I only mentioned my occupation to proof that - and to explain to you that my question here has absolutely nothing to do with code modularity, I'm asking about game modularity.

Of course the engine will be written completely in modular code - but the question is whether or not I should add game and plugin modularity on top of that, because that is a lot more work.

The engine can use completely modular code (for my own use) internally, but still look to the user as a single plugin. Because in that case I won't make the internal code modularity available to the game developer but require the game developer to use the entire engine as provided.

Because to provide game modularity there is an entirely additional layer of configuration needed (as discussed with tsukihime above) that requires a lot more work. That work would be wasted if no one uses it.
I should add game and plugin modularity on top of that, because that is a lot more work.

Yes.

The engine can use completely modular code (for my own use) internally, but still look to the user as a single plugin. Because in that case I won't make the internal code modularity available to the game developer but require the game developer to use the entire engine as provided.

Because to provide game modularity there is an entirely additional layer of configuration needed (as discussed with tsukihime above) that requires a lot more work. That work would be wasted if no one uses it.

Its not wasted if you have learned something.

Either way think of in terms of a framework, the game system is a framework and any additional code while yes can take part in the framework, I would say make it framework agnostic. That is abstract what you can from the game platform.

Is it more work? yes. But it doesn't couple your code to the system thus making things harder to debug. Because if there is a game breaking issue you'll know weather its your code or the game code.

So to answer your question, yes make it "framework agnostic" as much as you can.
The engine can use completely modular code (for my own use) internally, but still look to the user as a single plugin. Because in that case I won't make the internal code modularity available to the game developer but require the game developer to use the entire engine as provided.


Because to provide game modularity there is an entirely additional layer of configuration needed (as discussed with tsukihime above) that requires a lot more work. That work would be wasted if no one uses it.
You could potentially offer two versions: one for advanced users, and others for regular users.
You could potentially offer two versions: one for advanced users, and others for regular users.
yes, but what brought this topic on are my time restrictions. I simply can't work on programming many hours - but that has reasons that are not for public discussion.
yes, but what brought this topic on are my time restrictions. I simply can't work on programming many hours - but that has reasons that are not for public discussion.
What I mean is, if you were going to build it modularly "internally", but then release it as a "single script", you'd already be doing a lot of work to maintain them?
What I mean is, if you were going to build it modularly "internally", but then release it as a "single script", you'd already be doing a lot of work to maintain them?

with the javascript scripts I plan to release this is what I will be doing, a minified version and a non minified version.
What I mean is, if you were going to build it modularly "internally", but then release it as a "single script", you'd already be doing a lot of work to maintain them?
Yes and no
I'll be using a lot of modularity and abstraction to make the changes - in fact I consider something like RM's engine not abstract enough, I prefer to work on a pure logic level while RM's engine still focuses on fixed assignments.


In a way, that's part of the problem - I learned in the past that a lot of people have problems following the abstraction level I prefer, and that means to make the code usable by others I'll need to add more descriptions and an interface, all of that is more work.


And I don't know if I have the time to give that level of support after (or if) I release those scripts.

Original thread: https://forums.rpgmakerweb.com/threads/programming-style-functional-modules-or-compact-engine.45656/