Neatness tips...

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Le_juiceBOX
Citizen
Posts: 71
Joined: Sat Mar 26, 2016 3:07 pm

Neatness tips...

Post by Le_juiceBOX »

Hey, I was wondering if you guys can give me some tips on how to write cleaner code and some personal things you do to make things easier for you.

Thanks. :awesome:
SteamLibrary-like Program For Love2D Games:
take me to the forum thread!
bonez001
Prole
Posts: 36
Joined: Wed Sep 14, 2016 8:14 am

Re: Neatness tips...

Post by bonez001 »

Learn to use modules and local variables for bigger project. I'm still a beginner but that is what I observe.
Zireael
Party member
Posts: 139
Joined: Fri Sep 02, 2016 10:52 am

Re: Neatness tips...

Post by Zireael »

Use modules and classes and inheritance. And local variables.

A simple library that implements 1,2 and 3 is https://github.com/kikito/middleclass
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Neatness tips...

Post by s-ol »

separate concerns properly, indent properly, try to hit the balance between explicit/readable and performant/short.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Neatness tips...

Post by kikito »

Invest time thinking about the names you give to things.

5 minutes spent finding a meaningful name for a variable can save tens of hours of head-scratching in the future.

The best resource I know for finding good names for variables is chapter 2 of the Clean Code book. You can read it for free on Google Books (the whole book is a good read, but that chapter in particular is great).
When I write def I mean function.
Zireael
Party member
Posts: 139
Joined: Fri Sep 02, 2016 10:52 am

Re: Neatness tips...

Post by Zireael »

kikito wrote:Invest time thinking about the names you give to things.

5 minutes spent finding a meaningful name for a variable can save tens of hours of head-scratching in the future.

The best resource I know for finding good names for variables is chapter 2 of the Clean Code book. You can read it for free on Google Books (the whole book is a good read, but that chapter in particular is great).
Oh yeah, this. Will give the book a read, but I have a notes file devoted to hierachy only, i.e. class/module Spawn places stuff in my game world, therefore it needs to require Actor, Object and Player. If I want to place something, the Area class needs to call Spawn. That sort of thing. Conceptualizing it before coding really helps!
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 3 guests