Which one do you use?

Originally, I put this into the development discussion category. But then a moderator came along and told me to put it in this category instead. Even though it doesn’t really make sense why because I don’t want support or whatever as it’s just a general question. But yeah, which one do you use usually?

if cheese == 1 then -- Approved
print("bruh")
end

if cheese == 2 then print("WE GETTING DOWN TONIGHT BRO") end -- Not approved

I decided to continue the topic because I was enjoying the discussion but the mods closed it :frowning:

3 Likes

I personally use this one because it’s much easier to read and works with my eyes.

The second one I only use realy like if i’m doing short statements. Or i’m using the command bar line. I hate using that command bar.

2 Likes

rly much depends.
if its something like return, break or continue then i use one line.
if there is more code to it then i make a new a new line

2 Likes

For me, it depends mostly on the length

if cheese == 1 then
print("bruh")
A=true
B=1283712
end

But if it is just one thing, then one line is fine.

if cheese == 1 then return end
--or
if cheese == 1 then B=1923 end
2 Likes

In my opinion, at the end of the day it’s all preference and the only important thing is that you’re consistent with your convention.

The only real benefit I can think of (and it’s minor at that) is that if you use some type of code review system, using separate lines makes it easier to read diffs since it’s immediately known what changes you’re making.

2 Likes

If I am only doing one thing in the if statement I do it all on one line like:

if not chedder then return end

Cause after all theres no need to make this take up 3 lines.

2 Likes

Normally, whenever you’d like to break a loop;

if bool.Value == true then break end

doing one thing in the same line, you get the point.

if not bool.Value == true then bool.Value = true end

Generally because it’s faster, although putting it in a longer manner

if requestResult == true then
	print(requestResult)
end

turns out easier to read and more organized, although It’d take more space in your program. There’s no right or wrongs here, both are good to use based on the context you’re applying them to. I’d just avoid putting something that’s over 5 lines long in one line.

In my opinion though, this sort of creates the same problem the command bar line has. It’s alot harder to read and use if it’s that long in one line. That’s why I pretty much only use it for short statements. Not trying to attack your way of scripting, we all script differently. I’m just stating my opinion. I see where you’re coming from.

yeah, no. they just hire random people on contract who have zero business working in a forum of developers

I do the second one if the line of code is super short.

if foo then return end; -- like this

if foo then print("yep") return end; -- also this

if foo then humanoid.kill return end; -- this too

It would be easier to read and it’s a lot more convenient to me rather than taking up several lines just for simple code.

i always use the first one except for one line commanda like break return continue…

I always drop the line. I don’t honestly know why though. Maybe I just think it looks bad or something the other way. :person_shrugging:
Considering converting :thinking:

I use both of them but I definitely like to use the second one. I try to nest as little as possible so I have quick conditionals to eliminate bad arguments or incompatibilities.

Practically speaking, the one-liners are perfectly fine, and there is no real effect on performance.
However, I personally prefer the if statements to be broken up into multiple lines for readability.

If you want to stick with the one-liners, you may want to look into Ternary Expressions:

if the code is short then i do with the second one. i dont see a reason to expand by 2 more lines

1 Like

I didn’t know this was a thing. In one project, I used the and or ternary operators like this:

I say you should always use this one. Only excuse can be:
local x = if y then false else true
on some cases which you cannot fix with and, or. If block still valid but will add more than 3 lines for a simple thing. Multiple statements per line can get bad very fast.

While I agree multiple statements per line aren’t great, it’s more clear when you use number two sometimes and it helps to eliminate errors before they exist.
An example of this:

game:GetService("UserInputService").InputBegan:Connect(function(input, gpe)
       if gpe then return end
       --Now, you know gpe is false and the input is good to be processed normally, so you can eliminate this as a possible cause of issues/errors.
end)