4thAxis' Luau Style Guide: For anyone who is trying to improve their readability and consistency or just want enlightenment

First and foremost before we get started please remember-- this is not the official style guide of Lua or Luau.

The purpose of following a style guide is to keep consistent and clean code. You may choose to follow or take inspiration or if you’re not here to learn about style practices, you may simply read this for enlightenment. This guide assumes you have a general understanding of Luau. This guide also goes into depth into why you should follow such practices. The goal of this style guide is to promote styles that respect the modified LSP of Lua 5.1 external Luau-like analysis that is also in regards to developer ergonomics. This guide values styles that promote readability and in a language that is being constantly optimized-- the era of focusing on performance over readability is slowly coming to an end.

This guide at the moment does not support static type checking.

Please feel free to share your opinions or correct me if I have worded or explained something weirdly. I will try to update the guide more when possible.

31 Likes

I read over the guidelines and I like it! I will be using this for upcoming projects. :+1:

I must say, this is an incredible document. What you’ve presented here is a treasure for anybody who wants to improve the quality of their code.

All hail the 4th Axis!

Thanks for the feedback! :grinning_face_with_smiling_eyes:

Comments should be kept minimum, provide comments only when needed.

What?

Comments are vital for documenting your code and the thought process behind it. I would agree that superfluous or unhelpful comments do hinder readability, but that’s not a reason to avoid them; you should instead strive to write meaningful comments that primarily address why something is being done, as opposed to what is being done.

Refer to Roblox’s official style guide on comments.

9 Likes

To add on to this. Comments also turn to whitespace (iirc) when your script runs, so they really won’t affect your code much, if at all.

3 Likes

This was a matter of readability, not micro performance optimizations. But good to know.

I can see how the first sentence of their explanation is misleading because comments are definitely a vital part of your scripts. But I believe the author was trying to say that comments should only be used when they are absolutely necessary, or basically don’t use comments if they aren’t needed. I would say it is fine to have documentation and even comment headers for functions, but the author is trying to say that if the code is already obvious you don’t have to go in to depth about what each and every thing does.

6 Likes

That’s fair if so, but that section definitely needs rewording if that’s the case - it’s too vague about how exactly comments should be written, and where they should be applied, which is why I got the impression I did.

1 Like

To begin with, readability is already a subjective matter however I can only share my opinions and thoughts with you. A comment may be used to amplify the importance of something that may otherwise seem inconsequential-- but this is how far it should really go. Personally having to write up comments is like an excuse for how unreadable your code is. I do agree with coming up with meaningful comments as long as these are very direct and compact comments that don’t clutter your code up. Authors, as mentioned in the guide, also agree on this matter. Although it may seem I have worded or not have addressed this clearly, thanks for commenting.

Thanks to @JonData for clearing this up!

1 Like

Fair enough - that makes more sense! Thanks :slightly_smiling_face:

(I still don’t 100% agree, but your position is definitely a lot more reasonable than I first thought. I’ll leave my thoughts for another topic so as not to derail this one)

1 Like

Although commenting needs to be kept minimal, during the workflow before the product would not be necessary. I usually employ a strategy of commenting while the product is in work and then throwing the comments together if necessary or erasing them entirely. This helps tracking your previous work’s end. Most comments I use aren’t intended for others and the final product’s comments are often rearranged properly or removed if not sustainable.

It looks very similar to the official Lua style guide by ROBLOX. I think that especially the CONSTANT and Class:_PrivateFunction() conventions are really neat. The main reason why I like this guide is that it does not look overcomplicated (too many comments and too much obsolete styling).

1 Like