#What is the best way to prevent spaghetti code before it begins?
1 messages · Page 1 of 1 (latest)
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.
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.
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
i need to do this more often - i used to rush the variables out like this
local event = game.ReplicatedStorage.Events.eventname
instead of
--Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--...
--Events
local Event = ReplicatedStorage.Events.eventname
I write my code in a way that is self explanatory and try to avoid comments unless its something kinda complex
i still dont follow my advice very often
i write code to be as rushed as possible if it works ill label later -probably dont do that
it doesnt take tons of time just take 1 extra second to think
ur always working with ur past and current self
even when a solo dev
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