Click here to Skip to main content
14,769,263 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.
 
GeneralRe: Do you Program in Paragraphs or Sentances? Pin
Member 79891221-Jun-18 4:11
MemberMember 79891221-Jun-18 4:11 
GeneralRe: Do you Program in Paragraphs or Sentances? Pin
Sander Rossel1-Jun-18 0:45
professionalSander Rossel1-Jun-18 0:45 
GeneralRe: Do you Program in Paragraphs or Sentances? Pin
Member 79891221-Jun-18 4:01
MemberMember 79891221-Jun-18 4:01 
GeneralRe: Do you Program in Paragraphs or Sentances? Pin
Sander Rossel1-Jun-18 4:09
professionalSander Rossel1-Jun-18 4:09 
GeneralRe: Do you Program in Paragraphs or Sentances? Pin
KBZX50001-Jun-18 0:48
MemberKBZX50001-Jun-18 0:48 
GeneralRe: Do you Program in Paragraphs or Sentances? Pin
Member 79891221-Jun-18 3:55
MemberMember 79891221-Jun-18 3:55 
GeneralRe: Do you Program in Paragraphs or Sentances? Pin
KBZX50001-Jun-18 5:37
MemberKBZX50001-Jun-18 5:37 
GeneralRe: Do you Program in Paragraphs or Sentances? Pin
Member 79891221-Jun-18 9:07
MemberMember 79891221-Jun-18 9:07 
KBZX5000 wrote:
because they look so damn familiar.
That is the main point here.

"Readability" is not as rationally and objectively defined as we would like to think; it is highly personal. What you learned at school. Universities (at least here in Norway) tend to stress whitespace as the most essential element of good programming, so yuong programmers thend to frown at lines exceeding 30 characters.

When the code is spread over three times as many lines, I spend a lot of attention searching for the match: Hey, there is an "else" here - where was the matching "if"? Not on the line above, not two or three lines above, but four lines above.

if/else is usually fairly simple to handle, though. Braces are far worse. When you unroll seven levels of nested blocks, exactly where is the start of the block closed by the fourth one in the unstacking? You don't know which keyword to look for; everything starts with a brace. If the match is 16 lines higher up, it is much easier to match than if it is 67 lines higher up!

Also, I avoid superflous braces: There is no reason to make a block for every single-statement if, while or for clause. If you try to find the matching opening brace (like above), it is far easier if there are five candidates, as compared to twenty three.

(Exceptions are exceptions: The language "designers" did not learn from Pascal that a statement IS a block; they defined a block concept excluding a statement from being a block. Then came the excptional people declaring the exception mechanism to require blocks for all its parts. I consider statements not being blocks as one of the very big mistakes in the formal definition of the c language.)

It is not just for the braces: I really dislike "the rightward migration of source code", as it was once described. To some people, ideal source code has a left margin like a funnel (and sometimes, the underside of the funnel makes you think that you are programming lisp). Matching opening and closing braces is close to impossible except for the two or three innermost levels.

The fewer indentation levels, the better! Following a "return" statement by an "else" is meaningless. I kept it the code example above, because I know lot of coders would bark if I removed it, even though it really has no meaning, and is in a sense misleading: It seems to suggest that the code following the if(){} else{} is unconditional, regardless of the if-outcome. You actually have to open up that if-clause to discover that not only the statement in the else-clause itself but everything that follow the "else" it is conditional on that if-test.

Very often, funnel code is some variation of if - else if - else if ... but with such complex logic that a simple elseif-sequence won't do. The main point is: if (so-and-so), then do it and you are done! All the rest of the funnel is for other cases! Several times when I am the only one handling some code, in C I set up a "#define once i=1;i==1;i++" so that I can program like:
for (once) {
  if (complex condition) {
    ...do this and that...
    break;
  if (another complex condition) {
    ...do something else...
    break;
  ... as many processing alternatives as relevant ...
}
The for loop is a dummy: Because C doesn't provide any mechamism for breaking out of an arbitrary block, we must create a dummy loop to allow the break.

Good old Z.200 CHILL has a very nice feature: Any block (including single statements) could be assigned a label; a function name is a label. The EXIT statement breaks out of the block being so labeled. Also, at the end of the block, you can optionally add the label name for easier matching. The compiler processes it, and if you have placed it wrong, the compiler barfs at you. Yet another thing: Blocks are not enclosed in anonymous braces, but with identifying keywords that tells what kind of block ends here. CHILL doesn't suffer from the lisp syndrome that a lot of C code is plauged with.

CHILL also has an EVER keyword for loop control: You can write: DO FOR EVER ... and the semantics are very clear. Embedded code often has everlasting loops. From old CHILL experience, I added a "#define ever ;;" so that I could write "for (ever)". One of the youngsters (to quote Bill Bryson: "I don't want to say that he was awfully young, but he was wearing a Cub Scout uniform") got really mad when he discovered this, went through the entire code repository for the project and edited it back to the proper way of making an infinte loop: "while (1)", with a very nasty remark in the SVN repo about "some people" who are not taking things seriously but add funny jokes in the program code...

Which brings us back to the starting point: Recognition. This youngster immediately recognized "while (1)" as a loop that would run for ever; he did not recognize "for (ever)" as such.

For those of us who grew up with Pascal and CHILL and the like, some of those C coding style rules seem to serve more as "Don't you, common man, believe that this is something you will read as anything resembling a prosa description of what the computer will do! We are trained to recognize it, but we have taken measures so that you will not recognize it!" That is one of our tools to stay in power.
GeneralRe: Do you Program in Paragraphs or Sentances? Pin
Member 79891221-Jun-18 3:42
MemberMember 79891221-Jun-18 3:42 
GeneralRe: Do you Program in Paragraphs or Sentences? Pin
Bruce Patin1-Jun-18 5:11
MemberBruce Patin1-Jun-18 5:11 
GeneralRe: Do you Program in Paragraphs or Sentences? Pin
RandyBuchholz1-Jun-18 5:14
MemberRandyBuchholz1-Jun-18 5:14 
GeneralRe: Do you Program in Paragraphs or Sentences? Pin
Bruce Patin1-Jun-18 5:43
MemberBruce Patin1-Jun-18 5:43 
GeneralRe: Do you Program in Paragraphs or Sentences? Pin
MSBassSinger1-Jun-18 5:39
professionalMSBassSinger1-Jun-18 5:39 
GeneralRe: Do you Program in Paragraphs or Sentences? Pin
RandyBuchholz1-Jun-18 7:18
MemberRandyBuchholz1-Jun-18 7:18 
GeneralRe: Do you Program in Paragraphs or Sentences? Pin
Member 79891221-Jun-18 9:39
MemberMember 79891221-Jun-18 9:39 
GeneralRe: Do you Program in Paragraphs or Sentences? Pin
Kirk 103898211-Jun-18 6:14
MemberKirk 103898211-Jun-18 6:14 
GeneralRe: Do you Program in Paragraphs or Sentences? Pin
Gerry Schmitz1-Jun-18 7:03
mveGerry Schmitz1-Jun-18 7:03 
GeneralRe: Do you Program in Paragraphs or Sentences? Pin
RandyBuchholz1-Jun-18 7:27
MemberRandyBuchholz1-Jun-18 7:27 
GeneralRe: Do you Program in Paragraphs or Sentences? Pin
Gerry Schmitz1-Jun-18 7:38
mveGerry Schmitz1-Jun-18 7:38 
GeneralRe: Do you Program in Paragraphs or Sentences? Pin
RandyBuchholz1-Jun-18 8:08
MemberRandyBuchholz1-Jun-18 8:08 
GeneralRe: Do you Program in Paragraphs or Sentences? Pin
Gerry Schmitz1-Jun-18 8:44
mveGerry Schmitz1-Jun-18 8:44 
GeneralRe: Do you Program in Paragraphs or Sentences? Pin
Member 79891221-Jun-18 9:52
MemberMember 79891221-Jun-18 9:52 
GeneralRe: Do you Program in Paragraphs or Sentences? Pin
Vivi Chellappa2-Jun-18 5:21
professionalVivi Chellappa2-Jun-18 5:21 
GeneralThought of the Day Pin
OriginalGriff31-May-18 5:56
mveOriginalGriff31-May-18 5:56 
GeneralRe: Thought of the Day Pin
lopatir31-May-18 6:00
Memberlopatir31-May-18 6:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.