• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Beautiful code

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

15 replies to this topic

### #1Mussi  GDNet+

Posted 15 October 2011 - 05:22 AM

Sometimes when I write a complex piece of code that's easy to reuse and loose coupled or something along those lines I can't help but think it looks beautiful . How many of you occasionally think their code looks absolutely beautiful?

Posted 15 October 2011 - 06:40 AM

For me it's not the code itself that is beatiful, but the implementation behind it

I've had a number of occasions where I had an idea for a feature or an improvement in some of my projects which seemed to work out great on paper, but which I was unsure of while fleshing it out and implementing it (is this going to be fast enough? am I making this overly complex? etc.)

To see such an implementation working nicely and often even better than expected while written in a clean coding style is pure beauty to me, and the sense of accomplishment you get from implementing something you designed completely by yourself and which is working perfectly is just awesome

I gets all your texture budgets!

### #3Antheus  Members

Posted 15 October 2011 - 08:47 AM

Compare:
Volume of sphere = 4.13 * r^3
Volume of cube = a^3
Volume of cylinder = 3 * r^2 h
Volume of tea pot = "measure with cylindrical cups the volume of water it holds"
Volume of a mine = ...
Volume of a ... = ???

vs.

It's similar with elegant code.

### #4Cornstalks  Members

Posted 15 October 2011 - 08:56 AM

Compare:

Volume of sphere = 4.13 * r^3
Volume of cube = a^3
Volume of cylinder = 3 * r^2 h
Volume of tea pot = "measure with cylindrical cups the volume of water it holds"
Volume of a mine = ...
Volume of a ... = ???

vs.

It's similar with elegant code.

Exactly. The code is waaaay more elegant than the stupid integral.

But in all seriousness, yeah, I agree.
[ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

### #5way2lazy2care  Members

Posted 15 October 2011 - 09:31 AM

For me it's not the code itself that is beatiful, but the implementation behind it

I'm the opposite. I find the algorithm more beautiful than the actual implementation of it.

### #6/ SteveDeFacto   Banned

Posted 15 October 2011 - 07:57 PM

Sometimes when I write a complex piece of code that's easy to reuse and loose coupled or something along those lines I can't help but think it looks beautiful . How many of you occasionally think their code looks absolutely beautiful?

All of my code is beautiful! jk

### #7Mussi  GDNet+

Posted 16 October 2011 - 07:17 AM

Compare:

Volume of sphere = 4.13 * r^3
Volume of cube = a^3
Volume of cylinder = 3 * r^2 h
Volume of tea pot = "measure with cylindrical cups the volume of water it holds"
Volume of a mine = ...
Volume of a ... = ???

vs.

It's similar with elegant code.

This is sort of how I shoot myself in the foot sometimes. When I only need the volume of one or two items for example, I still try to implement the general and more elegant solution, which takes more time and adds unnecessary complexity.

### #8markr  Members

Posted 16 October 2011 - 04:14 PM

Code can look beautiful, but the proof of the pudding is in the eating.

Code which does useful stuff, mostly does not look beautiful. Aesthetics is not its primary concern.

While there are some things which look ugly, and are very bad, in practice, a lot of uglyness is about making it *sodding well work*. Code looks ugly, because it contains countless small bugfixes which accumulate over time, to make it look like a mess, but it *works*.

I see programmers (not software engineers!) refactor code because they think it is ugly. They may make it look nicer, but inevitably introduce countless bugs. Software engineers never refactor code because it is ugly.

Unit tests might detect the really big stupid bugs, but the small, sneaky bugs get through, into production, and break stuff for customers (err, players in the games industry, I guess).

### #9ApochPiQ  Moderators

Posted 16 October 2011 - 04:32 PM

Code which does useful stuff, mostly does not look beautiful. Aesthetics is not its primary concern.

This.

Most production-level code is actually pretty hideous. Of course, it can be hideous because it's truly bad, or because it's full of tiny considerations for really obscure cases.

Hmm, I smell a journal entry :-)

 As threatened!
Wielder of the Sacred Wands

### #10szecs  Members

Posted 17 October 2011 - 02:05 AM

Hmm, if I were at my own computer, I could do some mass killing by showing some of my code I saw beautiful.
They weren't good or anything, but sometimes I spent hours just looking at those beautiful code (with appropriate music of course).

### #11gavco98  Members

Posted 18 October 2011 - 02:02 AM

Only entomologists find my code beautiful
Gavin Coates
IT Engineer / Web Developer / Aviation Consultant

### #12Lode  Members

Posted 18 October 2011 - 02:24 AM

Compare:

Volume of sphere = 4.13 * r^3
Volume of cube = a^3
Volume of cylinder = 3 * r^2 h
Volume of tea pot = "measure with cylindrical cups the volume of water it holds"
Volume of a mine = ...
Volume of a ... = ???

vs.

It's similar with elegant code.

The integral does not have enough information. f, a and b are not given.

I know this is just an example, but, this is what I disliked about courses and love about programming code:

Programming code requires you to give the value, operators, etc... of everything you need. Only then it compiles and works. Every mathematical problem can be formulated as programming code.

Mathematical formulas can be sloppy, and often are in course books, with you having to guess the values or sometimes even meanings of some of the symbols based on vague slides. Plus, variable names in math formulas are 1 letter names, that's not very readable code .

### #13Eelco  Members

Posted 18 October 2011 - 02:54 AM

Compare:

Volume of sphere = 4.13 * r^3
Volume of cube = a^3
Volume of cylinder = 3 * r^2 h
Volume of tea pot = "measure with cylindrical cups the volume of water it holds"
Volume of a mine = ...
Volume of a ... = ???

vs.

It's similar with elegant code.

The integral does not have enough information. f, a and b are not given.

I know this is just an example, but, this is what I disliked about courses and love about programming code:

Programming code requires you to give the value, operators, etc... of everything you need. Only then it compiles and works. Every mathematical problem can be formulated as programming code.

Mathematical formulas can be sloppy, and often are in course books, with you having to guess the values or sometimes even meanings of some of the symbols based on vague slides. Plus, variable names in math formulas are 1 letter names, that's not very readable code .

Truth.

Conciseness and brevity are not the same thing; mathematicians and some functional language designers have a habit of confusing the two.

A concise statement of a solution to a problem is awesome. Zipping the equivalent text string will not make it a better solution, just harder to work with.

### #14Hodgman  Moderators

Posted 18 October 2011 - 03:20 AM

Zipping the equivalent text string will not make it a better solution, just harder to work with.

hahaha nice analogy!

Some things that come to mind for me when considering the beauty of code are:
How long does it take me to understand?
How connected/dependent is it to/on other code?
How deliberate is it with it's usage of resources?
How far does it stray from the scope of it's problem?
How easily can I change it?

### #15Telgin  Members

Posted 18 October 2011 - 09:40 AM

Code which does useful stuff, mostly does not look beautiful. Aesthetics is not its primary concern.

This.

Most production-level code is actually pretty hideous. Of course, it can be hideous because it's truly bad, or because it's full of tiny considerations for really obscure cases.

Hmm, I smell a journal entry :-)

 As threatened!

I'd like to think this means my code is actually not as bad as I think it is. But I know better, my code is hideous because it's usually tossed together without a large amount of thought. It does work most of the time, but I feel bad for whoever has to maintain this stuff if I leave my current position.

I do feel a certain amount of pleasure in actually producing elegant code that is maintainable and scalable, but it just doesn't happen often. My code usually looks clean up until it's about 50 lines long. It's all downhill from there.
Success requires no explanation. Failure allows none.

### #16RivieraKid  Members

Posted 18 October 2011 - 01:11 PM

code that looks like the problem being solved is beautiful because anyone can understand it and its easy to maintain.

Layers of abstraction for abstractions sake are the devil.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.