[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] learning pygame: what to focus for a board game?



Hey massimo,

On 6/15/07, massimo s. <devicerandom@xxxxxxxxx> wrote:
Well, I like to code, but I'd like even more to code *well*. I hate to
start programming, seeming to have clear ideas, then realizing that the
code is actually a mess. To me coding is an act of elegance. Too bad I
don't have the skills to follow completely this pursuit - nor the time
to get these skills. So my code is always messy -or at least, messier
than I'd like it to be. However, I like to try to get better and have
fun in the process. I can't learn without having fun and without doing
something that works, and the carcassonne project looks like a fun
project to learn.

I think I am like you, in that beautiful and elegant code makes me
happy and ugly code makes me unhappy. But I find that the sentiments
Casey is expressing about coding what works first, and refactoring
often is the best way to behave for me, even though it leads to ugly
unhappy code at that start. The trick for me is to remind myself that
the difference between beautiful and ugly code is often small - in
that the beautiful code is a subset of the ugly code in an elegant
arrangement. If I sit down and try to create beautiful code in an
elegant arrangement, I usually get frustrated and dither about what to
write, and ultimately fail and get an ugly mess. But looking at an
ugly mess and finding the good parts to pull out and fix up is usually
a straightforward and fun procedure when the ugly mess is small.

So my process to write good code is to make small ugly messes as
quickly as I can, then fix them up before they get big. That satisfies
my desire for elegance more than any other approach I know.


Well, refactoring doesn't allow that... Refactoring means you have to
reorganize your actual code, that is, rewriting things that you know
that function to accomodate new functions in a non-completely hellish
way. This often increases program quality but introduces regressions,
and it's not so funny.

If you develop in a test-driven way (python is very awesome for this
with it's whole "if __name__ == '__main__':" trick) I think you will
find the regression problems of refactoring to be very well managed.
Having that testing safety net is awesome because it lets you refactor
with more confidence, which means you refactor more which ultimately
leads to having both less and better code.


Basically, great design only ever comes from iterations. So if you
want great design... start iterating.