Tips/Methoods i can simplify my code overall?

Hi, i’m curious if i can find any methoods of how to find new ways to make my code better and more efficent, i wan’t tips, but i wan’t a methood to find new ways of making code shorter/simplier and more efficent. I told i can use modulo, i have to think twice if i wan’t to add something or to not make something that i don’t need.

I’ll be very happy if i get tips on how to improve my code

2 Likes

You can use module script with community modules. You can use oop in modules (orriented object progamming), there are some tuto out there, I found this: Unleasing the power of Object-Oriented Programming | OOP

1 Like

i know OOP can help read my code, but more i’m keen on simplifying it, for example how to make something the best as it can be

then you should use a lot of community modules. For example, red, garbage, zoneplus…

1 Like

but what about simplyfying my code, i can’t use module for everything, for my own system that are mine and works different, i mean, i wan’t something like what i can choose to make my code faster, like methood or function or something like this? how i can improve loops or optimization of my code?

Maybe send a snippet of the code you want to know how to optimise and then we can give tips.

2 Likes

i wan’t to know how to optimize overall, for future projects, i wan’t simple tips that can slighty improve my code like what to use, this is what i wan’t

1 Like

Can you give an example?

A simple tip that applies everywhere is using

task.wait() 

instead of

wait()
1 Like

hmm, i know that, but why? is task more optimized or something?

1 Like

And example, yea, soo for example if i need to use a lot of statements, can i improve that? i know i can simply think what statement is needed, but i wan’t more ways to simplify loops,statements and tables - those are my problems, i often use for in loop to check through tables with if statements

2 Likes

I’m not exactly sure, but I know it is faster than the normal wait() function.

1 Like

To make your code better, try to decouple things and give everything a single responsibility. This helps you know where to look when things go wrong. A modular approach to design also lets you put things in and remove them quickly which can help. Note that simple and short aren’t synonymous. Often the simple code is longer. Short code can be harder to read and therefore harder to change when you need to. Not always of course, but prefer readability over compactness.

As for speed. There are 2 ways to speed up your code in general. Either make it do work faster, or make it do less work. For the most part you will be doing the second. Remove anything unnecessary, or allow it to carry out long processes over longer periods of time. This reduces the workload for any given instance allowing more performant code overall.

As for modulo, it just does a division, but gives you the remainder instead. It can be useful in certain applications like number % 2 will let you be able to tell if the number is even or odd because an even number will have a remainder of 0 and an odd a remainder of 1. It is super useful in certain use cases and worth learning, but it probably won’t noticeably make your code faster in most cases. It might make it more readable though since modulo is frequently used by developers.

As for thinking twice about adding something, if you don’t need it, don’t add it until you actually do need it. It’s very easy to over engineer things. But feel free to experiment with things as the extra experience can help you better understand your problem and whatever solutions you are attempting.

If you want more structured code, you can look into “design patterns” which can give you an idea of common ways to structure code to solve specific problems that are generally maintainable

The question was a bit open ended, hopefully I gave you some ideas.

1 Like

yea, it’s nice, soo i have to simply, write and look what i can make better, this is great, thank you!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.