LWN.net Logo

Placement of variable declarations in C

Placement of variable declarations in C

Posted Oct 28, 2007 2:16 UTC (Sun) by giraffedata (subscriber, #1954)
In reply to: Placement of variable declarations in C by RobSeace
Parent article: A potential competitor for GCC: pcc

Structured programming isn't algorithmic programming that avoids excessive gotos. It's a different form of programming, and it doesn't have a goto concept at all.

Ideally, one would use a structured programming language for structured programming, but when forced to use C, one can use a paradigm that makes a structured meta-language out of it. For example, never use a goto statement.

You can look at a C program written in the structured paradigm as algorithmic and see looping and branching (obviously a compiler does), but since it wasn't written to be read that way, it won't be as easy to understand.

Structured programming has a for structure. It was named before C existed, and C's 'for' statement is meant to allude to it, though it is not the same as a structured for statement, e.g. in Pascal. The fact that the value of the index variable is predictable outside of the for statement is one way to tell the difference.

Besides algorithmic (branching and looping) and structured programming, there are various other forms of programming that don't have branches. LISP, Forth, and SAS are examples.


(Log in to post comments)

Placement of variable declarations in C

Posted Oct 28, 2007 11:28 UTC (Sun) by nix (subscriber, #2304) [Link]

I don't know what your definition of `branching' is, but it's not anything 
I'm familiar with. In order to describe any version of Lisp as `not having 
branches' one would have to define the two branches of `if' as `not 
branches', and similarly for `cond'.

If an exception throw/catch isn't a `branch', I don't know what is.

Placement of variable declarations in C

Posted Oct 28, 2007 14:26 UTC (Sun) by RobSeace (subscriber, #4435) [Link]

Yeah, what nix said...  I think you're just playing semantic games, here...  Just because you
don't want to call something a "branch" or a "loop", doesn't mean it doesn't fit the
definition of what I (and most other programmers I've encountered) use those words to mean...
Perhaps they mean something radically different in your world, I don't know...  Got a link to
any supporting documentation on your alternate meanings??

And, BTW, I happen to hold a degree in CS, so I'm fairly familiar with the various forms of
programming (though, it has been many years now), as well as languages such as LISP (which is
functional programming, BTW, and DOES have what *I* would call both loops and branches)...  I
just never encountered anyone who had your strange notions about structured programming, and
the supposed complete absense of "loops" and "branches", before... *shrug*

Placement of variable declarations in C

Posted Oct 28, 2007 19:04 UTC (Sun) by nix (subscriber, #2304) [Link]

Well, it's more accurate to say that Lisp *can* be functional. You have to 
avoid most forms of `set'/`setf', though, and it's sort of tricky compared 
to the mixed functional/declarative approach generally adopted.

Copyright © 2012, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds