General tips #4
Replies: 1 comment 1 reply
-
|
Thank you for the feedback. It can definitely be challenging to recommend a specific way as the best when there are multiple options. I've mostly avoided recommendations unless I think there is a clear, best way; for either readability or performance reasons. There are a few places where I give more weak recommendations, because I believe in 90% of cases the recommendation may apply, but there are exceptions. I've addressed the specific feedback below:
This guide is meant for FiveM Lua, not necessarily other interpreters. I disagree with your assertion that people should know native Lua.
The performance was based on benchmarking here: https://springrts.com/wiki/Lua_Performance#TEST_5:_Nil_Checks_.28.27if.27_vs._.27or.27.29 Do you have a counter example of a nil check with a default value that would not work with ternary operators? I find the ternary form of default values perfectly readable. |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
First of all, it is nice to find something like this. It can be difficult to find the best way because everybody has different preferences.
This leads to different opinions.
For example :
https://github.com/Manason/effective-fivem-lua/blob/main/docs/natives.md#replace-string-hashes-with-backticks
People should be aware of what is the correct syntax in LUA and so what is the goal of your guide ?
Write correct LUA code or Write specific FIVEM code ?
In Lua, using backticks (``) for strings to represent a hash key is not a valid syntax in Lua.
Same goes for the "ternary operator" (yes it is quoted because LUA does not have real ternary operators)
Your examples are valid and true for simple checks. But be aware if you start using 'and' + 'or'. The way LUA handles this stuff is not how you think it will work. You could use anonymous functions but writing the if else would be more readable.
NOTE : Both examples have similar performance.
Beta Was this translation helpful? Give feedback.
All reactions