Its one thing to bodge together something small with trial and error with banging my head against the lua api ; it's quite another to take on a major project with some semblance of sanity 3 minutes into it.
Anyone got anything worth reading on how to do the latter?
Whats a good resource for writing "good" lua code?
Re: Whats a good resource for writing "good" lua code?
Most of it comes from practice and somewhat personal preference. (I for one like to Camelcase modules)
Other than that, Kikito has a nice website with a few things about writing proper code. check it out here: http://kiki.to/
Other than that, Kikito has a nice website with a few things about writing proper code. check it out here: http://kiki.to/
- jojomickymack
- Prole
- Posts: 45
- Joined: Tue Dec 26, 2017 4:52 pm
Re: Whats a good resource for writing "good" lua code?
This is probably known by everyone here already, but the PIL (programming in lua) book is free online and highly relevant. Also, why not buy a copy and support the lua project? - http://www.lua.org/donations.html
http://www.lua.org/pil/contents.html
Chapter 16 and 17 contains the most important part of what 'good lua' consists of - and I see the pattern below verbatim in lua source code.
don't be afraid of setmetatable or __index - it's the key to lua's prototype model - definitely worth memorizing. If that snippit makes sense to you, you're a "good lua coder".
http://www.lua.org/pil/contents.html
Chapter 16 and 17 contains the most important part of what 'good lua' consists of - and I see the pattern below verbatim in lua source code.
Code: Select all
function Account:new (o)
o = o or {} -- create object if user does not provide one
setmetatable(o, self)
self.__index = self
return o
end
Re: Whats a good resource for writing "good" lua code?
luacheck is a tool for linting and static analysis of Lua code. While it won't check the aestetics of your code, it can check that you don't use global variables, don't shadow variables, and several more useful options. It is really handy.
Re: Whats a good resource for writing "good" lua code?
Separate game logic from the view code for major projects. Use busted and try your hand at test-driven development. Your brain will thank you when your major project doesn't resemble a bowl of spaghetti.
Re: Whats a good resource for writing "good" lua code?
In my basic understanding, I break what we do down into two categories: proficiency in the language and design patterns.
These two things are frequently mutually exclusive as a design pattern can be applied in many languages.
On that note: I find there is plenty of information on language proficiency, not so much on patterns. As a novice myself, I find my shortcomings are unrelated to language proficiency and more to do with design patterns (where I think the gold is). I keep two reference books always on hand (besides Programming in Lua): Design Patterns: Elements of Reusable Object-Oriented Software and the more recent Game Programming Patterns.
This answered many of my 'how' questions. Too many tutorials will focus on how to draw a box or write 'hello world', not how to write an observer/listener command system (example). And let's face it, there are some great tutorials on YouTube but most are quite terrible. However, those books are organized and will teach you about how to organize your software and some industry standards instead of having to reinvent the wheel.
Hope this helps!
These two things are frequently mutually exclusive as a design pattern can be applied in many languages.
On that note: I find there is plenty of information on language proficiency, not so much on patterns. As a novice myself, I find my shortcomings are unrelated to language proficiency and more to do with design patterns (where I think the gold is). I keep two reference books always on hand (besides Programming in Lua): Design Patterns: Elements of Reusable Object-Oriented Software and the more recent Game Programming Patterns.
This answered many of my 'how' questions. Too many tutorials will focus on how to draw a box or write 'hello world', not how to write an observer/listener command system (example). And let's face it, there are some great tutorials on YouTube but most are quite terrible. However, those books are organized and will teach you about how to organize your software and some industry standards instead of having to reinvent the wheel.
Hope this helps!
- Roland_Yonaba
- Inner party member
- Posts: 1563
- Joined: Tue Jun 21, 2011 6:08 pm
- Location: Ouagadougou (Burkina Faso)
- Contact:
Re: Whats a good resource for writing "good" lua code?
I believe the Lua Style Guide might be a good reference here. Olivine-Labs also shared their own Lua Style Guide. Both of them are not meant to be authorative, but they both present good habits and idioms which are commonly adopted by the Lua community.
Who is online
Users browsing this forum: No registered users and 5 guests