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
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?
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
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
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.