lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Dirk Laurie <> wrote:

> I'll speak for myself.
> Nobody writes better code than I do, when judged the way I judge it. :-)

Well, I think all coders probably think that way in general... though one
thing I have been told is that I am good at adapting my coding style to that
of the project I am working on. Unless, of course, I start the project, then
in that case my coding style is The Best(tm) as well! :)

> I'll occasionally require some rock, but I don't cut-and-paste code.
> (That was forced out of me in my Python days, when invisible errors
> due to significant whitespace ruined a good program, and it's the
> one Python habit I have not shaken off.) Patches amount to cutting
> and pasting.

I never cut-and-paste code, that is just asking for trouble, and you also
don't really learn much either. Generally, if I use third-party code I
manually insert it into the code. Or, if the patch is considerable I will
patch the code in and then manually use a visual diff program to look over
the changes and make any necessary changes to adapt the code to the style of
the codebase. Blind copying and pasting is just a recipe for disaster, I
always try to understand the code I am adding to any project so there are no
surprises later!

> I rewrite it so that it looks the way I would have written it. Sometimes
> trivially, e.g. I put 'if type(x)~="number" then return end' on one line,
> not on three; sometimes less so.

That just makes the code easier to read and maintain, so makes sense!

> I even rewrite code that comes off Don Knuth's page, and nobody writes
> better code than Knuth does, when judged the way Knuth judges it.

Sacrilege! ;)

> I rather suspect that at least one member of the Lua team feels this
> way too. Actually, Paige, I rather suspect that so do you.

Yes, indeed I do. Though in the case of Lua it would be less "just copy this
patch into the codebase" and more "adapt the ideas presented into the
codebase". I get the feeling the latter has happened, and upon reflection I
do understand why the former would not be done.

So far, with my custom Lua variant, I think I have done a good job of
adhering to the style that Lua uses. Though, honestly, I think Lua could use
a good code tidying pass as it is really obvious where different authors
have created code... why single character indenting in luac.c lhf, why? ;)

Actually, speaking of that... I remember a utility from years ago that would
reformat the source code for C, it had a *ton* of options to control every
possible code formatting scenario (placement of braces, etc). I can't for
the life of me remember what the program was called... anyone know?

Eventually I would like to do a from-scratch build of my Lua variant in my
own style, but for now I am just building on the vanilla version. At this
point I think I grok a significant portion of Lua, I am aiming for 100%!