Lua Anti-Patterns Overview
Lua Anti-Patterns Overview
Global Variables by Default
Global Variables by Default
local
keyword when declaring variables. In Lua, variables are global by default, which can lead to unexpected behavior and name collisions.Not Using Modules
Not Using Modules
Using Tables Inefficiently
Using Tables Inefficiently
table.insert()
when you know the index in advance. This is more efficient, especially for large tables.String Concatenation in Loops
String Concatenation in Loops
..
operator. Instead, collect strings in a table and use table.concat()
at the end, which is much more efficient.Not Using Proper Error Handling
Not Using Proper Error Handling
nil
plus an error message on failure.Using Numeric For-Loops Incorrectly
Using Numeric For-Loops Incorrectly
Not Using Proper Scope
Not Using Proper Scope
Inefficient Table Clearing
Inefficient Table Clearing
nil
to actually clear a table.Not Using Metatables Appropriately
Not Using Metatables Appropriately
Using Inefficient Patterns for OOP
Using Inefficient Patterns for OOP
Not Using Proper Closures
Not Using Proper Closures
Not Using Proper Module Structure
Not Using Proper Module Structure
Using Unnecessary Upvalues
Using Unnecessary Upvalues
Not Using Proper Error Propagation
Not Using Proper Error Propagation
Using Inefficient Table Traversal
Using Inefficient Table Traversal
pairs()
for traversing hash tables and ipairs()
for traversing array-like tables. Don’t use the length operator (#
) for non-sequential tables.Not Using Proper Documentation
Not Using Proper Documentation
Not Using Proper Testing
Not Using Proper Testing
Using Inefficient Algorithms
Using Inefficient Algorithms
Not Using Proper Resource Management
Not Using Proper Resource Management
Not Using Proper Configuration Management
Not Using Proper Configuration Management