structured lang?

A

ambika

Hello,
I have a very basic doubt.
Why is C called a structured programming language??why structured?
C++ is called a Object Oriented language 'cos it obeys the OOP's
concepts..Why is C called a structured programming lang??
Thanks to all those who are gonna answer..
-ambika
 
J

Joona I Palaste

ambika said:
Hello,
I have a very basic doubt.
Why is C called a structured programming language??why structured?
C++ is called a Object Oriented language 'cos it obeys the OOP's
concepts..Why is C called a structured programming lang??
Thanks to all those who are gonna answer..
-ambika

Because C source code is translated into object code into a structural
way.
Here is a structure of C code:

{
printf("Hello world!\n");
}

Here are two structures of C code nested together:

{
int i;
for (i=0; i<100; i++)
{
printf("Hello world!\n");
}
}

Can you see? You can nest structures inside each other pretty much as
deep or as wide as you like.

This is a *VERY* short and shallow introduction to structured
programming. For a proper one, see a textbook about programming. If
you don't have one, ask your teacher to recommend one, and go out and
buy it.

--
/-- Joona Palaste ([email protected]) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"Immanuel Kant but Genghis Khan."
- The Official Graffitist's Handbook
 
C

cody

structured means that you use procedures and while() and for() and
do{}while() loops instead of gotos.
i know no language which does not at least support this meantioned
structures(maybe older versions of basic doesn't).
but this is structured programming, structure your code and do not have
spaghettis&gotos.

oop is structured too, but it goes further so that every variable and
function must belong to a class, there isn't any global thing.
 
J

Joona I Palaste

cody said:
structured means that you use procedures and while() and for() and
do{}while() loops instead of gotos.
i know no language which does not at least support this meantioned
structures(maybe older versions of basic doesn't).
but this is structured programming, structure your code and do not have
spaghettis&gotos.
oop is structured too, but it goes further so that every variable and
function must belong to a class, there isn't any global thing.

Are you sure you aren't restricting yourself to imperative languages
only? I know there are at least some OO languages that aren't
imperative, and they certainly can't be categorised simply as "having
loops instead of gotos". Non-imperative languages usually lack any
explicitly mandated flow of control at all. Some examples of such
languages are Prolog, ML and Haskell.

--
/-- Joona Palaste ([email protected]) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"You can pick your friends, you can pick your nose, but you can't pick your
relatives."
- MAD Magazine
 
M

Malcolm

ambika said:
I have a very basic doubt.
Why is C called a structured programming language??why structured?
C++ is called a Object Oriented language 'cos it obeys the OOP's
concepts..Why is C called a structured programming lang??
A structured progam is one that is based around a hierarchy of relatively
short functions, each one of which has a single point of entry and returns
to the point where it was invoked, and which has a well-defined function.

An object-oriented program is one which is based around data organised to
represent items in the real world or which the program is simulating.
Generally these objects are also grouped by similarity to each other.

C is a good language to use for a structured program, because it is easy and
cheap to write C functions, but a poor language to use for most
object-oriented designs, because it doesn't have higher-level constructs
which make it easy to create objects and express the relationships between
them.
 
C

cody

structured means that you use procedures and while() and for() and
Are you sure you aren't restricting yourself to imperative languages
only? I know there are at least some OO languages that aren't
imperative, and they certainly can't be categorised simply as "having
loops instead of gotos". Non-imperative languages usually lack any
explicitly mandated flow of control at all. Some examples of such
languages are Prolog, ML and Haskell.

they aren't structured PL's then.
 
J

Joona I Palaste

they aren't structured PL's then.

Which would mean that not all OOP is strutured then, wouldn't it?

--
/-- Joona Palaste ([email protected]) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"I will never display my bum in public again."
- Homer Simpson
 
C

cody

structured means that you use procedures and while() and for() and
Which would mean that not all OOP is strutured then, wouldn't it?


exactly.

i have not experience with non-imperative langauges at all so i was not awre
of this fact.
 
E

E. Robert Tisdale

Joona said:
Which would mean that not all OOP is structured then, wouldn't it?

Apparently,
data and algorithmic abstraction are orthogonal to each other.
The following plot illustrates that point:

| | | Object | Object
| | | Based | Oriented
| | | Programming | Programming
--+-------------+---------------+---------------+---------------
| | built-in | User Defined | inheritance
| | types | Type (UDT) | polymorphism data
--+-------------+---------------+---------------+------------------------------>
i | spaghetti | assembler | | abstraction
m | code | [Dartmouth] | |
p | | BASIC | |
e | | Fortran IV | |
r | | Fortran 66 | |
a +-------------+---------------+---------------+---------------
t | structured | Fortran 77 | Algol, | Smalltalk,
i | programming | | Pascal, Ada, | C++, Java
v | | | Modula, C, |
e | | | Fortran 90 |
--+-------------+---------------+---------------+---------------
a | functional | lisp | |
p | programming | | |
p | | | |
l | | | |
i | | | |
c | | | |
a | | | |
t | | | |
i | | | |
v | | | |
e | | | |
--+-------------+---------------+---------------+---------------
d | logic | prolog | |
e | programming | | |
c | | | |
l | | | |
a | | | |
r | | | |
a | | | |
t | | | |
i | | | |
v | | | |
e | | | |
--+-------------+---------------+---------------+---------------
|
v
algorithmic
abstraction

I'm not an expert in computer programming language classification.
In the comp.object newsgroup, Bruno Desthuilliers complains that
two object oriented functional programming languages --
Scheme and OCaml -- don't appear on my plot.

Of course, programming language is actually multidimensional.
You should think of the plot above as a "projection" --
a sort of "principal component analysis" in two dimensions.

Algorithmic abstraction deals mostly with the *implementation*
of complicated algorithms.
Data abstraction deals mostly with the *representation*
of complicated data.
 
J

Jeff

ambika said:
Hello,
I have a very basic doubt.
Why is C called a structured programming language??why structured?
C++ is called a Object Oriented language 'cos it obeys the OOP's
concepts..Why is C called a structured programming lang??
Thanks to all those who are gonna answer..
-ambika

Do a search in google "structured programming language" and you will find :

http://www.wikipedia.org/wiki/Structured_programming

It give you good explanation.

HTH
 
A

ambika

Joona I Palaste said:
Are you sure you aren't restricting yourself to imperative languages
only? I know there are at least some OO languages that aren't
imperative, and they certainly can't be categorised simply as "having
loops instead of gotos". Non-imperative languages usually lack any
explicitly mandated flow of control at all. Some examples of such
languages are Prolog, ML and Haskell.

What does an imperative lang mean??what are non-imperative lang?Can
you please explain.
-ambika..
 
J

Joona I Palaste

What does an imperative lang mean??what are non-imperative lang?Can
you please explain.
-ambika..

An imperative language is one which explicitly specifies flow of
control. An imperative language says things like: "First do this.
After that do this. After that, if this is true, do this, otherwise
do that."
A non-imperative language is one which leaves flow of control up to
the program to decide. It is effectively saying: "Get me these
results, I don't care how".

--
/-- Joona Palaste ([email protected]) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"My absolute aspect is probably..."
- Mato Valtonen
 
C

cody

An imperative language is one which explicitly specifies flow of
control. An imperative language says things like: "First do this.
After that do this. After that, if this is true, do this, otherwise
do that."
A non-imperative language is one which leaves flow of control up to
the program to decide. It is effectively saying: "Get me these
results, I don't care how".


i really can't imagine how this should work. i only say this has to be done
and the compiler must guess how it should be accomplished or what?
 
J

Joona I Palaste

i really can't imagine how this should work. i only say this has to be done
and the compiler must guess how it should be accomplished or what?

Yes. From http://www.haskell.org:

Quicksort in Haskell:
qsort [] = []
qsort (x:xs) = qsort elts_lt_x ++ [x] ++ qsort elts_greq_x
where
elts_lt_x = [y | y <- xs, y < x]
elts_greq_x = [y | y <- xs, y >= x]


This means:
To qsort an empty list, return the empty list.
To qsort a list whose first element is x, and the rest of the list is
xs, return a concatenated list of three lists:
- A qsorted list of those elements that are smaller than x,
- A list consisting of x itself, and
- A qsorted list of those elements that are bigger than x.

That's it. That's basically Haskell translated into English. The more
observant among you can see that in Haskell, the English description of
an algorithm can be more-or-less translated directly into code, instead
of trying to make a step-by-step implementation.

*How* the Haskell interpreter concatenates lists, or finds out which
elements belong to which lists, is its problem, not yours.
 
C

cody

Quicksort in Haskell:
qsort [] = []
qsort (x:xs) = qsort elts_lt_x ++ [x] ++ qsort elts_greq_x
where
elts_lt_x = [y | y <- xs, y < x]
elts_greq_x = [y | y <- xs, y >= x]


This means:
To qsort an empty list, return the empty list.
To qsort a list whose first element is x, and the rest of the list is
xs, return a concatenated list of three lists:
- A qsorted list of those elements that are smaller than x,
- A list consisting of x itself, and
- A qsorted list of those elements that are bigger than x.

That's it. That's basically Haskell translated into English. The more
observant among you can see that in Haskell, the English description of
an algorithm can be more-or-less translated directly into code, instead
of trying to make a step-by-step implementation.

*How* the Haskell interpreter concatenates lists, or finds out which
elements belong to which lists, is its problem, not yours.


iam impressed, thats very fascinating!
maybe this will be the future of programming..
 
P

Peter Nilsson

cody said:
Quicksort in Haskell:
qsort [] = []
qsort (x:xs) = qsort elts_lt_x ++ [x] ++ qsort elts_greq_x
where
elts_lt_x = [y | y <- xs, y < x]
elts_greq_x = [y | y <- xs, y >= x]


This means:
To qsort an empty list, return the empty list.
To qsort a list whose first element is x, and the rest of the list is
xs, return a concatenated list of three lists:
- A qsorted list of those elements that are smaller than x,
- A list consisting of x itself, and
- A qsorted list of those elements that are bigger than x.

That's it. That's basically Haskell translated into English. The more
observant among you can see that in Haskell, the English description of
an algorithm can be more-or-less translated directly into code, instead
of trying to make a step-by-step implementation.

*How* the Haskell interpreter concatenates lists, or finds out which
elements belong to which lists, is its problem, not yours.

iam impressed, thats very fascinating!
maybe this will be the future of programming..

Functional languages have been the future of programming for more than
50 years. So I guess... the future is now. ;)
 
M

Morris Dovey

cody said:
i really can't imagine how this should work. i only say this has to be done
and the compiler must guess how it should be accomplished or what?

Cody...

There probably isn't much guessing to be done - BNF could be
considered a non-imperative language for parsing <whatever>, and
it's fairly non-ambiguous - even though the control flow is
determined strictly by the data being parsed rather than by the
structure of the parsing program.
 
C

cody

iam impressed, thats very fascinating!
Functional languages have been the future of programming for more than
50 years. So I guess... the future is now. ;)


but at the moment they are still academic science studies. i know of no real
application which uses such technology.
 
P

Peter Nilsson

cody said:
but at the moment they are still academic science studies.
i know of no real application which uses such technology.

Well okay, if you say so. Just don't tell the Lisp users...
 
E

E. Robert Tisdale

cody said:
But, at the moment, they are still academic science studies.
I know of no real application which uses such technology.

Can you say emacs?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,262
Messages
2,571,056
Members
48,769
Latest member
Clifft

Latest Threads

Top