Is it okay to use snake_case in Luau?

I used to program a lot in PascalCase and camelCase, however, recently I started learning Rust and my opinion changed on which naming convention I use. This is because I often find snake_case much more pleasant to look at when working with names that have similar characters.

stdDeviation

VS

std_deviation

I am wondering if it would be okay for me to use snake_case naming convention for public modules that I own, because the naming convention on Roblox is mostly camelCase and a bit of PascalCase, and some people might find it annoying to have snake_case in their camelCase codebase.

Previous naming convention
--!strict

local Dog = {}
Dog.__index = Dog

type Dog = {
	Name: string,
	NumberOfLegs: number
}

function Dog.new(name: string)
	local self = setmetatable({} :: Dog, Dog)
	
	self.Name = name
	
	return self
end

return Dog
Suggested naming convention
--!strict

local Dog = {}
Dog.__index = Dog

type Dog = {
	name: string,
	number_of_legs: number
}

function Dog.new(name: string)
	local self = setmetatable({} :: Dog, Dog)
	
	self.name = name
	
	return self
end

return Dog

There’s not really a difference. It’s completely how you script, and that’s fine. It won’t affect the performance of the script at all and isn’t a bad practice, it’s just that not many of us use it ourselves.

I am aware of that.

This is what I asking about since I don’t want people pointing out that they don’t like my module simply because it uses snake_case.

Seems good to me. If people don’t like the way you code that much then they don’t deserve to use your code :eyes:

As long as it is performant and documented, I do not think anyone will mind.

2 Likes

I was simply saying that it isn’t a problem to use snake_case, it is simply a preference and anyone that finds your code annoying finds it annoying. It’s how you code, they can’t control that, and nor should it be a problem for anyone.

1 Like

According to their style guide, you should use camelCase for local variables and PascalCase for Class and Enum like objects (this includes Roblox services)

I personally find that a consistent programming format helps make code easier to read for everyone, but again as long as you follow the rest of a codebase you should be alright

So I am assuming that this example should look like this according to Roblox’s style guide?

--!strict

local Dog = {}
Dog.__index = Dog

type Dog = {
	name: string,
	numberOfLegs: number
}

function Dog.new(name: string)
	local self = setmetatable({} :: Dog, Dog)
	
	self.name = name
	
	return self
end

return Dog
local Dog = require(script.Dog)

local ben = Dog.new("Ben")

Yeah, as far as I’m aware this would be correct

1 Like

basicly from what i see, Luau follows JavaScript / ECMAScript conventions - i.e. camelCase for locals, PascalCase for globals/class/interface names and SNAKE_CASE_CAPITALIZED for constants and/or magic numbers