Best Practices Handbook

A meme.
image
It’s not a bad method to use, but it’s surely laughable. (that being said im using it haha)

17 Likes

Can you explain this a little bit more for beginners? The announcement may be hard to understand for some. (edit: all you really need to do is give a mini explanation on why, or people are gonna keep doing it anyway)

1 Like

Yea good point, I’ll update that section in a bit.

1 Like

Wouldnt it be spelled “camelCase”?

Super neat handbook, tysm

1 Like

Good catch, I’ll fix that. I dont want to be using incorrect camal casing in my camal case section :blush:

1 Like

You should also teach about :Once() instead of just Connect and Disconnections.

2 Likes

Oh yea, I remember thinking about that last night. Although I must have fell asleep before writing it. I’ll add it now.

2 Likes

A few notes I’d like to say, this isn’t meant to be negative but just to add information so the community has as much information as we can pool as a collective :slight_smile:


camelCase has been phased out in the in-engine API in favour for PascalCase, Destroy not destroy and so forth, code which has public methods should ideally be using PascalCase for those methods for consistency with the engine itself


It would also be nice to add information about assert as a way to add guard clauses, baring in mind that if the first argument is false or nil, it will throw the second argument as an error

assert(game.Workspace:FindFirstChild("Baseplate"), "Baseplate does not exist.")

I 100% agree with this, perhaps an inclusion of the basics of how the self keyword works, especially since you use it in the returnCoolString function and might confuse a few people haha


Hopefully these few extras might help even just a handful of people

6 Likes

This is definitely useful information, I’ll probably edit this post tomorrow to include some of these ideas.

1 Like

There’s hardly an agreement on camel case being the standard, and either way it’s usually used in conjunction with pascal case and sometimes snake case (especially upper case for constants) depending on the specific thing you’re naming. Like is it protected, private, public? Is it a function? Is it a class? Is it a constant? Is it a file? Etc etc. The standard widely varies by programming language, and then of course projects and libraries within that language too.

The segment on functional programming is a bit far off too. Functional programming is quite a bit more complex and pretty hard to explain, it also varies a lot depending on who you ask.

If were talking about pure functional programming, which is often what people refer to these days when they use the term, it’s mainly about minimizing side effects and making functions deterministic. E.g if you call a function with the same argument, it will return the same thing every time. Usually when we program there’s lots of times this doesn’t happen, for example if we use the value of the clock inside of the function to decide something, or a math.random().

As for other “rules”, there’s a lot of people who are big on what you kinda mentioned, which is not updating data. So instead of changing data, they favor creating a new data structure to contain that data when performing some sort of operation with it. Recursions are also seen as the go to over loops. Which obviously stems from the whole mathematical origin of functions. And then of course functions can be passed to other functions, returned, or assigned to variables, etc.

Now people often think that if you use some programming paradigm, that has to be the only programming paradigm that you use. That obviously makes zero sense, there’s strengths and weaknesses of OOP and functional programming, and nothing that prevents you from using them or other paradigms in the same project or even together in the same bits of code. For example recursion can be pretty sweet sometimes, but it can also be memory intensive as shit and fill up the call stack to the point of crashing ur program.

There’s also no one set of rules for any paradigm, most of them have at least one or several “sub paradigms”.

3 Likes

I’m glad I didn’t get lazy reading this because I just discovered the use of Knit Framework. I can now develop without messing with Remotes and stuff.

2 Likes

actually i got better idea on Services metatable thing

here:

local Services = setmetatable({},{
    __index = function(self, ind)
        if pcall(function() game:GetService(ind) end) then
            rawset(self,ind,game:GetService(ind))
            return game:GetService(ind)
        end
    end
})

I know i added just only one line of code

but then __index wont need to be called a milion times instead the service gets cached

I find that it’s a lot easier to code a tough feature while I’m working in that one particular module in the moment. Then when I want to use it somewhere else, I already have that feature made, so I don’t need to worry about coding it. It gives me creative freedom as I don’t need to stop what I’m doing to code this thing, which will bore me. For me, this is usually done by trying to keep private methods public for more flexibility.

Later, if I notice that I never used it, then I’d delete it. Or if I try to use it and it doesn’t work, I end up removing it unless it’s a simple fix!

Kind of like this:

There’s more to this, though. If you fixed a bug by using task.wait(), than it’s unreliable. A simple wait should not fix any problem. It’s better to understand precisely what is causing the issue by debugging. That’d be much more optimized, faster, and of course reliable!

I love templates too!

:fearful:

Image

Too bad! This way is prettier! :smiling_imp:
Even ForeverHD does this (TopbarPlus), but that’s not why I do.
Not going to argue about this! It has worked for me literally forever (apart from very rare cases where I use ReplicatedFirst)! :innocent:

1 Like

These are all great tips! I prefer to use PascalCase for function names, but that’s just personal preference.

3 Likes

fair, fair, that may be better

Not sure if I understood what you were trying to get at here. If you could rephrase this that would be great. Again, these are practices that are widely used across professional environments. I can’t dictate whether you like them or not.

This topic isn’t just about making certain aspects of code “prettier.” It’s mostly about the most optimal solutions. If you don’t want to use GetService, that’s not my problem.

I’m not sure if I understand what you’re saying here. I never said you should resort to using waits for fixing bugs. I said to use task.wait() instead of wait()

However, I like the choice of emojis in your reply.

2 Likes

https://roblox.github.io/lua-style-guide/#naming

3 Likes

Read the OP, it talks about a general standard across the programming world. Not in Roblox or Lua/luau. Besides this doesn’t name camel case as THE standard, it outlines several standards depending on what you’re naming.

Lastly, this is not an official or widely referenced thing so I’m unsure what your point even is?

He means for Roblox generally. camelCase is recommended for variables and functions while PascalCase is recommended for module names and methods.

He means for Roblox generally. camelCase is recommended for variables and functions while PascalCase is recommended for module names and methods.

There are numerous different naming conventions. However, camalCase is widely recognized as the generally accepted convention across the programming world.

Amazing you think he means roblox generally when that’s quite literally not what he says. And again, even in Roblox it’s not that simple. Constants are a variable, local and global variables are also obviously variables. Yet a different style is commonly used when naming each of the three.