The point is, you shouldn’t have to think about what the name stands for. That could mean anything, L could be luck(), LI could be lineImpact(). A function that smoothly changes a value from a to b is called lerp (or linear interpolation). Always be as descriptive as you can with your variables.įunction names should let the programmer know what the function does before reading the code contained in it. This makes it hard to figure out what is going on even if you wrote it (especially when you have a large script with hundreds of variables). Let’s say you made a variable for how fast a part would move. Variable names are very important when you have not looked at a script in a while and you have to change something. Now the solution to this is quite simple the code is missing an end, but with more complex problems, your code being clean and readable is going to become more and more important. If hit.Parent:FindFirstChild("Humanoid") then Now there are more than one issue here (in terms of writing clean code) but just focus on the what will give you an error.ĭid you find it? Even if you did, try looking at this one to see the difference: If h.Parent:FindFirstChild("Humanoid") then For the messy version I want you to find the problem without running the code to get an error message. This will make it easier to see what code that block holds or debugging a simple problems such as missing closing parenthesis. Anytime you need to see when a block of code starts and ends, you should always use one TAB or about 8 spaces. Now, most modern code editors do this automatically, but sometimes they don’t always do it correctly (though it’s rare for a modern editor to make a mistake). Indentationįirst let’s talk about indentation. In the end, you have to create your own way of writing code in the best way that works for you. In this tutorial, I will be showing you how to write clean code, and improve your scripts aesthetics and readability.īefore I start showing how I write cleaner code, I want to say that everyone’s “style” is different. It also makes your scripts much more readable especially when your trying to debug a problem. Now, it may not seem that important to you, but I think it’s what shifts programming from a logical process, to an art. I see a lot of people writing messy code in their scripts, whether it’s a free model, a YouTube tutorial or a post here on the developer forum.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |