Unoffical empeg BBS

Quick Links: Empeg FAQ | RioCar.Org | Hijack | BigDisk Builder | jEmplode | emphatic
Repairs: Repairs

Page 1 of 3 1 2 3 >
Topic Options
#267277 - 15/10/2005 02:47 Humor For Programmers
JeffS
carpal tunnel

Registered: 14/01/2002
Posts: 2858
Loc: Atlanta, GA
Probably all of the programmers here are well aware of The Daily WTF, but since I only found it a couple weeks ago, I figured I'd share. Some days are better than others, but this one absolutely cracks me up- unfortunately it seems that this is a rather common occurance, which kind of scares me.

The program I'm maintaining at the moment could probably dominate this site but I'm refraining from submitting anything at the moment. I'm still too much in awe of how badly written it is.

Anyway, here's hoping the code I wrote in my early years doesn't find its way up onto this site . . .
_________________________
-Jeff
Rome did not create a great empire by having meetings; they did it by killing all those who opposed them.

Top
#267278 - 15/10/2005 08:32 Re: Humor For Programmers [Re: JeffS]
muzza
Pooh-Bah

Registered: 21/07/1999
Posts: 1765
Loc: Brisbane, Queensland, Australi...
Gold. Pure gold.
_________________________
-- Murray I What part of 'no' don't you understand? Is it the 'N', or the 'Zero'?

Top
#267279 - 15/10/2005 12:19 Re: Humor For Programmers [Re: muzza]
jondle
new poster

Registered: 19/08/2005
Posts: 38
Loc: San Diego, CA, USA
That reminds me of a student that works with me. He was wanting help on a java assignment, so I looked at his code. All of his veriables were things like "asdf" or "bob."

I spent the whole time I was helping him asking, "what does asdf hold?"

I told him he needs to use descriptive variables and he told me he likes to be annoying to the TA's (graders). I guess he doesn't realize they give him a grade on that stuff.

Anyway, that was my personal WTF yesterday.
_________________________
Mark IIa -- #30103119 -- 70 gig w/ ext3 fs-- Eutronix Light Kit -- Greenlight buttons

Top
#267280 - 15/10/2005 13:12 Re: Humor For Programmers [Re: jondle]
tman
carpal tunnel

Registered: 24/12/2001
Posts: 5528
Quote:
I told him he needs to use descriptive variables and he told me he likes to be annoying to the TA's (graders). I guess he doesn't realize they give him a grade on that stuff.

It is surprising how many people try to do that. I used to occasionally help mark code at university for extra beer money and if I couldn't understand it reasonably quickly then they got marks deducted. One guy used a single word as a variable but kept varying which chars were upper and lower case. The code worked but one of the criteria was to have readable code so his mark dropped like a stone. Probably should have submitted that one to the obfuscated C contest...

Top
#267281 - 15/10/2005 13:32 Re: Humor For Programmers [Re: tman]
pgrzelak
carpal tunnel

Registered: 15/08/2000
Posts: 4859
Loc: New Jersey, USA
Having been a TA for a few years, I can certainly relate to that. And I would take points off if it became difficult to understand or was not documented. My favorite, though, was when one assignment was handed in by multiple students - you could hold printouts up to the light and have them line up perfectly. So, I would divide the single grade among all of the students that handed that particular paper in, until they got the idea...
_________________________
Paul Grzelak
200GB with 48MB RAM, Illuminated Buttons and Digital Outputs

Top
#267282 - 15/10/2005 15:44 Re: Humor For Programmers [Re: pgrzelak]
sn00p
addict

Registered: 24/07/2002
Posts: 618
Loc: South London
Slighty OT but....

I've never really understood why some people get majorly obsessive about commenting code - I don't know how many times I've heard "code without comments is bad".

Generally speaking, your code should speak for itself, if it isn't then there's something wrong somewhere! I know that in practice this isn't always possible, but when I come across a situation like this, a single line comment usually suffices.

Like above, giving variables and functions proper descriptive names is about the biggest favour you can give yourself and others who access the code.

Bad code is bad code, no amount of commenting is going to fix it!

Top
#267283 - 15/10/2005 16:02 Re: Humor For Programmers [Re: sn00p]
tman
carpal tunnel

Registered: 24/12/2001
Posts: 5528
They have to be good comments as well. I've seen stuff like the following:

Quote:
// Increment i
i++;


I guess it could be useful. You might just on the off chance have somebody that doesn't know the programming language being used at all reading it

Top
#267284 - 15/10/2005 16:47 Re: Humor For Programmers [Re: sn00p]
andy
carpal tunnel

Registered: 10/06/1999
Posts: 5916
Loc: Wivenhoe, Essex, UK
Quote:

Generally speaking, your code should speak for itself, if it isn't then there's something wrong somewhere! I know that in practice this isn't always possible, but when I come across a situation like this, a single line comment usually suffices.



I couldn't agree more, when I put comments in it tends to be to defend or explain a seemingly odd piece of code. Things like "I know this looks like a strange way to do it, but it is right because...".
_________________________
Remind me to change my signature to something more interesting someday

Top
#267285 - 16/10/2005 00:10 Re: Humor For Programmers [Re: andy]
JBjorgen
carpal tunnel

Registered: 19/01/2002
Posts: 3584
Loc: Columbus, OH
I mostly comment when I'm in the situation that I know that I'm going to have to come back and maintain this and I won't know WTF I was thinking the first time through, especially when it comes to documenting the business logic and not just reading the code.
_________________________
~ John

Top
#267286 - 16/10/2005 09:56 Re: Humor For Programmers [Re: sn00p]
Anonymous
Unregistered


Quote:
Slighty OT but....

I've never really understood why some people get majorly obsessive about commenting code - I don't know how many times I've heard "code without comments is bad".

Generally speaking, your code should speak for itself, if it isn't then there's something wrong somewhere! I know that in practice this isn't always possible, but when I come across a situation like this, a single line comment usually suffices.

Like above, giving variables and functions proper descriptive names is about the biggest favour you can give yourself and others who access the code.

Bad code is bad code, no amount of commenting is going to fix it!


I see it as the comments being a higher level to the code. It's not that people can't understand the code itself, it's just faster and easier to understand english than it is to understand any programming language. My philosophy is to be able to read the whole program like a book without looking at one line of code. "// Increment i" is too low level for that.

I used to use little tricks to make each line of code as small and as fast as possible, but in reality, for the average program you can't tell any difference when it runs on today's computers. I also used to find it amusing that no one else could read my code, until I started realizing that I couldn't read it either a week after I wrote it. Now, if it makes it easier to read I'll write a piece of code in several lines when I could do it in one. And now I sort of get a kick out of how easy it is to read my code.

Execution speed and program size are no longer top priorities. Readable and maintainable code is, because processers and hard drives are cheap, but a programmer's time isn't.

Top
#267287 - 16/10/2005 21:31 Re: Humor For Programmers [Re: sn00p]
JeffS
carpal tunnel

Registered: 14/01/2002
Posts: 2858
Loc: Atlanta, GA
Quote:
I've never really understood why some people get majorly obsessive about commenting code . . Generally speaking, your code should speak for itself, if it isn't then there's something wrong somewhere
I comment pretty obsessively. In fact, usually I write the comments first and then the code later. This is two-fold for me- first it helps me understand what I'm trying to do later when I (or another programmer) come back to look at it, and second it helps me make sure I've got it straight in my mind before I code it. If I can't explain something, then I'm not ready to write the code yet.

I understand about the code speaking for itself, but most of the time code can really only speak about the HOW, not the WHY.

Consider the following code:
Code:

for (i=0; i<Accounts.Count; i++)
{
Accounts[i].Process();
}



This seems farily straightfoward code, so a comment like "//Loop through our accounts and process them" is not useful. We can see that from the code. However, a comment telling us what the real-world problem is that we're trying to solve is helpful in understanding the bigger picture: "//Calculate new monthly values for each of our accounts based on current market values".

Steve McConnell talks about this in his "Code Complete" book where you should try not to include low-level programming concepts (records, variables, etc.) in your comments but rather talk about real world problems (account, monthly statement, etc.).

I think you can get away with a few high level comments to explain what you're doing, but because I generally tend to write the comments first and describe the process, I end up with many comments sprinkled throughout. I don't think that level is necessary, but I don't think it's a bad thing, either. It's one of those habits that I've found helps me write more robust code.


Edited by JeffS (16/10/2005 21:39)
_________________________
-Jeff
Rome did not create a great empire by having meetings; they did it by killing all those who opposed them.

Top
#267288 - 16/10/2005 23:27 Re: Humor For Programmers [Re: JeffS]
JBjorgen
carpal tunnel

Registered: 19/01/2002
Posts: 3584
Loc: Columbus, OH
Yeah...that's basically what I said in two lines about documenting business logic
_________________________
~ John

Top
#267289 - 16/10/2005 23:44 Re: Humor For Programmers [Re: ]
mlord
carpal tunnel

Registered: 29/08/2000
Posts: 14491
Loc: Canada
Quote:

Execution speed and program size are no longer top priorities.


I've been hearing that myth for 25 years now, and it just never holds water. Unless one doesn't mind having to continuously purchase newer faster hardware to keep up. Ugh.

And of course, the segment I work in -- embedded operating systems -- speed/space are always THE most important thing, after having a working implementation of course.

Cheers

Top
#267290 - 17/10/2005 00:08 Re: Humor For Programmers [Re: JBjorgen]
JeffS
carpal tunnel

Registered: 14/01/2002
Posts: 2858
Loc: Atlanta, GA
Quote:
Yeah...that's basically what I said in two lines about documenting business logic
Yeah it was- I've developed a bad habit of posting before finishing reading the thread. It's bitten me twice now recently. Once I realized it, though, I wasn't going to delete all of that.

Plus, I'm longwinded!
_________________________
-Jeff
Rome did not create a great empire by having meetings; they did it by killing all those who opposed them.

Top
#267291 - 17/10/2005 00:36 Re: Humor For Programmers [Re: mlord]
Anonymous
Unregistered


Quote:
Quote:

Execution speed and program size are no longer top priorities.


I've been hearing that myth for 25 years now, and it just never holds water. Unless one doesn't mind having to continuously purchase newer faster hardware to keep up. Ugh.

And of course, the segment I work in -- embedded operating systems -- speed/space are always THE most important thing, after having a working implementation of course.

Cheers


Well, of course there are exceptions, but I think for the average program that does average tasks on today's desktops, they don't have to worry too much about speed. Of course faster is better, but in my opinion for most situations readable code is more important.

Top
#267292 - 17/10/2005 07:53 Re: Humor For Programmers [Re: ]
frog51
pooh-bah

Registered: 09/08/2000
Posts: 2091
Loc: Edinburgh, Scotland
This is because average programs are things like Office etc. Which people expect to take a wee bit to open/edit and so on. I hate that expectation! I remember opening docs in Windows 3.1 and they were FAST. Now there is so much bloat, both in MS Office, and Word documents for example, that it takes ages (relatively speaking)

Running OpenOffice on Linux is better, less bloat......(oops, ranting again, where was I?)

Oh yes, low power or high performance apps - this is when efficient code becomes essential...even though gamers buy zippy machines, there is good impetus for games coders to do this right, and for small embedded apps there is often no other way.

And surely the comments live in the source code...not necessarily in the compiled app.!
_________________________
Rory
MkIIa, blue lit buttons, memory upgrade, 1Tb in Subaru Forester STi
MkII, 240Gb in Mark Lord dock
MkII, 80Gb SSD in dock

Top
#267293 - 17/10/2005 08:57 Re: Humor For Programmers [Re: frog51]
JeffS
carpal tunnel

Registered: 14/01/2002
Posts: 2858
Loc: Atlanta, GA
In a desktop app, performance only matters when the difference is perceptable to the user. So if something takes a while to open and you could make it faster, then you should make it faster. If, however, it is a question of a few nanoseconds vs. code readability then readability should take precidence. Now when you're talking a different kind of system nanoseconds could become an issue. It all depends on what kind of app you're developing.

The rule of thumb I go by is to create code that is readable first and optimize when necessary. Trying to optimize code for speed as you write it is generally inneffecient at best, and harmful at worst. Often you'll be defeating compiler optimizations, creating difficult to read code, and not addressing the true bottlenecks anyway. The 80/20 rule applies to optimizations- 20% of the code is going to be responsible for 80% of the performance problems. How's the best way to know what that 20% of the code is? To test it and see- not assume before hand you'll know where the problems are going to be.

This is actually an issue at work right now. My boss has ruled that for new projects, all data access needs to be done via stored procs. Now I am well aware that there is a raging debate on the issue of stored procs vs. paramaterized, in-line SQL (and I'd welcome input on this debate from people I resepct here)- I don't really have a "side" on the issue. Like most programming issues, I say make the right decisison for the right circumstance. Even if Stored Procs are the way to go, though, I resent my boss making that decision for us- I think i'dt be better if she'd just trusts us to make the right decisions, although she did say she'd not stop us from writing in-line SQL, but I know if there are ever problems she'll blame it on that without ever looking into the problem for real.

At any rate, her reasons for using Stored Procs over in-line SQL? Speed and maintainiability. "Maintainablility" is a funny argument because while Stored Procs are easy to correct and deploy (since they are in the database), they are much more difficult to organize and read, especially if you do all of your CRUD with them (requiring hundreds of Stored Procs). So I don't know that I buy the whole maitainability thing.

What really gets me is the performance thing though. She uses this argument like a trump suite- how can you argue with performance? However, both in-line sql and stored procs are compiled the first time they are executed and the only performance gain you get from a stored proc has to do with the way it is looked up for subsqent executions (both are cached, but apparently stored procs are cached in a little easier to find place). This time savings is going to be imperceptable to a user pressing a button, but for her it is the knock-out argument. Now I'll totally agree if it is a call that is going to be made thousands of times in a loop where the time can add up, but if it is a simple request in response to a use pressing a button, I think there are far more important concerns than the nanoseconds that might be saved that are impossible for the user to perceive. Things like true matinatability, code readability, good abstraction, etc.

Anyway, I'm tired of people trying using knock-out blows for any coding concept (not anyone here, BTW, just the trend I've seen and participated in in the past). Use the right tool in the right situation. We are not all writing the same apps, therefore we all have different goals at different times. A database application is very different from a 3D graphics engine is very different from a compiler is very different from a . . .
_________________________
-Jeff
Rome did not create a great empire by having meetings; they did it by killing all those who opposed them.

Top
#267294 - 17/10/2005 09:53 Re: Humor For Programmers [Re: JeffS]
sn00p
addict

Registered: 24/07/2002
Posts: 618
Loc: South London
Quote:
Consider the following code:
Code:

for (i=0; i<Accounts.Count; i++)
{
Accounts[i].Process();
}



This seems farily straightfoward code, so a comment like "//Loop through our accounts and process them" is not useful. We can see that from the code. However, a comment telling us what the real-world problem is that we're trying to solve is helpful in understanding the bigger picture: "//Calculate new monthly values for each of our accounts based on current market values".



But I wouldn't be calling the member function "process", I'd be naming it after what it does, therefore a comment wouldn't give me anymore information than what the line of code does! :P

Top
#267295 - 17/10/2005 11:40 Re: Humor For Programmers [Re: JeffS]
frog51
pooh-bah

Registered: 09/08/2000
Posts: 2091
Loc: Edinburgh, Scotland
All the apps I like to see use stored procs, but my requirements are not performance based, but security based, and it is much easier to meet FSA requirements with a limited set of stored procedures. It is so common to see an app which appears secure at first glance but is vulnerable to a simple SQL Injection atack, thus rendering all the front end security laughable.

<sigh>
_________________________
Rory
MkIIa, blue lit buttons, memory upgrade, 1Tb in Subaru Forester STi
MkII, 240Gb in Mark Lord dock
MkII, 80Gb SSD in dock

Top
#267296 - 17/10/2005 11:45 Re: Humor For Programmers [Re: sn00p]
JBjorgen
carpal tunnel

Registered: 19/01/2002
Posts: 3584
Loc: Columbus, OH
Quote:
But I wouldn't be calling the member function "process", I'd be naming it after what it does, therefore a comment wouldn't give me anymore information than what the line of code does! :P


hmm...

Accounts[i].calculateNewMonthlyValueForOurAccountBasedOnCurrentMarketValue();

seems a bit verbose...
_________________________
~ John

Top
#267297 - 17/10/2005 11:53 Re: Humor For Programmers [Re: JBjorgen]
Roger
carpal tunnel

Registered: 18/01/2000
Posts: 5683
Loc: London, UK
Quote:
hmm...

Accounts[i].calculateNewMonthlyValueForOurAccountBasedOnCurrentMarketValue();

seems a bit verbose...


So? That's what Intellisense (or whatever it's called in your favourite IDE) is for.
_________________________
-- roger

Top
#267298 - 17/10/2005 18:41 Re: Humor For Programmers [Re: Roger]
JeffS
carpal tunnel

Registered: 14/01/2002
Posts: 2858
Loc: Atlanta, GA
Quote:


Quote:
hmm...

Code:
    Accounts[/i].calculateNewMonthlyValueForOurAccountBasedOnCurrentMarketValue();


seems a bit verbose...



So? That's what Intellisense (or whatever it's called in your favourite IDE) is for.


Intellisense might help you write it, but understanding it's a different story. I personaly think the comment is easier to read, but to each his/her own.
_________________________
-Jeff
Rome did not create a great empire by having meetings; they did it by killing all those who opposed them.

Top
#267299 - 17/10/2005 18:48 Re: Humor For Programmers [Re: sn00p]
JeffS
carpal tunnel

Registered: 14/01/2002
Posts: 2858
Loc: Atlanta, GA
Quote:
But I wouldn't be calling the member function "process", I'd be naming it after what it does, therefore a comment wouldn't give me anymore information than what the line of code does! :P


1. See John's Post

2. Sometimes you don't get any control over what the functions you're calling are named, especially if you're using generic utilities.

3."Process", in the real world from which I took this example (it isn't real code, but it is a real concept), is the right name for what is happening to the account- that's what the users call it. In fact, the button they push is called "process". So it's not as generic as it sounds. However, if I leave it at that then any programmer wanting to know more about what the code is trying to accomplish has to go to external documentation and read about what "monthly processing" is. I'd rather give an overall description right in the method so anyone coming behidn me (including myself) can follow my train of thought.
_________________________
-Jeff
Rome did not create a great empire by having meetings; they did it by killing all those who opposed them.

Top
#267300 - 17/10/2005 18:54 Re: Humor For Programmers [Re: frog51]
JeffS
carpal tunnel

Registered: 14/01/2002
Posts: 2858
Loc: Atlanta, GA
Quote:
All the apps I like to see use stored procs, but my requirements are not performance based, but security based, and it is much easier to meet FSA requirements with a limited set of stored procedures.
I can see that, and it's a good point. Our users are all internal to the company, so security isn't AS big of a deal. Still, it's an important consideration since no project stays confined to the rules under which it was initially developed, especially with regards to security.

Quote:
It is so common to see an app which appears secure at first glance but is vulnerable to a simple SQL Injection atack, thus rendering all the front end security laughable.
I would like to point out that I was referring to paramaterized in-line SQL, which is not vulnerable to SQL Injection attacks (not that any one who has access to these systems would know what a SQL Injection attack is). I do realize, however, that SQL Injection is not the only security concern that Stored Procs address. They can really allow you to lock down all access and tightly control what is being done to the data.
_________________________
-Jeff
Rome did not create a great empire by having meetings; they did it by killing all those who opposed them.

Top
#267301 - 18/10/2005 03:48 Re: Humor For Programmers [Re: JeffS]
canuckInOR
carpal tunnel

Registered: 13/02/2002
Posts: 3212
Loc: Portland, OR
Quote:
I understand about the code speaking for itself, but most of the time code can really only speak about the HOW, not the WHY.

This is soooo important. One of my functions at work is to review code written by the rest of our department members. I can't count the number of times that I've seen code that makes me go "huh?" -- the code may be "self-documenting", but not doing what I think it should be doing. The first question I'll usually ask is "why are you doing this?" Sometimes the answer is "well, I tried doing it this [what I would have expected them to do], but it had a problem that doing it this way avoids," to which I'll say "Maybe you could add a comment to that effect, so that whoever maintains this code after you doesn't waste time by ripping it out, and trying to replace it with that." Sometimes I just get a shrug, or an answer that isn't very well thought out -- those are the cases that tell me that a) the developer didn't spend much time thinking about the design, or b) the developer doesn't know the language well enough to know a better way to do it, or c) the code is probably buggy. I've caught a lot of buggy code as a result.

Further, "self-documented code" is sometimes just wrong -- you start out with a function named one thing, which then gets minorly modified so that it subltly doesn't quite live up to its name, but no-one changes the name of the function, because it's an API, and you don't know who else is using the function. Personally, I've never seen any non-trivial so-called "self-documented" code where the "self-documenting" is as complete as it needed to be.

If your comments tell the WHY, and your code tells the HOW, it's a lot easier to make sure that the HOW is actually correct.

On a related note going back to Paul's original comment about incomplete documentation, which spawned this subthread: "documentation" isn't just "commenting code". Documentation encompasses a whole lot more than that, from design specs, to commenting code (algorithms, data structures, code components, etc) to writing end-user documentation.

Top
#267302 - 18/10/2005 05:26 Re: Humor For Programmers [Re: canuckInOR]
sn00p
addict

Registered: 24/07/2002
Posts: 618
Loc: South London
Quote:
Quote:
I understand about the code speaking for itself, but most of the time code can really only speak about the HOW, not the WHY.

This is soooo important. One of my functions at work is to review code written by the rest of our department members. I can't count the number of times that I've seen code that makes me go "huh?" -- the code may be "self-documenting", but not doing what I think it should be doing. The first question I'll usually ask is "why are you doing this?" Sometimes the answer is "well, I tried doing it this [what I would have expected them to do], but it had a problem that doing it this way avoids," to which I'll say "Maybe you could add a comment to that effect, so that whoever maintains this code after you doesn't waste time by ripping it out, and trying to replace it with that." Sometimes I just get a shrug, or an answer that isn't very well thought out -- those are the cases that tell me that a) the developer didn't spend much time thinking about the design, or b) the developer doesn't know the language well enough to know a better way to do it, or c) the code is probably buggy. I've caught a lot of buggy code as a result. [/QUOTE]



Which is exactly the case andy mentioned above and what I was inferring, sometimes things have to be done oddly and not in the way you would necessarilly think or want to write them. In those cases a single line comment saying "It's done like this because " will suffice.

Quote:
Further, "self-documented code" is sometimes just wrong -- you start out with a function named one thing, which then gets minorly modified so that it subltly doesn't quite live up to its name, but no-one changes the name of the function, because it's an API, and you don't know who else is using the function. Personally, I've never seen any non-trivial so-called "self-documented" code where the "self-documenting" is as complete as it needed to be.


The name of the function might lie, but the code inside it wont. I don't see how a comment could be any better, after all your programmer might forget to change the comment, or the comment might get shifted from its original place after code edits, imho it's far easier to get comments out of sync with code than "code"!

Dunno, maybe I'm odd, maybe my CAD field (ultra fast database with ultra fast graphics) is so far removed from "data entry" style software.


Edited by sn00p (18/10/2005 05:29)

Top
#267303 - 18/10/2005 09:47 Re: Humor For Programmers [Re: sn00p]
JeffS
carpal tunnel

Registered: 14/01/2002
Posts: 2858
Loc: Atlanta, GA
On a side note to all of this commenting stuff, one other thing I use comments for is refactoring or rewriting code. Whenever I have to maintain an app that was not developed well, has no external documentation, is not self-documenting, and is not commented well (which describes every app I've been hired to maintain), whenever I have to work in a certain module the first thing I do is go in and start commenting the code. This forces me to take the time to understand the mess step by step, and since it's easy to get overwhelmed by 1500 line methods that do 100 different things with no comments, it keeps me on track. Certainly there are other ways to understand code, but that really works well for me personally.

"If you can't describe it, you can't code it or maintain it," is probably my mantra and the reason I'm so hot on using comments. Of course, I realize that there are other was to display understanding besides being able to write comments, but that is a nice litmus test I use on myself.
_________________________
-Jeff
Rome did not create a great empire by having meetings; they did it by killing all those who opposed them.

Top
#267304 - 19/10/2005 19:59 Re: Humor For Programmers [Re: sn00p]
canuckInOR
carpal tunnel

Registered: 13/02/2002
Posts: 3212
Loc: Portland, OR
Quote:
Quote:
Further, "self-documented code" is sometimes just wrong -- you start out with a function named one thing, which then gets minorly modified so that it subltly doesn't quite live up to its name, but no-one changes the name of the function, because it's an API, and you don't know who else is using the function. Personally, I've never seen any non-trivial so-called "self-documented" code where the "self-documenting" is as complete as it needed to be.


The name of the function might lie, but the code inside it wont.

Now, suppose there's a bug in the code, so that it's doing something yet even more different -- you have a function named for something it's not really doing, the original programmer's intent is to do something that the code's not actually doing -- without a comment explaining what the intent was, are you, the maintainer, going to guess at the code's intent, or just incorrectly fix it to do what the name of the function is?

Quote:
I don't see how a comment could be any better, after all your programmer might forget to change the comment, or the comment might get shifted from its original place after code edits, imho it's far easier to get comments out of sync with code than "code"!

That's partly why it's so important -- if the comments match the code, then you know it's more likely things are hunky-dory. If the comments don't match the code, then you and the developer need to have a chat, because it's an indicator that he didn't write what he intended to write.

In addition, tons of research has been done that shows commenting code does improve maintainability and code readability. Welcome to the field of software metrics analysis. Several years ago, I spent 8 months as an intern with a the Software Engineering and Analysis Lab at Nortel (I can't find an external web-presence for them, but there's an description for them here).
Lots of statistics; I couldn't hack it, and had to get out.

In general, I treat blocks of code as a paragraph, and, just like paragraphs have an introductory sentence, I typically add a summary comment about what the block of code is supposed to be doing, and why. Line-by-line commenting is excessive, and metrics analysis shows that too much commenting can be just as bad as too little.

Top
#267305 - 19/10/2005 20:40 Re: Humor For Programmers [Re: canuckInOR]
tman
carpal tunnel

Registered: 24/12/2001
Posts: 5528
It is all a balance. You need a concise function name and a concise set of comments. Just because the compiler gives you the ability to have a 255 char long function name doesn't mean you should have an insanely long function which describes exactly what it does. You shouldn't put a comment in for every single line either.

What's next on the discussion list? Vi or Emacs? Code formatting style? OS distribution?

Top
#267306 - 19/10/2005 20:42 Re: Humor For Programmers [Re: sn00p]
tman
carpal tunnel

Registered: 24/12/2001
Posts: 5528
Quote:
The name of the function might lie, but the code inside it wont. I don't see how a comment could be any better, after all your programmer might forget to change the comment, or the comment might get shifted from its original place after code edits, imho it's far easier to get comments out of sync with code than "code"!

Eww! A bad comment or an incorrect function name is actually worse than a function with no comments and a vague function name. If you're not going to bother keeping stuff accurate then you might as well rip it out to save confusion.

Top
#267307 - 20/10/2005 05:25 Re: Humor For Programmers [Re: tman]
sn00p
addict

Registered: 24/07/2002
Posts: 618
Loc: South London
Quote:

What's next on the discussion list? Vi or Emacs? Code formatting style? OS distribution?


Yeah, while we're at it, anybody using K&R style bracketing needs to be taken out into the parking lot and shot. Harsh, but fair!

Top
#267308 - 20/10/2005 06:28 Re: Humor For Programmers [Re: sn00p]
andym
carpal tunnel

Registered: 17/01/2002
Posts: 3996
Loc: Manchester UK
Quote:
Yeah, while we're at it, anybody using K&R style bracketing needs to be taken out into the parking lot and shot. Harsh, but fair!


Had to look it up, but agreed, I hate it. According the webpage i looked at my bracketing follows the Allman/BSD style.... nice!
_________________________
Cheers,

Andy M

Top
#267309 - 20/10/2005 09:34 Re: Humor For Programmers [Re: sn00p]
andy
carpal tunnel

Registered: 10/06/1999
Posts: 5916
Loc: Wivenhoe, Essex, UK
Quote:

Yeah, while we're at it, anybody using K&R style bracketing needs to be taken out into the parking lot and shot. Harsh, but fair!


Indeed. I have been forced to use K&R style for the last two days (on my new contract), as that was the standard here. As of ten minutes ago we have just changed the standard, so that I can go back to sane bracketing. Hurrah !

P.S. if anyone is looking for a decent coding standards doc for C#, take a look at http://home.comcast.net/~lancehunt/CSharp_Coding_Standards.pdf


Edited by andy (20/10/2005 09:35)
_________________________
Remind me to change my signature to something more interesting someday

Top
#267310 - 20/10/2005 09:42 Re: Humor For Programmers [Re: andy]
tahir
pooh-bah

Registered: 27/02/2004
Posts: 1913
Loc: London
Quote:
I have been forced to use K&R style for the last two days


Is that a bit like Crane style....

Top
#267311 - 20/10/2005 10:21 Re: Humor For Programmers [Re: andy]
JeffS
carpal tunnel

Registered: 14/01/2002
Posts: 2858
Loc: Atlanta, GA
I hate K&R Bracketing, but I have a guess as to where it came from. Not all languages have a "begin" construct (only "end"), and so putting the starting brace on the same line as the comparison makes the code look a similar style. Althouth why Ritchie specifically felt this was necessary is beyond me, since if he wanted a language without a "begin" construct he could have just left the beginning brace out when he creatd the thing. Of course, I might be wrong on why they used that style- I'm just speculating.

Personally I think I could probably learn to work in K&R, but I would be pretty unhappy for a while. It just seems fundamentally wrong not to match braces up visually.

Interestingly enough, on the thedailywtf forum yesterday there was someone ranting against standard bracing, complaining that the extra white space (the line with the starting brace) was useless and made the code difficult to read. Whatever.

I think I read somewhere that Steve Mcconnell said there is no room for religion in programming (his dad was a preacher, btw), and I think he's right. There are certainly a lot of wrong ways to do things, but there is no single "one right way" to solve problems or write code, and when people start talking that way (I'm thinking specifically of managers), then I start worrying. Mcconnell even makes a case that using the *very* occassional goto could be considered OK if the need is warranted, saying that the old standard "never use gotos" is a bit to hard line*. He does a good job arguing this in "code complete", especially with some of his "rewrite this without a goto" examples, though I must admit to having been in the "never use gotos" camp forever and not having ever had need of one. Still, I think the overarching point is valid. Programming principles are important, but when it comes to specific implementation leave religion out and be accepting of other people's choices, even if they are different from your own . . . unless it's just plain 'ol bad code.

*What Mcconnell says about gotos is, as a rule of thumb try not to use them, and if you do you can get rid of 90% fairly easily. Once you are down to the 10% where gotos seem necessary, work very hard to get rid of 90%. When you've done that, you may have a legitimate need for the reamaining goto.
_________________________
-Jeff
Rome did not create a great empire by having meetings; they did it by killing all those who opposed them.

Top
#267312 - 20/10/2005 10:45 Re: Humor For Programmers [Re: JeffS]
sn00p
addict

Registered: 24/07/2002
Posts: 618
Loc: South London
I used a goto a while back when I found that one of our recursive routines could use up all the stack in a specific circumstance.

The routine itself makes most sense being recursive, so in this situation I opted for a malloc+setjmp+longjmp to save & restore data and address and then used a goto to get to the start of the routine. I guess I could have used a while(1) loop (or possibly another setjmp/longjmp), but the goto seemed most logicial.

Only time I've ever used a goto in 'C'.

Top
#267313 - 20/10/2005 11:41 Re: Humor For Programmers [Re: JeffS]
JeffS
carpal tunnel

Registered: 14/01/2002
Posts: 2858
Loc: Atlanta, GA
Incidently, since I mentioned Mcconnell a few times, I should mention that I disagree with him on the subject of braces. He says that you should use either of the following:

Code:

if (x) {
doSomething()
}



-or-

Code:

if (x)
{
doSomething();
}



And specifically NOT to use

Code:

if (x)
{
doSomething();
}



I have never seen the second format style used (which doesn't mean that it isn't) and am much more comfortable with the third style that I use every day. His arguments that the braces hinder understanding program flow in the third example don't hold water with me, or the majority of programmers it seems. He could be right, but it makes me feel good to know that I disagree with him on something (because on just about every other concept of programming I buy his logic, hook, line, and sinker).
_________________________
-Jeff
Rome did not create a great empire by having meetings; they did it by killing all those who opposed them.

Top
#267314 - 20/10/2005 12:23 Re: Humor For Programmers [Re: JeffS]
wfaulk
carpal tunnel

Registered: 25/12/2000
Posts: 16706
Loc: Raleigh, NC US
Although I understand the notions behind not using it, I still use K&R. (Then again, I'm not a programmer by trade.) The other two make enough sense, but I actually have a harder time finding braced sections using those methods than with K&R. GNU (aka "My terminal isn't wide enough yet") is horrid, but actually makes the most logical sense to me; it just doesn't work out in reality. Of course, all that goes out the window if indenting isn't done properly. Thank god for indent.
_________________________
Bitt Faulk

Top
#267315 - 20/10/2005 12:46 Re: Humor For Programmers [Re: sn00p]
Tim
veteran

Registered: 25/04/2000
Posts: 1525
Loc: Arizona
Quote:
I've never really understood why some people get majorly obsessive about commenting code - I don't know how many times I've heard "code without comments is bad".

Generally speaking, your code should speak for itself, if it isn't then there's something wrong somewhere! I know that in practice this isn't always possible, but when I come across a situation like this, a single line comment usually suffices.

Like above, giving variables and functions proper descriptive names is about the biggest favour you can give yourself and others who access the code.

Bad code is bad code, no amount of commenting is going to fix it!


I think a lot of it has to do with what you are actually working on. When I'm doing a flight model, I comment the hell out of the code - with multiline explanations in certain areas to make sure I remember what term I am currently calculating and how it fits into the big picture. Even with all that code, going back over some of my old stuff that I haven't seen for six years or so is still confusing.

I guess there is a direct relationship between the amount of commenting necessary and the complexity of the problem.

- Tim

Top
#267316 - 20/10/2005 17:49 Re: Humor For Programmers [Re: tman]
canuckInOR
carpal tunnel

Registered: 13/02/2002
Posts: 3212
Loc: Portland, OR
Quote:
It is all a balance. You need a concise function name and a concise set of comments. Just because the compiler gives you the ability to have a 255 char long function name doesn't mean you should have an insanely long function which describes exactly what it does. You shouldn't put a comment in for every single line either.

Agreed. [Edit: snipped stuff I already said in earlier post.]

Top
#267317 - 20/10/2005 18:15 Re: Humor For Programmers [Re: wfaulk]
canuckInOR
carpal tunnel

Registered: 13/02/2002
Posts: 3212
Loc: Portland, OR
For everyone else that doesn't know the basic styles off the top of their head:
Code:

Allman/BSD Horstmann GNU Whitesmiths K&R

if (b) if (b) if (b) if (b) if (b) {
{ { x = 1; { { x = 1;
x = 1; y = 2; x = 1; x = 1; y = 2;
y = 2; } y = 2; y = 2; }
} } }



Personally, I use K&R, though I disagree with Jeff's theory about how/why it evolved. I tend to think it's just so that you can fit one more lines of real code on the screen, instead of taking a line for an opening brace on its own. The if() line is sufficient to signal the opening of a block.

I disagree with the "braces should line up" theology -- I can always tell where a compound statement block starts, based on the indent level. Of course, if there's no indenting, you're hosed, but in that case, having all the braces line up doesn't help any, either. If I need to find the corresponding opening brace for some reason, I can just use the % key*.

IMHO, Horstmann is awful -- in the example given, how easy would it be to swap those two variable initialization lines, if you wanted to (compared to doing the same in any of the other styles)?

The problem with GNU is that you end up with a non-standard indent level that's special just for braces, so you have to tab/indent twice (as opposed to once) for the code within the block. Laziness rules.


* -- yes, this is an implicit admission that I use VIM.

Top
#267318 - 20/10/2005 18:50 Re: Humor For Programmers [Re: canuckInOR]
JBjorgen
carpal tunnel

Registered: 19/01/2002
Posts: 3584
Loc: Columbus, OH
I'm a K&R guy too, but not religious about it. As long as it's consistent, I don't have too much trouble working with it.

Some thoughts:

Horstmann seems bad to me because it'd be too easy to grab a curly brace when copying and pasting a block of code.

I agree that GNU is too much indentation. No thanks.
_________________________
~ John

Top
#267319 - 20/10/2005 19:49 Re: Humor For Programmers [Re: JBjorgen]
wfaulk
carpal tunnel

Registered: 25/12/2000
Posts: 16706
Loc: Raleigh, NC US
My favorite hate about GNU indentation is the fact that each indent is four spaces, but each eight spaces are replaced by a tab, which makes an assumption that tabs occur every eight spaces. It also makes finding matching indents in vi a real PITA.

Personally, I set my tabstops to 2 spaces and indent once for each K&R indentation.

Actually, I don't know what K&R style is for switch statements, but sometimes I put braces around the bodies of switch cases, and when I do that, it ends up being somewhat GNU-like. Actually, looking back at some old code, I can't remember why I did that.
_________________________
Bitt Faulk

Top
#267320 - 20/10/2005 20:27 Re: Humor For Programmers [Re: JeffS]
JBjorgen
carpal tunnel

Registered: 19/01/2002
Posts: 3584
Loc: Columbus, OH
Jeff said:
Quote:
I hate K&R Bracketing


So I'm assuming that when coding in Delphi, you use:

Code:

if (x > y) then
begin
statement1;
statement2;
end;



Whereas I (preferring K&R) would use:
Code:

if (x > y) then begin
statement1;
statement2;
end;


Top
#267321 - 20/10/2005 21:07 Re: Humor For Programmers [Re: canuckInOR]
JeffS
carpal tunnel

Registered: 14/01/2002
Posts: 2858
Loc: Atlanta, GA
Quote:
Personally, I use K&R, though I disagree with Jeff's theory about how/why it evolved.
Yeah, I'm kind of out there on that one. It's one of those things that soudns reasonable until you acually speak/type it. I hearby retract my theory!
_________________________
-Jeff
Rome did not create a great empire by having meetings; they did it by killing all those who opposed them.

Top
#267322 - 20/10/2005 21:15 Re: Humor For Programmers [Re: JBjorgen]
JeffS
carpal tunnel

Registered: 14/01/2002
Posts: 2858
Loc: Atlanta, GA
Quote:

So I'm assuming that when coding in Delphi, you use:
. . .

You are correct.

And of course, by "hate" I simply mean that it drives ME nuts, not that I think other people shouldn't do it. I'm simply not used to it and therefore have difficulty reading/writing code that way, but I don't believe my way is superior.

Mcconnell suggests that K&R is good because it keeps the starting brackets part of the control structure and Whitesmiths is good because it makes the brackets part of the block. He reasons that either of these options is reasonable so that your code is formatted to properly illustrate logic flow. Allman/BSD is a no, no because the brackets are displaced from both the block and the logic statement. Personally, I don't feel that you need to take it that far (and that he's getting a little "religious")- as long as your blocks are intedented and you do it consistently you've met the major objectives.
_________________________
-Jeff
Rome did not create a great empire by having meetings; they did it by killing all those who opposed them.

Top
#267323 - 20/10/2005 21:22 Re: Humor For Programmers [Re: JeffS]
wfaulk
carpal tunnel

Registered: 25/12/2000
Posts: 16706
Loc: Raleigh, NC US
Personally, I'm a fan of languages that make you indent properly and avoid block delimiters altogether. Python comes to mind.
_________________________
Bitt Faulk

Top
#267324 - 20/10/2005 21:27 Re: Humor For Programmers [Re: wfaulk]
canuckInOR
carpal tunnel

Registered: 13/02/2002
Posts: 3212
Loc: Portland, OR
Quote:
Personally, I set my tabstops to 2 spaces and indent once for each K&R indentation.

Gah! I want to maim people that do this! tabstop should never be set to anything other than 8. You really should be using what vim calls 'softtabstop' (along with 'shiftwidth'), which allows you to edit as though a tabstop is 2 spaces, but leaves the tabstop definition at the standard 8 spaces. I really hope you also have 'expandtab' set (which, for the non-vim users, turns tab stops to spaces).

Cheers,
Tab-nazi.

Top
#267325 - 21/10/2005 08:18 Re: Humor For Programmers [Re: canuckInOR]
Anonymous
Unregistered


Are there any members of this BBS that are NOT programmers?

Top
#267326 - 21/10/2005 08:33 Re: Humor For Programmers [Re: ]
JeffS
carpal tunnel

Registered: 14/01/2002
Posts: 2858
Loc: Atlanta, GA
I think many of the members of this BBS are not programmers- especially if you mean as a profession. But even then there are several who've probably never touched a piece of code in their lives. We do probably have a rather high concentration for a non-programming bbs though.
_________________________
-Jeff
Rome did not create a great empire by having meetings; they did it by killing all those who opposed them.

Top
#267327 - 21/10/2005 08:49 Re: Humor For Programmers [Re: ]
furtive
old hand

Registered: 14/08/2001
Posts: 886
Loc: London, UK
Quote:
Are there any members of this BBS that are NOT programmers?


Hello
_________________________
Mk2a RioCar 120Gb - now sold to the owner of my old car
Rio Karma - now on ebay...

Top
#267328 - 21/10/2005 09:40 Re: Humor For Programmers [Re: canuckInOR]
JeffS
carpal tunnel

Registered: 14/01/2002
Posts: 2858
Loc: Atlanta, GA
Quote:
tabstop should never be set to anything other than 8. You really should be using what vim calls 'softtabstop' (along with 'shiftwidth'), which allows you to edit as though a tabstop is 2 spaces, but leaves the tabstop definition at the standard 8 spaces.
I'm trying understand what you're saying here, but I don't get it (not a vim user if that matters). Why would you want your tabs set to 8?

I usually indent everything 2 spaces and have my editor set to insert spaces instead of tabs. Of course, with the editors I use (VS.net and Delphi) the whole tab functionality is really obsolete anyway. VS.net formats your code as soon as you put your closing brace and Delphi has a "smart tab" which inserts spaces up until you reach the next character-after-a-space on the previous line (or the most recent line that extends as far as you're typing).

However, on this subject, tabs in general just drive me nuts. In fact, if the editor doesn't have the option to insert spaces instead of tabs, I just ignore the tab button. I hate opening code in a different editor and having it look like garbage because the previous program used a different tab setting than the one I have now. I am experiencing this most with SQL code right now.

And on THAT subject, why is it that no one seems to ever format SQL code? I realize it's a totally different animal than regular code, but certainly you can find something consistent to do with it.
_________________________
-Jeff
Rome did not create a great empire by having meetings; they did it by killing all those who opposed them.

Top
#267329 - 21/10/2005 13:28 Re: Humor For Programmers [Re: canuckInOR]
wfaulk
carpal tunnel

Registered: 25/12/2000
Posts: 16706
Loc: Raleigh, NC US
Quote:
tabstop should never be set to anything other than 8.

GNU/Emacs freak.

Quote:
You really should be using what vim calls 'softtabstop' (along with 'shiftwidth'), which allows you to edit as though a tabstop is 2 spaces, but leaves the tabstop definition at the standard 8 spaces.

Nope, just "tabstop=2 shiftwidth=2". Interesting idea, though.

Quote:
I really hope you also have 'expandtab' set (which, for the non-vim users, turns tab stops to spaces).

Nope.

See, I find it useful for indents to be one character. It helps me find matching indents better when they span a screen's worth of data.


Edited by wfaulk (21/10/2005 13:33)
_________________________
Bitt Faulk

Top
#267330 - 21/10/2005 18:25 Re: Humor For Programmers [Re: JeffS]
canuckInOR
carpal tunnel

Registered: 13/02/2002
Posts: 3212
Loc: Portland, OR
Quote:
Quote:
tabstop should never be set to anything other than 8. You really should be using what vim calls 'softtabstop' (along with 'shiftwidth'), which allows you to edit as though a tabstop is 2 spaces, but leaves the tabstop definition at the standard 8 spaces.
I'm trying understand what you're saying here, but I don't get it (not a vim user if that matters).

I used the names of vim settings, since I believe Bitt mentioned using vi in another post, and it's the terminology I'm most familiar with.

A 'softtabstop' set to two spaces means that when you hit tab in the editor, rather than inserting a tab character, "\t", it will insert two spaces. Once you tab over a full tab stop, it replaces spaces with a tab character. This last behaviour is actually quite odious.

Fortunately, vim also has a setting called 'expandtab', which changes all literal tab characters into the equivalent number of spaces (depending, of course, on what your tabstop is).

Shiftwidth is a setting that allows you to shift lines of text (in- or outdent) by a certain number of spaces.

In vim, I never actually use the tab key. I use a shift operation to do all my non-automatic indenting.

Quote:
Why would you want your tabs set to 8?


Using your favourite language, do the equivalent of the following:
Code:
perl -e'print "\n\t#\n        #\n";'

There are 8 spaces in that last part. Run that wherever you choose and let me know how often those hash marks don't line up (assuming a fixed width font, of course). Next, create a simple text file containing those two lines. Print it out on paper, again with a fixed width font. I bet the colons line up, right? Then, in a shell, cat the file (I think the old DOS command was 'type'). How big are the tabs? Throw some <pre></pre> tags around it, and view it in a webpage. I bet those hash marks line up, right? They do in Firefox, links, lynx, and konqueror.

Aside from a text-editor where someone has manually changed the tabstop to something other than 8, a tabstop is 8 spaces. If you look at the documentation of the text-editor that person is using, I'd be willing to bet that the default tabstop (which they've changed) is 8.

Where else, other than your text editor, can you change how a tabstop is displayed? I'd bet nowhere. That's because 8 spaces is the standard. Don't change what's standard.

Quote:
I usually indent everything 2 spaces and have my editor set to insert spaces instead of tabs.

This sounds like it's the equivalent of having 'expandtabs' turned on in vim.

Quote:
Of course, with the editors I use (VS.net and Delphi) the whole tab functionality is really obsolete anyway. VS.net formats your code as soon as you put your closing brace and Delphi has a "smart tab" which inserts spaces up until you reach the next character-after-a-space on the previous line (or the most recent line that extends as far as you're typing).

Yes, smartindent is great -- vim has that, as well, and I use it. It doesn't make tab functionality obsolete, however, as, if there are literal tab characters in your file when it gets saved, then they're still there regardless of how your editor displays them.

Quote:
However, on this subject, tabs in general just drive me nuts. In fact, if the editor doesn't have the option to insert spaces instead of tabs, I just ignore the tab button. I hate opening code in a different editor and having it look like garbage because the previous program used a different tab setting than the one I have now.

Now you know why you should never change the tabstop setting from 8. If you have, the only place your formatting will ever look "correct" is in the place it was originally edited.

Quote:
And on THAT subject, why is it that no one seems to ever format SQL code?

We do -- it's a department coding standard.

Top
#267331 - 21/10/2005 18:47 Re: Humor For Programmers [Re: canuckInOR]
JeffS
carpal tunnel

Registered: 14/01/2002
Posts: 2858
Loc: Atlanta, GA
Quote:
Aside from a text-editor where someone has manually changed the tabstop to something other than 8, a tabstop is 8 spaces.
Not true in my world, I'm afraid. VS.NET has it set to 4 and it messes me up when I try to open SQL code that I generated in Sql Query Analyzer.

In fact, I only just now realized that VS.NET inserts tabs when it auto formats rather than spaces- I guess it hasn't tripped me up because I always open c# files in vs.net. Now I'm going to have to see if there's an option to convert to spaces . . .

I also just realized that vs.net indents four rather than two. It's funny I've been programming in c# for two years now and didn't realize that.

Anyway, I guess in my early days I ran into too many apps where tabs were not 8 spaces that I just gave up on tabs altogether. And I experienced it just this week trying to edit SQL code, so there you go.
_________________________
-Jeff
Rome did not create a great empire by having meetings; they did it by killing all those who opposed them.

Top
#267332 - 21/10/2005 19:02 Re: Humor For Programmers [Re: wfaulk]
canuckInOR
carpal tunnel

Registered: 13/02/2002
Posts: 3212
Loc: Portland, OR
Quote:
Quote:
tabstop should never be set to anything other than 8.

GNU/Emacs freak.

Au contraire. The first thing I do after installing a linux distro is remove Emacs. (Historically, it was because I never used it, and when using tiny hard-drives, it took up waaaay too much space for something I never used. Now it's just a matter of principle.)

Don't mistake my advocacy of 8 space tab stops as advocacy of GNUs standard for mixing tabs and spaces. That's even worse than using non-standard tabstops, since the tabs are at least internally consistent.

Quote:
Quote:
You really should be using what vim calls 'softtabstop' (along with 'shiftwidth'), which allows you to edit as though a tabstop is 2 spaces, but leaves the tabstop definition at the standard 8 spaces.

Nope, just "tabstop=2 shiftwidth=2". Interesting idea, though.

Do you ever look at your code with something other than your text editor? grep? less? more? cat? in a text editor at someone else's desk? in a cvs repository via the web? How do you set the tabstops in all those, so your code formatting appears consistent no matter how you're viewing your code? You don't like the assumption that tabstops are always 8 spaces, but where, other than where you've manually changed away from the default of 8 spaces, are tabstops anything but 8 spaces?

Anywhere other than your editor, what you wrote to look like this (on an 80 character terminal):
Code:

if (!statOnly) {
if (result.errorCode) {
if (result.messages.size() > 0) {
TXT_Printf(stderr, SEV_ERROR, "%s\n", (const char *)result.messages[0]);
}
else
TXT_Printf(stderr, SEV_ERROR, "Unknown error.\n");
exit(result.errorCode);
}


will now look like this:
Code:

if (!statOnly) {
if (result.errorCode) {
if (result.messages.size() > 0) {
TXT_Printf(stderr, SEV_ERROR, "%s\n", (const cha
r *)result.messages[0]);
}
else
TXT_Printf(stderr, SEV_ERROR, "Unknown error.\n"
);
exit(result.errorCode);
}



Of course, if that were printed out on paper, those lines would just get lopped off, instead of wrapping.

Quote:
Quote:
I really hope you also have 'expandtab' set (which, for the non-vim users, turns tab stops to spaces).

Nope.

See, I find it useful for indents to be one character. It helps me find matching indents better when they span a screen's worth of data.

The important thing isn't that the indent is "one character", but that indents are always the same number of characters, whether that's one tab, or two spaces.

[edit: fixed quoting.]

Top
#267333 - 21/10/2005 19:13 Re: Humor For Programmers [Re: canuckInOR]
wfaulk
carpal tunnel

Registered: 25/12/2000
Posts: 16706
Loc: Raleigh, NC US
While it's certainly something of a defacto standard that tabstops are at 8 characters, I've seen all sorts of places where that's not true. (The only one that comes to mind is a glass tty I used to use where it was ten. Took me days before I figured out some weird-ass tab-related problem. Which is, of course, why I remember it.)

Personally, I don't see the big issue with how many spaces tabs are or spaces versus tabs as long as you're consistent. The only real problem I have along those lines is GNU indenting, where they assume that tabs are 8 characters (despite there being no real standard to that effect) and that they mix spaces and tabs. Personally, I always use tabs to indent, but I make sure to be consistent.

For example, if I have some code that looks like:
Code:

if ( a<b ) {
if ( c<d ) {
if ( e<f ||
g<h ) {
doit();
}
}
}


then I format it like this:
Code:

if ( a<b ) {
ttif ( c<d ) {
ttttif ( e<f ||
ttttsssssg<h ) {
ttttttdoit();
tttt}
tt}
}


Where "t"s represent space taken up by tabs and "s"s represent space taken up by spaces. That way, no matter what you tabstops are set to, it lines up properly, as long as you're using a fixed-width font. The worst that can happen is that the tabs are too wide, but it's easy to ":set tabstop=2" or ":%s/^I/ /g" or whatever the eqivalents might be in your editor.
_________________________
Bitt Faulk

Top
#267334 - 21/10/2005 19:31 Re: Humor For Programmers [Re: JeffS]
canuckInOR
carpal tunnel

Registered: 13/02/2002
Posts: 3212
Loc: Portland, OR
Quote:
Quote:
Aside from a text-editor where someone has manually changed the tabstop to something other than 8, a tabstop is 8 spaces.
Not true in my world, I'm afraid. VS.NET has it set to 4

Huh. I haven't used windows since... uh... NT 4.0, I think, so I'm coming to this primarily from a unix standpoint. I'm certainly not up on all the fancy IDE editors out there, particularly on Windows.

Quote:
I also just realized that vs.net indents four rather than two.

Well, at least it's a good indent. 2 space indents are too small, IMHO. I like 4 space indents.

Quote:
Anyway, I guess in my early days I ran into too many apps where tabs were not 8 spaces that I just gave up on tabs altogether.

I used to like tabs. Then I started working with other people.

Tabs just shouldn't be used for formatting code.

Top
#267335 - 25/10/2005 00:17 Re: Humor For Programmers [Re: canuckInOR]
rob
carpal tunnel

Registered: 21/05/1999
Posts: 5335
Loc: Cambridge UK
Code:

...
else
TXT_Printf(stderr, SEV_ERROR, "Unknown error.\n");
exit(result.errorCode);


Tsk, always brace, could be a macro!

Rob

Top
#267336 - 25/10/2005 00:41 Re: Humor For Programmers [Re: JeffS]
DLF
addict

Registered: 24/07/2003
Posts: 500
Loc: Colorado, N.A.
Quote:
... never touched a piece of code in their lives.

Do macros or markup languages count? (Tech writer here.)
_________________________
-- DLF

Top
#267337 - 25/10/2005 03:12 Re: Humor For Programmers [Re: rob]
canuckInOR
carpal tunnel

Registered: 13/02/2002
Posts: 3212
Loc: Portland, OR
Heh. Yeah, I know. I always brace, just because a one-line if/else statement will always turn into a block given enough time. In this case, it's not my code -- just a sufficiently deeply nested example. Although, now that you mention it, I think it is a macro. I think I'll check it out tomorrow...

Top
#267338 - 25/10/2005 08:05 Re: Humor For Programmers [Re: rob]
peter
carpal tunnel

Registered: 13/07/2000
Posts: 4180
Loc: Cambridge, England
Quote:
Code:

...
else
TXT_Printf(stderr, SEV_ERROR, "Unknown error.\n");
exit(result.errorCode);


Tsk, always brace, could be a macro!

Shouldn't matter, if the macro writer knew what they were doing.
Code:
#define TXT_Printf(X,Y...) do { stmt; stmt; stmt; } while (0)


If the macro is defined in such a way that it doesn't act as a single statement, then IMO the definition is at fault, not the lack of braces at the use site.

Peter

Top
#267339 - 25/10/2005 09:55 Re: Humor For Programmers [Re: peter]
rob
carpal tunnel

Registered: 21/05/1999
Posts: 5335
Loc: Cambridge UK
Quote:
Shouldn't matter

Don't make me get religious on your ass now!

Rob

Top
#267340 - 25/10/2005 10:18 Re: Humor For Programmers [Re: rob]
JeffS
carpal tunnel

Registered: 14/01/2002
Posts: 2858
Loc: Atlanta, GA
Quote:
Don't make me get religious on your ass now!
LOL!

FWIW, I'm an "always put the braces" guy, but I'm not "religious" about it toward other programmers.
_________________________
-Jeff
Rome did not create a great empire by having meetings; they did it by killing all those who opposed them.

Top
#267341 - 25/10/2005 12:11 Re: Humor For Programmers [Re: peter]
Roger
carpal tunnel

Registered: 18/01/2000
Posts: 5683
Loc: London, UK
Quote:
Shouldn't matter, if the macro writer knew what they were doing.


Agreed; I just had to fix up a couple of macros in our codebase here. Not because anyone had used them where they could break, but because they're just Wrong(tm).
_________________________
-- roger

Top
Page 1 of 3 1 2 3 >