Lua Indenting and utilities and graphs

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
bartoleo
Party member
Posts: 118
Joined: Wed Jul 14, 2010 10:57 am
Location: Savigliano

Lua Indenting and utilities and graphs

Post by bartoleo »

Hi,
I'm new to Lua-World...
I was looking for some utility (external... not and ide-function) to reformat/reindent Lua code files...

I made the utility ... posted all in a new thread...[url]ttp://love2d.org/forums/viewtopic.php?f=3&t=2035[/url]
Last edited by bartoleo on Wed Oct 27, 2010 11:10 am, edited 2 times in total.
Bartoleo
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Lua Indenting and utilities

Post by Robin »

General questions like this are probably better asked on Stack Overflow.
Help us help you: attach a .love.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Lua Indenting and utilities

Post by kikito »

I don't agree.

This is the "General discussion about LÖVE, Lua, game development, puns, and unicorns", isn't it? The question is valid on my eyes.

(But hey, probably posting the question on both sites is a good idea)

Coming back to the question at hand:

Utilities that "reformat/reindent" code are usually called code beautifiers. Sometimes they are called prettifiers and I've also seen some rare cases where they called them tabifiers

I don't know of any lua-specific beautifier, and I don't think there is any (too specific).

However, Lua's syntax is actually pretty similar to other scripted languages, like ruby or python. You can probably google for "beautifier prettifier tabifier ruby python", and find some tools there. If you feed them some lua code, chances are that the resulting code will be quite good.
When I write def I mean function.
User avatar
Thursdaybloom
Citizen
Posts: 81
Joined: Mon Feb 15, 2010 3:43 am
Location: Australia

Re: Lua Indenting and utilities

Post by Thursdaybloom »

kikito wrote:Utilities that "reformat/reindent" code are usually called code beautifiers. Sometimes they are called prettifiers and I've also seen some rare cases where they called them tabifiers.
I've never heard of such a thing! Are you telling me that the time I've spent making my code aesthetically delicious has been wasted??
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Lua Indenting and utilities

Post by kikito »

Not at all. Doing it manually has lots of advantages.

The other day I was reading Coders at Work and one of the guys there said it better than I could. (From the top of my head, not verbatim):
The first thing I do when I have to study some code that I didn't write is clean up the code. I tabify it all, manually. Then I start put some comments here and there. Renaming variables, etc. When I'm renaming functions I know how more or less everything works. But the first step is tabifying. It forces me to read the code more than once, and it forces me to stay longer on the uglier code.
Making your code reasonably indented is a discipline, and every programmer should practice it. Much like giving proper names to variables and functions.
When I write def I mean function.
User avatar
bartoleo
Party member
Posts: 118
Joined: Wed Jul 14, 2010 10:57 am
Location: Savigliano

Re: Lua Indenting and utilities

Post by bartoleo »

I agree with you all... I Try to code indented
But sometimes, it's better having 'identical' indenting on all code , so an utility could be a good solucion
I tried this:
UniversalIndentGUI
http://universalindent.sourceforge.net/
but I think that it doesn't indent lua (it highlights syntax)

In java I use the reformatter of Eclipse... and others 'small' but very good utilities like LINT...
Bartoleo
User avatar
walesmd
Prole
Posts: 22
Joined: Fri Oct 08, 2010 3:11 am
Location: Augusta, GA
Contact:

Re: Lua Indenting and utilities

Post by walesmd »

Not at all. Doing it manually has lots of advantages.
Zed Shaw has a quote in his most recent book Learn Python the Hard Way that gets around to the same point as well. To paraphrase:
Manually type the code examples in this book, don't copy in paste. By having to type the code you will "learn" the physical aspects of programming and be able to much more quickly identify syntax errors because you will "feel" the error before you see it.
User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: Lua Indenting and utilities

Post by zac352 »

Wait what? A code prettifier? How does that work?
edit: Oh. They rename variables, fix up comments, and they tabify everything.
I do that manually, though automatic indentation and word completion are (most of the time) helpful. :|
Hello, I am not dead.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Lua Indenting and utilities

Post by kikito »

walesmd wrote: "feel" the error before you see it.
I had totally forgotten about that one, and it is utterly important.

Countless times I've spotted bugs just by being disciplined with my tabbing.
When I write def I mean function.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Lua Indenting and utilities

Post by Robin »

kikito wrote:I don't agree.

This is the "General discussion about LÖVE, Lua, game development, puns, and unicorns", isn't it? The question is valid on my eyes.
Yes, the question is valid, I just thought this is the kind of question that is especially suited for the people at SO.

Anyway, back to the issue at hand: I'd say that if reading ugly code makes you feel hurt and/or dirty, you're probably on the right way to becoming a great programmer. It might be interesting to compare the output of a prettifier with manually indented and formatted code, to look for differences, although the problem with that is that everyone (every programmer, every project) has their own style, which probably will not match others exactly.
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 4 guests