• Congratulations to the Class of 2024 on your results!
    Let us know how you went here
    Got a question about your uni preferences? Ask us here

Evolution of Programming Languages question ... (1 Viewer)

Joined
Nov 4, 2004
Messages
3,550
Location
Sydney
Gender
Male
HSC
2005
Hey guys, just a question in regards to understanding what means what ...

syllabus extract;
Basic building blocks
• variables and control structures
(imperative)
• functions (functional)
• facts and rules (logic)
• objects, with data and methods or
operations (object oriented)

isnt imperative a type of programming language that involves the use of variables, control structures (ie. repeition, sequence and whatever) and that is a TYPE of programming language

where as function, logic and oos are just paradigms or something? are they also programming language types?
i was reading previous threads made last year and didnt completely answer my question, i mean i know what each are and i can define them off the top of my head no problems, but they dont slip in for me, what about declarative languages, is logic declarative?

thanks alot for helping me clear this up!
 

sunny

meh.
Joined
Jul 7, 2002
Messages
5,350
Gender
Male
HSC
2002
Casmira said:
isnt imperative a type of programming language that involves the use of variables, control structures (ie. repeition, sequence and whatever) and that is a TYPE of programming language
Yes. Imperative languages is just another paradigm.

Casmira said:
where as function, logic and oos are just paradigms or something? are they also programming language types?
Yes and yes. You can almost say a paradigm is a type of programming language. So imperative (aka procedural), functional, logic (aka declarative) and OO are all programming paradigms.

Casmira said:
i was reading previous threads made last year and didnt completely answer my question, i mean i know what each are and i can define them off the top of my head no problems, but they dont slip in for me, what about declarative languages, is logic declarative?
Yes, logic languages = declarative languages.

What exactly are you having trouble understanding?
 
Joined
Nov 4, 2004
Messages
3,550
Location
Sydney
Gender
Male
HSC
2005
It doesnt make sense to me if you understand me, I can recall what they are but thats it

I spoke to the other SDD teacher and she ruled it out basically what my understanding is, one other question about categorising software

software mainly can be either procedural, event driven or declarative?
then you can generalise it further saying its either (or a mix) of imperative, logical, object orientated and functional?

im just trying to fit it like a map then it clicks in for me
 

sunny

meh.
Joined
Jul 7, 2002
Messages
5,350
Gender
Male
HSC
2002
Casmira said:
It doesnt make sense to me if you understand me, I can recall what they are but thats it

I spoke to the other SDD teacher and she ruled it out basically what my understanding is, one other question about categorising software

software mainly can be either procedural, event driven or declarative?
then you can generalise it further saying its either (or a mix) of imperative, logical, object orientated and functional?

im just trying to fit it like a map then it clicks in for me
You're probably having this problem because you've never experienced any of these paradigms properly probably other than imperative/procedural, which is why it doesn't make much sense.

There are four paradigms: imperative, logic, OO, and functional. You are right in the sense that you can classify them further into imperative/procedural, OO, and declarative (functional and logic). The characteristic of a declarative language is that there is no clear start/stop to the program in which there is a clear sequence of steps needs to be taken for a problem to be solved. Both functional and logic have this characteristic.

Languages that fit under the imperative paradigm are also called procedural languages (or you can say procedural paradigm as well). These are characterised by a sequence of strict steps that the computer has to follow in order to solve a problem. Thus it focuses on the steps that are necessary to solve the problem. For example, to find 'x' factorial (x!) in a procedural language such as C, we can do:
Code:
int factorial(int x) {

    int answer = 1;
    int i = 0;

    for (i=x; i>=1; i--) {
        answer = answer*i;
    }
    return answer;
}
Contrast this to a functional language, such as a Haskell:
Code:
factorial :: Integer -> Integer
factorial 0 = 1
factorial x = x * factorial(x-1)
The problem is solved not so much in a sequence of steps, but rather the problem is defined and the solving part is left to the program to figure out, ie, x! is = x * (x-1)! and repeat until x=0, where 0! = 1. Recursion is a key characteristic.

And in Prolog:
Code:
factorial(0, 1).
factorial(X, A) :-
  X > 0,
  X1 is X-1,
  factorial(X1, A1),
  A is X * A1.
(Factorials isn't probably a very good example to demonstrate the power of logic languages, since it is relatively simple and similar to functional languages in how it solves the problem).

And since this problem isn't really such an OO problem...theres very little point in doing it in OO. It would just be like the imperative program written in Java and made into classes as much as possible.
 
Joined
Nov 4, 2004
Messages
3,550
Location
Sydney
Gender
Male
HSC
2005
another question

"Logical languages run most inefficiently on Von-Neumann processors, as logic is non-procedural and needs to be broken down into machine code as this utilises much CPU usage"

is this true? I just need to justify reason why logical languages are ineffecient on the von-neumann processors incase the HSC launches an explain or justify question at me
 

sunny

meh.
Joined
Jul 7, 2002
Messages
5,350
Gender
Male
HSC
2002
Casmira said:
another question

"Logical languages run most inefficiently on Von-Neumann processors, as logic is non-procedural and needs to be broken down into machine code as this utilises much CPU usage"

is this true? I just need to justify reason why logical languages are ineffecient on the von-neumann processors incase the HSC launches an explain or justify question at me
Yes this can be true. Problems solved using logic languages usually use a set of rules (aka facts), and an inference engine that determines a solution (eg, answers a question) based on the facts it has in its knowledge base. A simple interferece engine might merely be a tree searching algorithm, which depending on the circumstances might be extremely inefficient (possibly quadratic time or worse) if poorly designed, or if the search space of the problem is extremely large.

I don't know about the whole "broken down into machine code" thing - it doesn't make sense to me - any paradigm has to be "broken down into machine code" for it to work on a computer.
 
Joined
Nov 4, 2004
Messages
3,550
Location
Sydney
Gender
Male
HSC
2005
I needed some way to express how ineffecient it is, I could just say its ineffecient but for bigger marks question such as discuss I needed a stronger word, because in my half yearlies I got 5/6 for one mark because of the words I used! I was cut

But Logic would have to go through more 'stages' to go eventually into machine code or what?
Im guessing that for example a word like ?(Cheese) is 50000 binary digits, which can be probably done in 25000 binary digits if i did it in machine code, is that a good way to think of how its ineffecient, like the syntax is a standard and machine code specalises every single task to be effecient?
 
Last edited:

sunny

meh.
Joined
Jul 7, 2002
Messages
5,350
Gender
Male
HSC
2002
Casmira said:
But Logic would have to go through more 'stages' to go eventually into machine code or what?
This hard to compare, a complex imperative program can go through many stages when compiled before it gets working machine code.

Casmira said:
Im guessing that for example a word like ?(Cheese) is 50000 binary digits, which can be probably done in 25000 binary digits if i did it in machine code
I have no idea what you mean here. Representing a word in binary digits will always be the same number of bits no matter how you do it. It has nothing to do with machine code.

At the HSC level I don't think you would be expected to give great details on why logic paradigm languages are less efficient than imperative languages on the Von-Neumann processor. I think all the question is getting at is that the Von-Neumann processor is designed to work step by step to come to a solution, as are imperative languages, thus making the conversion of high level imperative code into machine code more straightforward.

Logic languages however, rely on the compiler to realise or figure out the steps that would reach a solution when given a certain set of criteria. As a result, the compiled program does not solve a problem not by executing a sequence of straightforward steps as in imperative programs, but rather searches for a solution given a problem and a set of constraints (facts and rules).

Here is a simple Prolog example:
Code:
iProlog (21 March 2003)
: studies(sunny, sdd).
: studies(casmira, sdd).
: likes(sunny, sdd).
: studies(X, sdd)?

X = sunny

X = casmira
: studies(X, sdd), likes(X, sdd)?

X = sunny
:
The first 3 lines facts were entered into Prolog: "Sunny studies SDD", "Casmira studies SDD", and "Sunny likes SDD".

Then the fourth line was executing a query: studies(X, sdd)? is asking, who studies SDD? And Prolog returns X=sunny and X=casmira, as you would expect.

The fifth line: studies(X, sdd), likes(X, sdd)? is asking Prolog, what person X studies SDD, AND likes SDD? Prolog returns X=sunny.

Notice at no point in this program did I actually tell Prolog how to solve a problem, I merely gave it a set of rules (who studies SDD, and who likes SDD), and asked it a number of questions, and Prolog's inference engine determines the answer of my question based on the facts it knows.

The steps that the inference engine execute would not have been a set of sequential straightforward steps like a imperative program; it needs to (without going into detail) search for a solution, which might take longer to execute. Depending on the search algorithm used and the complexity of the problem, the runtime of the program can be quadratic time or worse.
 
Joined
Nov 4, 2004
Messages
3,550
Location
Sydney
Gender
Male
HSC
2005
"I have no idea what you mean here. Representing a word in binary digits will always be the same number of bits no matter how you do it. It has nothing to do with machine code."

sorry I clearly didnt convey what i was saying, like what I'm trying to say is if you do for example, your above prolog program in prolog, then you go make it in imperative or object orientated, or even machine code (you'll have to make it differently, but none the less), wouldn't it be far more effecient as those lower level languages because they're so much closer to machine code? like im trying to understand why the higher the language, the less 'ineffecient', its my own curiosity essentially, i can talk on and on about imperative following von-neumann structure but id have really no idea what im saying and just for comforts sake

thanks for explaining logic though :D that helpe me understand it more!
 

MarsBarz

Member
Joined
Aug 1, 2005
Messages
282
Location
Nsw
Gender
Male
HSC
2005
sunny said:
Logic languages however, rely on the compiler to realise or figure out the steps that would reach a solution when given a certain set of criteria. As a result, the compiled program does not solve a problem not by executing a sequence of straightforward steps as in imperative programs, but rather searches for a solution given a problem and a set of constraints (facts and rules).
Correct me if I am wrong but this is all just theoretical isn't it? How can anything not be done sequentially? It might not look like it's sequential to us but deep inside the code of a logic language things are done in a particular sequence aren't they? How can you possibly have something which is not sequential?
Even event-driven programs are actually sequential, for example an event-driven program would just be refreshing hundreds of times per second to see if anything has been clicked.

Sorry I'm a bit confused could you clarify this a bit?
 

sunny

meh.
Joined
Jul 7, 2002
Messages
5,350
Gender
Male
HSC
2002
MarsBarz said:
Correct me if I am wrong but this is all just theoretical isn't it? How can anything not be done sequentially? It might not look like it's sequential to us but deep inside the code of a logic language things are done in a particular sequence aren't they?
If you put it that way, you can take it one step further and say everything a computer does has to be sequential since there can only be one possible instruction being executed by a single core CPU at any given time.

MarsBarz said:
How can you possibly have something which is not sequential?
Even event-driven programs are actually sequential, for example an event-driven program would just be refreshing hundreds of times per second to see if anything has been clicked.
Not quite that simple, but thats the idea.

You have to remember these are high level paradigms, ie, they are models or certain ways to do things. As far as this higher level of abstraction is concerned, it is not a sequential model. The HSC is not concerned with the innards of the paradigms themselves.
 
Joined
Feb 3, 2006
Messages
75
Gender
Male
HSC
2007
Ive a question,

"Explain the three main components of any imperative programming language and illustrate your answer by choosing examples of each component from a language of your choice."

What would i do for this?
 

sunny

meh.
Joined
Jul 7, 2002
Messages
5,350
Gender
Male
HSC
2002
When they say "component", I think they mean feature or characteristic.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top