Principals of Programming Languages 101 (PPL) |
||
![]() ![]() Delta Lt dopel These are good points. To add a little extra... There are arguably 4 main classes of programming languages. Procedural, Logical, Functional, and Object Oriented (OO). The reason I say "arguably" is because the line between OO and procedural is often blurred. See this discussion on Perl to see what I mean. I wont go into much detail as this is a 101 explanation. I will mainly just give an overview of each type. Procedural This includes C, JavaScript, VBScript, Perl, and many others. It's defining characteristic is that it makes use of "procedures" or "subroutines." Code execution is linear in a certain sense. Here's an analogy to help explain this. If you were to code going to a restaurant to get dinner in C, it would be similar to this: 1. Sit at table 2. Read menu and choose option from a list. 3. Go to the kitchen a get recipe. 4. Preform recipe. 4.a Compile ingredients for meal. 4.b cook meal 5. bring meal out to table 6. eat So because you are doing every step, you have much more control over what is happening. This is one reason why C is used mainly for OS's. You can control things down to the actual assembly instruction if you need to. This makes code incredibly fast and efficient. Scripting languages are often procedural because the tasks they accomplish best are often, but not always small and straight forward. OOP Object Oriented languages like Java, C#, C++, and even Perl do not have have functions in the sense procedural languages do. Instead, they have evolved structures that represent a logical entity, called Classes. These classes have functions inside them called methods. One main difference between a method and a C function is that if you write a function called speak(), it does the same thing every time. In OO there is a principal called polymorphism that allows you you to have a method speak() that reacts differently depending on what type of class it is. Example duck.speak() would go quack. dog.speak() would go bark. Taking the analogy form above in OO would look more like this... 1. Sit at table 2. Read menu and choose option from a list. 3. Tell the waiter which option. 4. The waiter goes tell the chef. 6. The chef gets the ingredients from the grocers delivery guy. 7. Chef cooks meal. 8. Returns the meal to waiter. 5. Waiter brings meal out to table 6. By now you hopefully have figured out how to sack your date :) 7. eat Notice there is a lot more involved here. You can concentrate on what you are good at (sacking your date) and let the details to the people who specialize in that area. So while there may be slightly more overhead at run time due to all the communication between Objects, you build a meal much faster than if you were growing your own vegetables every time. Think for a moment about what would in the C story, if I were to order 2 different dishes... So this means that OO languages are great for building complicated systems that have to integrate and work with other systems, often on different technologies. They also offer portability of code much more easily than a procedural language. Functional Example of functional languages are Scheme and Lisp. I would even classify ANSI SQL in this area. Their application is mainly mathematics and academia, but have been used in many areas such as web dev, and AI. These languages to a large extent avoid the use state. This implies that they are largely recursive in nature. One major advantage to functional languages is that they work really well with lists. I will use a generic syntax because frankly I don't remember any Lisp ;) ex. In a procedural language to count to ten you would do this: i = 0 top = 10 Loop Until i = top i = i + 1 End loop print i In a functional language it would look like this. function add(i, top) if (i = top) return i else add(i, top) + 1 end function print add 0, 10 You could also do the same thing very easy on an entire list. Count to 10, 20, and 30. This would take many more lines of code to do in C. print add (0, 0, 0), (10, 20, 30) Logical These are very different from what you would normally consider programming. They are often very English like and based on predicate logic. The most famous of these languages is Prolog. It is often used in AI. The reason for this is because AI requires difficult searches, which can be very slow in most languages languages. The way Prolog works is it first defines a set of statements or facts, sort of like a flat file database. Then you program queries on that set of data. Relatively complicated questions can be asked in very simple syntax. You can do things like: Facts likes(john, apples) likes(jane, apples) likes(john, pears) queries ?- likes(X, apples) Answer: john, jane ?- likes(john, apples) Answer: Yes ?- likes(john, X) Answer: apples, pears Replies:
|
||
| CyberArmy::Forum v0.6 Generated In 0.01662 seconds |