How to write clean code

it really just boils down to personal preference. What kind of casing you use (camelCase, PascalCase), Variable naming schemes (abbr, full name) Programming type (OOP) What language you use (Python, Lua) really all of it is just personal preference. if you like something better than use it. If you don’t like something then just don’t do it.

of course, but still many use it as exit statement soo it’s nice to teach about standarts

1 Like

perfect tutorial of how to chat gpt’ify your code

I didn’t used chat gpt, i used my experience and this is only showcase to understand simple techniques, they should be applied on bigger scales like in frameworks or systems, but for beginners i made tutorial on touched event which is practically most known for lava brick tutorials and ect.

i think this is a pretty useful tutorial for beginners, personally, i try to keep my code within the script editor space so i don’t have to use the horizontal scrollbar, which makes it easier to view my code.

(just a small thing but you could store the player in the debounce table instead of 0.)

Exploiters do not have access to your original code, only the bytecode. Which can only be used to reconstruct something resembling your script. Type annotations, most variable names, and all formatting is lost. Cleaner code wont help them develop any faster than normal.

it’s faster to index due to some lua stuff, soo it’s natural that calling table.find will be worse, it’s common practice to do this

I thought those programs to read scripts are more powerfull, still nice to know

Honestly, that code is actually harder to read due to the lack of indentation. (and the extremely high amount of useless comments)
Personally i find having lots of indentations easier to read since i can remember what parts do what according to the number of indents aswell as seeing what statements are dependent on what other statements. My number of indents ona signle line sometimes reach well above 5 and i dont see anything wrong with it

That is understandable, but do note that the comments are purely there for people on the DevForum to understand it and are giving feedback on some other things.

2 Likes

If you need to write comments your code is not clean. Your code should comment itself

depends, sometimes you can describe very advanced functions or create sections

-- Get all cells in grid, Check if they are near player, Render them then
local function RenderChunks()
    -- code
end
-- Settings
local UseBullets = true
local UseRaycasts = true
local IsPenetrationDamageEnabled = false
local DefaultMultiplier = 2

-- Modules
local Bullet = require(script.Bullet)
local Sight = require(script.Sight)
local Barrel = require(script.Barrel)

-- Self
local Gun = {}
Gun.__index = Gun

... Code ...

It does not depend at all. Even for a math function where comments could be justified, I found it was trivial to just make it readable with proper descriptive variable and function names

I primarily use comments to explain why something is there, and not what it does (unless it’s unclear what it does). Overcommenting leads to clutter, just balance your code readability and the comments. I agree that you should have descriptive variable and function names, once I named a function TryCallbackWithExponentialBackoff (Try means it can fail, ExponentialBackoff just means it will wait exponentially between errors) - sure it’s more verbose, but don’t you have autocomplete and intellisense?

1 Like

Roblox has a Lua style guide. It provides an in depth guide from the file structure to best practices. I highly recommend you guys check this one out.

1 Like

Oh alright then, do you know how much of a performance impact indexing it with the player would be though? just wondering.

I understand but everyone is different, comments are usefull for some people, personally i use them in sections or in function descriptions, reading comment is faster than analyzing code, soo still it depends

From what i remember micro-seconds, but still it’s something for soo, it’s good practice to consider when working only when value is important and there is also only one possible type of it (there can’t be 2 players with same name)

1 Like

Thanks