I know it depends on you style of coding, but when you write a program, what's more important to you: Clarity or brevity. For example, some people find it very rewarding when they get a lot of 'bang' out of a short amount of code, while others prefere to extend this code for easier readability. What's your oppinion/style?

03-31-2004

XSquared

If I can explain the short code so that I can understand it a month later, I'll do that. Otherwise I'll use the longer method.

04-01-2004

CornedBee

Long code unless resources are limited. Or write the long code first, and when the app is finished, replace it with the short code, but keep the long version in a comment.

My compiler completely eliminates the swap in the former case, and just passes b,a to printf instead. All you've managed to do in the latter is confuse what is actually going on, so the compiler has to take the conservative approach and do what you asked.

04-01-2004

Prelude

>what's more important to you: Clarity or brevity.
I enjoy one-liners as much as anyone else, but for production code you should err on the side of clarity. The goal isn't to astound people with your brilliance by writing code not even you can understand a day after writing it, but to write code that anyone can follow and easily maintain.

04-01-2004

WaltP

Quote:

Originally Posted by Prelude

>what's more important to you: Clarity or brevity.
I enjoy one-liners as much as anyone else, but for production code you should err on the side of clarity. The goal isn't to astound people with your brilliance by writing code not even you can understand a day after writing it, but to write code that anyone can follow and easily maintain.

Unless you're worried about job security. Then obfuscation guarantees you're the only one that can work on the code. :D It rarely works though

04-01-2004

CornedBee

Quote:

Brevity and obfuscation is basically for fun.

For work, clarity is much more important.

Of course this first example is very extreme. Any programmer with a bit of experience in C or C++ would probably look at you as if you're insance if you tell him to use the first variant over the second because of clarity, in this simple form.

04-01-2004

Prelude

>Unless you're worried about job security.
If you're worried about job security then you probably write bad code anyway, so you've nothing to lose by trying to improve yourself. :)

04-01-2004

jrahhali

aww yee!, really cool guys. Thanks for you input. lol, i know there's sometimes that i wish i could take 50 lines of code and compress it into 5, and say "look how great i am everyone!" hehe. But your right, clarity is much more important in most cases. cheers