Followers 0

# Beautiful code

## 15 posts in this topic

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?
1

##### Share on other sites
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
0

##### Share on other sites
Compare:[code]
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 ... = ???[/code]

vs.

It's similar with elegant code.
2

##### Share on other sites
[quote name='Antheus' timestamp='1318690047' post='4872857']
Compare:[code]
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 ... = ???[/code]

vs.

It's similar with elegant code.
[/quote]
Exactly. The code is waaaay more elegant than the stupid integral.

But in all seriousness, yeah, I agree.
0

##### Share on other sites
For me it's not the code itself that is beatiful, but the implementation behind it
[/quote]
I'm the opposite. I find the algorithm more beautiful than the actual implementation of it.
0

##### Share on other sites
[quote name='Mussi' timestamp='1318677745' post='4872793']
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?
[/quote]

All of my code is beautiful! jk [img]http://public.gamedev.net/public/style_emoticons/default/tongue.gif[/img]
0

##### Share on other sites
[quote name='Antheus' timestamp='1318690047' post='4872857']
Compare:[code]
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 ... = ???[/code]

vs.

It's similar with elegant code.
[/quote]

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.
0

##### Share on other sites
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).
0

##### Share on other sites
[quote name='markr' timestamp='1318803254' post='4873231']
Code which does useful stuff, mostly does not look beautiful. Aesthetics is not its primary concern.
[/quote]

This.

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

Hmm, I smell a journal entry :-)

 [url="http://www.gamedev.net/blog/355/entry-2250790-there-are-many-kinds-of-ugly/"]As threatened![/url]
2

##### Share on other sites
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).
1

##### Share on other sites
[font=sans-serif][size=2]Only entomologists find my code beautiful [/size][/font]
0

##### Share on other sites
[quote name='Antheus' timestamp='1318690047' post='4872857']
Compare:[code]
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 ... = ???[/code]

vs.

It's similar with elegant code.
[/quote]

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 .
0

##### Share on other sites
[quote name='Lode' timestamp='1318926253' post='4873805']
[quote name='Antheus' timestamp='1318690047' post='4872857']
Compare:[code]
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 ... = ???[/code]

vs.

It's similar with elegant code.
[/quote]

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 .
[/quote]

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.
0

##### Share on other sites
[quote name='Eelco' timestamp='1318928048' post='4873816']Zipping the equivalent text string will not make it a better solution, just harder to work with.[/quote]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?
0

##### Share on other sites
[quote name='ApochPiQ' timestamp='1318804324' post='4873241']
[quote name='markr' timestamp='1318803254' post='4873231']
Code which does useful stuff, mostly does not look beautiful. Aesthetics is not its primary concern.
[/quote]

This.

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

Hmm, I smell a journal entry :-)

 [url="http://www.gamedev.net/blog/355/entry-2250790-there-are-many-kinds-of-ugly/"]As threatened![/url]
[/quote]

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.
0

##### Share on other sites
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.
1

## Create an account

Register a new account