Page 1 of 2

Coding Style Rants [Split From "What's Your Coding Style?"]

Posted: Thu Mar 04, 2010 4:23 am
by osdnlo
Sorry, haven't read all the posts, so I hope no one stole my style yet: (A Perfect Example)

Code: Select all

int function(void)
{
      int i=0, x=0; //function variables
      for(i=0;i<10;i++) { printf("\nblah 0x%X",i); }
      if(!(i==8)) { printf("\nNot 8"); } else { printf("\n8!"); }
      return x=i; //return value of i      
}
I think you call that OCD. My goal is to compact my code as much as possible. Ideally, each line would be the exact same length.

Re: What's Your Coding Style?

Posted: Thu Mar 04, 2010 4:51 am
by paolodinhqd
osdnlo wrote:Sorry, haven't read all the posts, so I hope no one stole my style yet: (A Perfect Example)

Code: Select all

int function(void)
{
      int i=0, x=0; //function variables
      for(i=0;i<10;i++) { printf("\nblah 0x%X",i); }
      if(!(i==8)) { printf("\nNot 8"); } else { printf("\n8!"); }
      return x=i; //return value of i      
}
I think you call that OCD. My goal is to compact my code as much as possible. Ideally, each line would be the exact same length.
this is a little messy :?

Re: What's Your Coding Style?

Posted: Thu Mar 04, 2010 4:56 am
by osdnlo
You should see it with syntax highlighting, it's a work of art. I hate white space and I consider code with a lot of white space to be messy.

Re: What's Your Coding Style?

Posted: Thu Mar 04, 2010 5:47 am
by Solar
Basically there are two camps: Those who adhere to a specific "named" style because it is well-recognized and considered readable by their peers, and those who adhere to some personal style because they themselves consider it most readable.

I see slight advantages in the former way (if only because existing code formatters readily support the "named" styles) as long as it's a one-shot tool for personal use. Once you write software, i.e. large bodies of code that would benefit from peer review or later collaborative effort, the "personal" styles are on the losing side because the chances that others would agree with your style are slim.

@ osdnlo:

I see two disadvantages of your "compact" style right away: grep and compiler error messages. Both lose value when you start to bundle multiple statements on a single line.

Re: What's Your Coding Style?

Posted: Thu Mar 04, 2010 6:02 am
by osdnlo
You said it brother. Debugging is a biotch. It's the price I pay to sooth the savage beast. One thing my style does is that it provides a mild form of job security. I learned that the more mucked up I make my code, the less likely the boss will can me for being perpetually late, simply because no one else wants to work on my code. Moreover, when I am feeling pissy I remove all comments when I am done haha. Lastly, I hide my copyrights in various places in the code. This is work code I am talking about. :)

Re: What's Your Coding Style?

Posted: Thu Mar 04, 2010 6:18 am
by Solar
osdnlo wrote:One thing my style does is that it provides a mild form of job security...
Run, boy. Run and pray we never meet in an office at work.

(No smiley put on purpose. I mean it.)

Re: What's Your Coding Style?

Posted: Thu Mar 04, 2010 6:23 am
by osdnlo
That's typically the reaction I get. No one ever told me to run and pray before, but life is random and there we have it. lol... you even made sure that I took you seriously. I suppose this means you wont be hiring me anytime soon? :)

Re: What's Your Coding Style?

Posted: Thu Mar 04, 2010 6:30 am
by Solar
I work as a maintenance coder for roughly ten years now. Picking up the muck other people left behind and making some sort of sense out of it. I found that technical competence and legibility of source are usually directly proportional to each other.

Writing obscure source is not job security, at least not in the long run, because you won't stay in the same job for all your life. Job security is when you do your job so well that your references will get you another job any time, and legibility of code is a value in itself.

Add to that that I prefer to work in a non-hostile environment. How hostile your peers react to you is a function of how much your work helps them compared to how much work you add to their desks. Intentionally writing illegible code goes a long way towards screwing up the "good vibes" at your working place.

Re: What's Your Coding Style?

Posted: Thu Mar 04, 2010 6:37 am
by Lithorien
Solar wrote:
osdnlo wrote:One thing my style does is that it provides a mild form of job security...
Run, boy. Run and pray we never meet in an office at work.

(No smiley put on purpose. I mean it.)
I think you found the next rant for your blog, Solar. ;)

Re: What's Your Coding Style?

Posted: Thu Mar 04, 2010 6:37 am
by osdnlo
Solar wrote:I work as a maintenance coder for roughly ten years now. Picking up the muck other people left behind and making some sort of sense out of it.
No wonder you want to kill me. Perhaps I should run and pray for you instead.
Solar wrote:I found that technical competence and legibility of source are usually directly proportional to each other.


Now that's just mean. I write like that on purpose. I muck up the code at work because it makes me happy and I think the hidden copyrights are just hilarious. I didn't even tell you the worst part. I also tightly connect many functions together and I displace them in separate files. This makes your task much harder doesn't it?
Solar wrote:Writing obscure source is not job security, at least not in the long run, because you won't stay in the same job for all your life. Job security is when you do your job so well that your references will get you another job any time, and legibility of code is a value in itself.
Words of wisdom.

Re: What's Your Coding Style?

Posted: Thu Mar 04, 2010 7:19 am
by Solar
osdnlo wrote:
Solar wrote:I found that technical competence and legibility of source are usually directly proportional to each other.


Now that's just mean.
No. Intentionally obfuscating source to cover your shortcomings (e.g., "being perpetually late") and having other people do double and thrice the work so you can sleep longer is mean.

Actually, it ranks even higher on the "meanness" scale than customers writing stupid or incomplete requirements, because when given the benefit of doubt, they might be just dumb (or simply out of their depth as not everyone is born to handle cold process flow logic). You, however, are intentionally doing a bad job. You're one third engineer, one third craftsmen, and one third artist. And you're intentionally making your product worse. Consider that for a moment.

Next time some gadget you bought breaks two days after the warranty expired, your car's brakes malfunction and you run over a pedestrian, or your credit card gets cut in two by the waiter due to some unexplainable computer glitch, don't complain.

Re: What's Your Coding Style?

Posted: Thu Mar 04, 2010 8:18 am
by gravaera
Hi:
osdnlo wrote:You said it brother. Debugging is a biotch. It's the price I pay to sooth the savage beast. One thing my style does is that it provides a mild form of job security. I learned that the more mucked up I make my code, the less likely the boss will can me for being perpetually late, simply because no one else wants to work on my code. Moreover, when I am feeling pissy I remove all comments when I am done haha. Lastly, I hide my copyrights in various places in the code. This is work code I am talking about. :)
I read this, and I'm still not sure exactly how to respond, so this is really just freelancing I'm doing here. I cannot understand how writing messy code can give you job security. Unless you're one of those incompetent, pathetic cretins who just sits in a 'department' and works at a 'job' for 'a living'.

I'm sure you must feel very proud that your mediocrity and dodgy tactics have managed to somehow keep you afloat for some years. I wish I could be hired at your company. I like busting the chops of people like you. I like inserting little "by the ways" in conversation with the Project Manager about your work. Like:

"Oh, well I had to work on module XYZ -- the one that <insert-your-name-here> was drafting? -- Yea. I suppose he hadn't really got around to finishing it? You must have had to re-assign it, cos it's not functional."

"Oh?"

"Yea. The module itself has the right interface, but I guess seeing as it's just a draft, the bad code behind the interface was part of the design phase. Like drafting. I suppose I'm supposed to finish it, right? I'll get to it."

About ten or so of those, and you lose your precious little job. I've done it about three times already. I felt great seeing people with no pride in their work forced to leave. I suppose you feel good about croushing and maintaining a low profile, and whatnot. But I seem to always think that people like you have more to offer to the firm.

So I like to push you into the spotlight. To reveal your true potential, you know? I'd like to encourage everyone else to do the same to the cretin in your office. You don't have to attack him at all. Just find ways to hilight him in passing. Like:

(In conversation with the lower level manager for your department, or whoever:)
"Aww, sure. <Insert name here> is a really valuable part of the project, actually. He's done small bits here and there, but he keeps the morale up."

"Oh? Very good then. I see."

"Yea. I really admire him. He doesn't much go for the technical stuff on the team, but when there's conflict, he's usually a great help on the social stuff. Great guy."

Then just reinforce that fact that the person is not technically competent. Repeatedly, but with careful timing. And each time, place less emphasis on his social prowess, and watch his incompetence just unwind as he's exposed.

Also, I can't understand what you're doing here, if you're such a useless programmer. What kind of kernel do you expect to produce? Please, by all means, reply and enlighten me. Because I see no way for someone like you to go anywhere in the low level world. But correct me if I'm wrong, I beg you.

Re: What's Your Coding Style?

Posted: Thu Mar 04, 2010 11:06 am
by Selenic
gravaera wrote:I cannot understand how writing messy code can give you job security. Unless you're one of those incompetent, pathetic cretins who just sits in a 'department' and works at a 'job' for 'a living'
I think the reasoning goes something like: Only I understand the code, therefore only I can work with it, so I can't be fired. Works better the larger and more essential the obfuscated code base is, but I'd guess that then it causes so many bugs that it's probably *more* likely to get rewritten from scratch (depending on where you work, whether the time can be afforded, etc.)

This comes to mind; though it's about natural languages and not programming languages, it's a pretty similar idea.

One thing about my style that the snippet from osdnlo does remind me of is the fact that I'll write something like this, rather than separate lines or all in one:

Code: Select all

int i, j, k; // Loop indices
int somevar;
int sum=0;

Re: What's Your Coding Style?

Posted: Thu Mar 04, 2010 11:35 am
by Solar
Selenic wrote:I think the reasoning goes something like: Only I understand the code, therefore only I can work with it, so I can't be fired.
And there you are, doing the only job anyone would give you: Working on the same project for the rest of your live - and that project is horribly obfuscated, uncommented and, most likely, buggy.

Well done. NOT. 8)

Re: What's Your Coding Style?

Posted: Thu Mar 04, 2010 3:07 pm
by osdnlo
@gravaera: It's the office pariah like you that causes me to code like that. I do it to watch people like you get all teary eye'd and want to fight me. Trust me, inside, I want to fight you just as bad. :twisted:

@Selenic: Exactly. That's what I meant and was mostly kidding though. I do it mostly just to piss people off because they act like gravarea.

@Solar: My code is never buggy when I release it. I just make it hard to work on for others. The reason they wont fire me is because I am very good at what I do, I regularly schedule meetings with upper-level staff to demonstrate my latest work because they are interested. I am constantly being rewarded for it. I have it made. I sit at my desk with my feet on it for crying out loud. I have two monitors, on one is a movie the other my code. You think I can do that because I suck? LOL... as Solar said: NOT. :)