#What is the best way to prevent spaghetti code before it begins?

1 messages · Page 1 of 1 (latest)

tropic locust
#

I am a good way into learning how to use Luau in roblox studio and want to prevent my games from becoming a buggy mess that I can't deal with because of spaghetti code!

What are stratagies you or other people have used to prevent this

winged crescent
#

Its usally a good way to use a lot of ModuleScript with function such setter/getter, and also im sometimes make spaghetti code, but for testing phase, if im satisfify with the code, that its working, i usally try to put in modulescript, if that type doesn't fit there, then usally i put then im function, since i can declear the name, what it does. instead inside whole events or so.

sick herald
#

Use comments, even if you think their not helpful they will come to help you in the future if you forget why you used something.

Make categories, use this as an example:

--{{ Service's }}--
-- < Your service here.
--{{ Variables }}--
-- < All the variables here, and stuff like functions under.

Try to use the Roblox Forums for all the help you need, check the Documentations that Roblox provides for everything you do, such as lets say you want to understand the Mouse function then check what it is used for what you can be better fixed

Use modules for big scripts so your code stays organized.

Explains the things you can create on Roblox.

scarlet flame
#

tbh i have no idea, apparently according to some people (better coders than me) say that trying to create a structure too early on can lead to more issues in the future so its best to start building your project get it working first with spaghetti code and when u see patterns such as multiple items using the exact same code over and over then start fixing it. i read once on reddit that theres no such thing as perfect way to structure code - good code is code that you can easily delete and rewrite because no matter what you do you will always end up rewriting it

i like to preference first - i only been scripting for 6-7 months and i am only repeating words from OTHER people

scarlet flame
spice lichen
#

i still dont follow my advice very often

scarlet flame
spice lichen
#

ur always working with ur past and current self

#

even when a solo dev

scarlet flame
#

spaghetti code is easier to read compared to 'well written code' - spaghetti code is mostly sequencial while constantly switching between modulescripts and scrolling down to the bottom of the page to see where the functions actually get called can actually make it feel harder to read

#

tho i am actually pretty dumb so this might not apply to everyone