Advertisement

Beautiful code

Started by October 15, 2011 11:22 AM
14 comments, last by RivieraKid 13 years ago
[font=sans-serif][size=2]Only entomologists find my code beautiful :([/font]
Gavin Coates
[size="1"]IT Engineer / Web Developer / Aviation Consultant
[size="1"][ Taxiway Alpha ] [ Personal Home Page ]

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.

1845918e723ad0b5874fa2fb77870925.png

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 :).
Advertisement

[quote name='Antheus' timestamp='1318690047' post='4872857']
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.

1845918e723ad0b5874fa2fb77870925.png

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 :).
[/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.
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?

[quote name='markr' timestamp='1318803254' post='4873231']
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 :-)


[edit] As threatened!
[/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.
Success requires no explanation. Failure allows none.
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.

This topic is closed to new replies.

Advertisement