- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
<FONT face="Courier New" size=2>guys, i have no idea what this style possibly looks like. are you talking about the difference in:</FONT>
<FONT face="Courier New" size=2>while (fear && loathing) {</FONT>
<FONT face="Courier New" size=2> - versus -</FONT>
<FONT face="Courier New" size=2>while (feat && loathing)
{</FONT>
[:#]
Admin
<FONT face="Courier New" size=2>fuck you, forum!</FONT>
<FONT face="Courier New" size=2>s/feat/fear</FONT>
Admin
Jed is only (1) character short of Jedi!
Admin
This makes me cry.
Take some perfectly good error messages and remove them, and hope we can debug why the customer is having problems.
I have never had a problem with customers calling tech support about a specific error they don't understand. We can collect statistics about which error they don't understand and focus resources on either preventing that specific error, or giving a better message. This is an easy management decisions about what errors are worth that effort.
I have many problems because customers call "It doesn't work", perhaps with a very generic error. I have spent weeks on these before discovering a real bug. In fact I'm working on such a bug right now, and I have no clue why it is failing, and I still have not found any useful place to add log messages. (Though if I add the messages everywhere the bug never shows up, so it is a timing thing)
Yes it costs money to have users call tech support. However it costs even more money when tech support has to run the user through a long sequence of questions before they find out which argument is bad - and the program even knows in this case.
Admin
Huge fan of the ternary and think it's not used nearly enough by other developers. It only degrades readability if the reader don't use it or understand it and, unless someone can provide a good reason as to why one shouldn't use it, it's the readers' problem.
I use K&R almost exclusively, for a very simple reason. If I'm looking for a method I look for the access specifier, which comes first in a Java method declaration. If I'm looking for a loop, I look for it's respective keywords, and presume the curly brace at the same level of indentation is the close of it. I don't look for a curly brace which, by comparison to a keyword, is far less intuitive. In fact, I worked for only one company that had BSD as a standard and it was eventually changed to K&R. Generally, I find less vertical real estate more readable than having an extra line with only a scope specifier.
Sincerely,
Mung Kee
(Pizza icon dysfunction sufferer)
Admin
Another example of the Peter Princple at work
No, the Peter Principle has nothing to do with Viagara spam ....See http://www.envisionsoftware.com/articles/Peter_Principle.html for an explanation.
Admin
I use a style similar to the third, but in pascal:
procedure Proc1;
begin
if condition then begin
somecode;
end;
if SomeOtherCondition then begin
somecode;
end else begin
somecode
end;
end;
This is usually referred to as 'hanging begin'.
Whe I write C code I do the same thing with the curly braces, mostly out of habit. Why do you find this style so henious? I find that it is not necessary to look for the opening block indicator (begin or { ) in most circumstances, the indention (unless incorrect) clearly indicates where a new block begins, and the end block indicator 'out-dented' on a new line clearly ends the block.
Admin
<FONT face="Courier New" size=2>not at all knowing your specific problem, but this reminds me of a bug i had once while learning c (java? can't recall). adding the error messages added things in memory that prevented a buffer overrun somewhere. :) it was probably c. she is a harsh mistress.</FONT>
Admin
WTF is "Windows-world"?
Admin
You should probably use whichever style is accepted by the community you're working with, so that people from that community can read your code.
For example, I use C# at the moment, so:
function { if (test) { } }
Though if I went to work with a company that did Java, they'd probably want me to do something like this:
function{ if (test){ } }
It's evil and horrible and shouldn't exist, but hey, if that's what I'm paid to do... However, I think the first of these is the ideal solution.
As for braces vs words for begin/end delimiters, I prefer braces because they are (IMHO) less intrusive, less clunky to work with, a little quicker to type, and more visible when the function is already full of words. The downside is that you have to do your indentation properly, because if it gets messed up, you're in serious trouble. Luckily, VS.NET (and probably a lot of other IDEs) sort this out for you pretty much automatically.
Admin
Damn this forum software!!! This (I hope) is what it was supposed to look like:
function { if (test) { } }
vs
function{ if (test){ } }
Admin
I give up. You get the idea
Admin
This is the same type of vitriolic sputum you see from these political pundit jerkoffs. Your problem, like theirs, is that you refuse to accept that someone else sees things a different way, even if their way hasn't been proven wrong. It's simply a matter of opinion.
Already full of words yeah, but are they blue?!
Admin
I've had it too with this forum...
(AAARGH, my "delete" key won't work... AGAIN [:@])
This is it. This is my last post, until this forum is either fixed and useable or replaced by a decent other forum. This sucks big time. I say: Let's boycot this site until it's fixed!
Admin
By the way, I'm astounded by the number of people who more than likely regard themselves as good programmers, also rely so heavily on a curly brace to read code. Maybe it isn't programming skills after all. Maybe it's just reading comprehension.
Admin
I like the ternary too, but when I had to maintain code that had ternary's nested inside eachother inside an aspx page, I wanted to rewrite the C# compiler to throw an error on the cursed question mark.
Lisa needs braces, so long dental plan, Lisa needs braces, so long dental plan, Lisa needs braces, so long dental plan. Come on, show us your braces. Aaaauuuggghhh!!! There is no God.
Can we just mark the whole braces discussion as a giant troll?
Admin
Now there's a good idea!
Admin
At least you can get those damn icons to work! I hate them more than anything but strangely I'm drawn to them.
Admin
Ok, Mung Kee, maybe I was a little too hard on the "opening brace on the same line" thing. It's probably just that I'm used to it being on the next line, but that just seems easier to me. Either way, modern tools help loads.
As for begin/end keywords... I think you're right - before programming skills can come into it, you have to actually parse the document, so to speak, and that's down to how it's laid out. It's the same skills working here that allow you to read a report or browse a website, or look for something in a book, none of which necessarily need programming skills. Of course, programming skills can help by telling you what to expect (though that assumes that the person wrote it in the same way you would), but at this point, if you need them, then it's poorly laid out.
I feel that braces offer a more visible difference to the contents of the function than keywords do.
Also, don't assume it will always be blue - suppose you're viewing it in a comparison app that doesn't do syntax highlighting for that language?
Basically, I can work with begin/end keywords, and have done in the past, but I just prefer braces.
Admin
(Though if I add the messages everywhere the bug never shows up, so it is a timing thing)
We have a lot of those, and it is not timing. In Selligent/Centura script, certain commands hang if the subsequent command is not a message box.
Admin
Ambiguate is a word by the same logic that disambiguate is. It is simply not used idiomatically because it is much clearer to simply refer to one having confounded, obscured, or clouded the meaning. For that matter, I don't believe disambiguate was in any wide idiomatic use until Microsoft started using it in all it's literature and before it, Sun. But wisely, when the technical writing called for a more precise term than colloquial English provided, they adopted or modified an already existing term from another field rather than needlessly inventing a new one, which would have been an out of character excercise in ingenuity--if not down right disengenuous. This reminds me of the "Creationists" who assert that evolution is "only a theory". Yes, but in the same technical sense that gravitation, "Quantum Electro Dynamics", and "Special Relativity" are "theories". We should be happy that "disambiguate" does not have a sloppy colloquial cousin meaning something clear and precise like "to make noise".
The argument reminds me of a classmate in a college algorythm analysis class who complained about the author's frequent use of the term "non-negative integer", to which we all cut him a look and one of us replied "because it's better than always saying 'positive or zero' you dufus". This was the same student who, after learning about Knuths work on sort algorythm efficiency, remarked that it was too late to become a programmer, that everything had already been done!
The emergeance into tech-speak of words like disambiguate and (God help us) "Attritted", are healthy. It is this fungeability that has made the English language so successful. This is an example of the normal healthy evolution of language and we must respond with cogence. Hah!
At any rate, it's better than making up acronyms and emoticins. Not that there isn't a place for both (and this would be that place) but the first time I see "WTF" used in the Wallstreet Journal, that's it! I'm moving to another solar system!
Admin
Which is why smart people move to languages without any braces so as to avoid that kind of issues
Coders with more than half a brain will catch any leaking exception (you don't want the users to SEE your exceptions anyway, now do you?) and log them somewhere, displaying a nice&friendly error message in the process.
The one who uses the exception is the dev, or the dev team that has to patch the bug, and a damn frigging useless exception/exception trace is... not really helpful as far as testing/finding/fixing the issue goes.
That would be an issue if compilers didn't handle that kind of simple optimization issues.
Most of them do
Whitespace-marked blocs.
Get rid of any typing and any useless information, double win
Admin
Anonymous wrote:
It's much like "Waterworld". Expensive, and crap.
But without Kevin Costner, which is about the only thing I can come up with in its favour.
Oh, and K&R style, 2 space indentation and no fscking tabs, but that's latter part's just for me. I have no fear of reformatting indentation as a half-way-decent change management tool will only show non-whitespace differences. diff -bBe would work, for example.
Simon
Admin
On very rare occassion do I browse anything without syntax highlighting. Really the only time I do is when I'm deploying to a server via NetMeeting or VNC which doesn't have an IDE. If it becomes all that common a problem, I would tend to put SOME SORT of IDE on the machine, but have no problem reading non-highlighted code. I can't imagine many people are hopping around to new servers, which don't have any environment set up. Sure, on rare occassion you need to browse files in production. Now, if we're talking about reading poorly indented code, I would get pretty angry trying to read through that mess.
Admin
I knew I should have been more specific...
Obviously, that performs differently. Personally, I think that is some WTF code on it's own if used in anything real. It's a silly example from a CS 101 book about how the operators are different. In real code, that syntax isn't good for readability.
I meant arguing curly brace style is the same as arguing about:
for( int i = 0; i< 10; ++i )
{
...
}
vs
for( int i = 0; i< 10; i++ )
{
...
}
Admin
I switch between C and Pascal, with the the vast majority of the time spent in pascal, and find it the other way around, a nice chunky 'end' makes a more recognizable and consistant visual seperator than a little skinny {. But then I like the way an 'end' or 'begin' keyword matches up with the look of the text of the body of a routine. C code always looks anemic.
Besides all that, I prefer typing several letters to stretching both pinkies to hit a curly brace :p If the were somewhere else on the keyboard I might like the better.
Admin
Take a look at this... (I removed comments and such)
How is that difficult to read? It seems incredibly obvious to me where each block starts. Simply look up until you find the first indented line at that indentation level, as the blue lines illustrate in the picture. So long as you're not dealing with poor indentation, I don't think it gets much more clear than that.
Let's try using this software with HTML...
Admin
8 spaces is quite close to "poor indentation" in my book.
Admin
Since everyone else is doing it, I'll post my bracing style as well. It's rather complex:
So there you have it. Classes and functions have their opening brace on a line of their own, as do switch statements and all other statements where the condition is too long for one line.
Admin
Amen. 4! No more, no less.
Admin
I couldn't agree more!!!!
Stop this begin/end nonsense right away please, WTF!!!
For the java-eclipse fans, it's CTRL-P you're looking for to match delimiters.
Matt
Admin
To add to this, easily read code is much more about proper indentation than it is curly braces and keywords.
Admin
Sorry about that typo, it's CTRL-SHIFT-P ofcourse.
Admin
CTRL-P? You sure you want to go with that?
Admin
I agree. Although, if I had to choose between more or less, I would definitely pick more. I used to work with a guy that used 2-space tabs and his code was completely unreadable.
[image]
Admin
He must have had very poor peripheral vision.
Admin
I find it hilarious that folks who advocate putting the opening brace on the same line because it saves vertical space almost always use 4-space or 8-space tabs, thereby wasting horizontal space. They also tend to put braces around single-statement blocks, like so
if (wtf) {
++lol;
}
instead of
if (wtf)
++lol;
The vertical space argument is bunk. Assuming you display about 30 lines on the average screen, are there really enough blocks that an extra line for an opening brace in each block really hampers your productivity and the amount of code you can read on one screen? Give me a break.
I use 2-space indentation and opening braces get their own line. Single-statement blocks don't get braces. I have never had a bug where I added a statement to an if- or while-scoped block that only had one statement before and forgot to add braces around it, so the argument "yeah well you should always enclose blocks in braces cuz it makes it easier to add additional statements later" is crap as well - how much goddamn work is it to add a pair of braces?
Repeat after me: 2-space indents and braces on their own lines is the way of the lord.
Admin
[image] Use the source Mung Kee. You will find the secret of the pie.[image]
Admin
Brillant is too!
Admin
[pi]
[image]
Admin
Nowhere did you make an argument for why braces should be placed on separate lines. So, even if I accept your arguments, there's no reason I should buy into your final statement because you've proven nothing.
Sincerely,
Richard Nixon
Admin
Hear, hear! WTF, Indeed.
Admin
[image]
Sincerely,
Richard Nixon
Admin
So what's your argument FOR using a separate line for starting curly braces? It's either lack of code comprehension or reading comprehension. That lonely curly brace is a crutch for the feeble minded engineer.
I like how you don't provide a case for your style but still expect someone to adopt it. I would love to see a good sized method with 2 space indentation. Why don't you post it and I'll go get the Advil?
Great, another f-in preacher. Your 'lord' must be the Engineering equivalant of L Ron Hubbard (or Tom Cruise, I can't decide which).
Admin
I made an argument that is usually accepted without question in about 20 states in the US: "for it is the way of the lord".
My real argument is that, in order to find the opening brace, I only need to scan up from the closing brace, or two spaces left and one line up from the first statement. Indentation is a visual means of showing that the statements all belong together inside a block; by the same token, the delimiters for said block belong together on the same vertical line.
By putting the opening brace on its own line, it's ALWAYS IN THE SAME HORIZONTAL LOCATION given an identation level. That's a Good Thing in terms of usability - like the Mac system bar being at the top of the screen, or the Start button in the bottom left-hand corner: you can't miss it. If the opening brace is at the end of the line, it's never in the same horizontal position, because lines have variable lengths. It's like installing a light switch at a variable height on the wall depending on how long the room is. It's bad behavior and should be punished by death.
Admin
And you're the one criticizing my lack of reading comprehension, when you can't handle a smaller indentation step?
"Those 2 or 6 extra indentation spaces are a crutch for the feeble minded engineer."
Sheesh. I know monkeys with better reasoning power than you.
Admin
Another thing about the "saving space" argument for putting the brace at the end of the line: if that's the case, then, why not put every fricking statement on one line? You could have a giant 100kb one-liner. There'd be no wasted space whatsoever.
If you accept the argument that indentation helps readability, then you should also accept that having the brace on its own line performs the same function, at least for some people.
Admin
Beastiality technically isn't illegal in every state either, but that doesn't make right.
My argument is that all I have to do is find the character that's in the same vertical line. Your brain doesn't even have to process what character that is. If the indentation is consistent, I don't care if it's curly brace or a letter.
And knowing that it's definitely a curly brace in that column while scanning up saves how much time for the scan? I submit 0ms.
Your light switch analogy is irrelevant and pointless too.
Admin
I agree with you both. I use MSVC++, which defaults to four-space tabs, but chose to open that file in Notepad (defaults to eight-space tabs) because it doesn't have syntax highlighting (which would have detracted from my point). Don't worry, Notepad is no longer my "IDE" ;)
Why does the CAPTCHA always fail on the first try?
Admin
My point, as you'll see in a previous post, is that readability is more about indentation than vertical spacing or curly braces. That's the way I read code anyway.
BTW, nice play on my nickname. I never would have thought of that. To paraphrase, "Hey, 'Mung Kee' sounds just like 'monkey'!"