Web Design Mississauga by DTW

Java programming language

Posted by admin | Systems Applications | Tuesday 22 December 2009 12:48 am

virtual machine, a program written in native code on the host hardware that translates generic Java bytecode into usable code on the hardware. Further, standardized libraries are provided to allow access to features of the host machines (such as graphics and networking) in unified ways. The Java language also includes support for multi-threaded programs–a necessity for many networking applications.

The first implementations of the language used an interpreted virtual machine to achieve portability, and many implementations still do. These implementations produce programs that run more slowly than the fully-compiled programs created by the typical C++ compiler and some later Java language compilers, so the language suffered a reputation for producing slow programs. More recent implementations of the Java VM produce programs that run much faster, using multiple techniques.

The first of these is to simply compile directly into native code like a more traditional compiler, skipping bytecodes entirely. This achieves great performance, but at the expense of portability. Another technique, the just-in-time compiler or “JIT”, compiles the Java bytecodes into native code at the time the program is run. More sophisticated VMs even use dynamic recompilation, in which the VM can analyze the behavior of the running program and selectively recompile and optimize critical parts of the program. Both of these techniques allow the program to take advantage of the speed of native code without losing portability.

Portability is a technically difficult goal to achieve, and Java’s success at that goal is a matter of some controversy. Although it is indeed possible to write programs for the Java platform that behave consistently across many host platforms, the large number of available platforms with small errors or inconsistencies led some to parody Sun’s “Write once, run anywhere” slogan as “Write once, debug everywhere”.

Secure execution of remote code

The Java platform was one of the first systems to provide wide support for the execution of code from remote sources. An applet could run within a user’s browser, executing code downloaded from a remote HTTP server. The remote code runs in a highly restricted “sandbox”, which protects the user from misbehaving or malicious code; publishers could apply for a certificate that they could use to digitally sign applets as “safe”, giving them permission to break out of the sandbox and access the local filesystem and network, presumably under user control.

Evaluation

In most people’s opinions, Java technology delivers reasonably well on all these goals. The language is not, however, without drawbacks.

Java tends to be more high-level than similar languages (such as C++), which means that the Java language lacks features such as hardware-specific data types, low-level pointers to arbitrary memory addresses, or programming methods like operator overloading. Although these features are frequently abused or misused by programmers, they are also powerful tools. However, Java technology includes Java Native Interface (JNI), a way to call native code from Java language code. With JNI, it is still possible to use these features.

Some programmers also complain about its lack of multiple inheritance, a powerful feature of several object-oriented languages, among others C++. The Java language separates inheritance of type and implementation, allowing inheritance of multiple type definitions through interfaces, but only single inheritance of type implementation via class hierarchies. This allows most of the benefits of multiple inheritance while avoiding many of its dangers. In addition, through the use of concrete classes, abstract classes, as well as interfaces, a Java language programmer has the option of choosing full, partial, or zero implementation for the object type he defines, thus ensuring maximum flexibilty in application design.

There are some who believe that for certain projects, object orientation makes work harder instead of easier. This particular complaint is not unique to the Java language but applies to other object-oriented languages as well.

Language

An example of a hello world program in the Java language follows:

public class HelloWorld {
public static void main(String[] args) {
System.out.println(“Hello world!”);
}
}

Control structures

Loops

while (Boolean expression) {
statement(s)
}

do {
statement(s)
} while (Boolean expression);

for (initialisation ; termination condition ; incrementing expr) {
statement(s)
}

Conditional statements

if (Boolean expression) {
statement(s)
}

if (Boolean expression) {
statement(s)
} else {
statement(s)
}

With else if arbitrarily complex if-then-constructions may be built.

if (Boolean expression) {
statement(s)
} else if (Boolean expression) {
statement(s)
} else if (Boolean expression) {
statement(s)
} else {
statement(s)
}

switch (integer expression) {
case constant integer expr:
statement(s)
break;

default:
statement(s)
break;
}

Exception handling

try {
statement(s)
} catch (exception type) {
statement(s)
} catch (exception type) {
statement(s)
} finally {
statement(s)
}

Goto statements

It is possible to put a label before any statement

myLabel: aJavaStatement;

The command

break;

terminate the current loop.

The label may be used to jump out of a inner for, while or do-loop

break myLabel;

A continue-expression terminates the current interation step and starts the next one

continue;

In addition with

continue label;

program control may be handed directly to an outer loop.

The statement

return;

terminates a method.

With

return aValue;

aValue may be given back to the calling method.

Primitive data types

Variable Type Description
byte 8-bit signed (two’s complement) integer
short 16-bit signed (two’s complement) integer
int 32-bit signed (two’s complement) integer
long 64-bit signed (two’s complement) integer
float 32-bit single-precision floating point (IEEE 754 standard)
double 64-bit double-precision floating point (IEEE 754 standard)
char 16-bit single Unicode character
boolean true or false

Characters use the 16-bit Unicode encoding. It contains all of the usual characters, but also includes character sets for many languages other than English, including Greek, Cyrillic, Chinese, Arabic, etc. Java programs can use all of these characters, although most editors do not have built-in support for character sets other than the usual ASCII characters. Arrays and strings are not primitive types: they are objects.

Versions

* JDK 1.0 1996, Solaris, Windows, MacOS Classic, Linux
* JDK 1.1 1997, Solaris, Windows, MacOS Classic, Linux
* JDK 1.2 1998, Solaris, Windows, Linux, ?
* JDK 1.3 2000 (also known as Java 2), Solaris, Windows, MacOS X, Linux
* JDK 1.4 2002, Solaris, Windows, MacOS X, Linux
* JDK 1.5 2003 (yet to be released)

Java was initially released as the Java Development Kit 1.0 (JDK 1.0). This included the Java runtime (the virtual machine and the class libraries), and the development tools (e.g. the Javac compiler). Later, Sun also provided a runtime-only package, called the Java Runtime Environment (JRE). The first name stuck, however, so usually people refer to a particular version of Java by its JDK version (e.g. JDK 1.4). The JDKs of version 1.2 and later versions are often called Java 2 as well. For example, the official name of JDK 1.4 is The Java(TM) 2 Platform, Standard Edition version 1.4.

The language as such has been stable since JDK 1.0; the class libraries that come with the JDK got larger and have changed in some parts. Extensions and architectures closely tied to the Java programming language include: J2EE, J2ME, JNDI, JSML, JDBC, JAIN, JDMK[?], Jini[?], Jiro[?], JXTA, JavaSpaces[?], JMI[?].

1.5 (codename[?] Tiger) is scheduled to be released in late 2003. Major changes include:

* Generics – Provides compile-time type safety for collections and eliminates the drudgery of casting.
* Autoboxing/unboxing – Eliminates the drudgery of manual conversion between primitive types (such as int) and wrapper types (such as Integer).
* Metadata – Lets you avoid writing boilerplate code, by enabling tools to generate it from annotations in the source code. This leads to a “declarative” programming style where the programmer says what should be done and tools emit the code to do it.

(from [1] (http://java.sun.com/features/2003/05/bloch_qa))

Interpreted version

There is an interpreted version of Java called beanshell which may be used as a shell scripting language. The interpreter may be embedded in a Java application to make it scriptable.

A good starting point for learning Java is the Sun tutorial on Java Programming, found at http://java.sun.com/docs/books/tutorial/.

Another very helpful page for beginners and experts alike is the current Java Syntax page for the latest Java API, Java 2 v1.4.2, also from the Sun site, found at http://java.sun.com/j2se/1.4.2/docs/api/

See also

* Java platform
* Java API
* Java virtual machine
* gcc (includes a Java to machine language compiler)
* Comparison of Java to C++.
* JINI
* Eclipse (Open source IDE)
* NetBeans (Another open source IDE)
* Optimization of Java

PHP programming language

Posted by admin | Systems Applications | Tuesday 22 December 2009 12:46 am

The computer language PHP (originally “Personal Home Page”, but now a recursive acronym for “PHP Hypertext Preprocessor”) is a widely used open-source programming language used primarily for server-side applications, to develop dynamic web content such as the Wikipedia software. It can be seen as an open source alternative to Microsoft’s Active Server Pages (ASP) system and to the similar CGI/Perl system.

Its ease of use and similarity with the most common structured programming languages, most notably C, Java and Perl, allows most experienced programmers to start developing complex applications with a minimal learning curve. It also enables experienced developers to get involved with dynamic web content applications without having to learn a whole new set of functions and practices.

One of the more attractive parts of PHP is that it is not only a scripting language. Because it has been designed from the start to be modular, the PHP core system has been used to develop desktop applications that are close to the same performance as traditional C++ compiled applications, and it can be used from the command line just like Perl or Python.

PHP allows, among other things, easy interaction with a very large number of relational database systems (Oracle[?], DB2, MySQL, PostgreSQL, etc.), while maintaining a simple and straightforward syntax. PHP runs on every major operating system, including Unix, Linux, Windows, and Mac OS X and can interact with all major web servers. The PHP website (php.net) has some of the best documentation pages of any project, and has lots of help with setting up PHP on obscure operating systems and web-servers. The Linux, Apache, MySql, PHP (LAMP) architecture has become very popular in the industry for deploying reliable, scalable and secure web applications.

PHP is the result of the collective efforts of many contributors. It is licensed under a BSD-style license, the PHP license (http://www.php.net/license/3_0.txt).

Table of contents
1 PHP’s Libraries
2 History
3 Popularity of PHP
4 Related Articles
5 External Links

PHP’s Libraries

PHP, unlike ASP and Perl, has some of the largest free and open-source libaries included with the core build. PHP is a fundamentally internet-aware system and as such there are modules built in for accessing FTP servers, all manners of database servers, LDAP servers and much more. What’s more the most used functions such as printf(), str_replace(), preg_match() from C are all available from PHP.

PHP has a wide variety of extensions such as support for the Windows API, Process Management on Linux, cURL support, ZIP and GZip support. Some of the more unique features are PDF generation, Shockwave Flash generation (on the fly), integration with IRC and much more besides.

History

PHP was originally designed as a wrapper around Perl by Rasmus Lerdorf in 1994 to display his resume information, and collect some data, such as how many hits it was generating. Others first used “Personal Home Page Tools” in 1995, which Lerdorf had combined with his own Form Interpreter to create PHP/FI. Zeev Suraski and Andi Gutmans rewrote the parser in 1997, forming the basis of PHP 3. They also changed the name to its current recursive form. After months in beta, the development team officially released PHP/FI 2 in November 1997. Public testing of PHP 3 began immediately and the official launch came in June 1998. Suraski and Gutmans started a new rewrite of PHP’s core, producing the Zend engine in 1999. In May 2000, PHP 4 powered by the Zend Engine was released. Development continues toward PHP 5 with Zend Engine 2.

Popularity of PHP

PHP is one of the most popular server-side scripting systems on the Web. It’s been widely adopted since the release of version 4, which was the first version powered by the powerful Zend Engine from Zend Technologies[?].

According to Netcraft’s (http://www.netcraft.com/info) April 2002 survey, PHP is now the most-deployed server-side scripting language, running on around 9 million of the 37 million sites in their survey. This is confirmed by PHP.net’s own figures (http://www.php.net/usage.php), which show PHP usage measured on a per-domain basis growing at around 5% per month.

PHP is not, however, the most commonly used tool if measurements are made on a per-page basis. Another estimate in March 2002, based on searching for Web pages by their suffix, places PHP in second place at 30% of measured pages, behind 48% using Microsoft’s ASP, but also shows PHP growing rapidly in market share. However, this method is notoriously inaccurate for measuring PHP popularity as some PHP systems dispense with the file names, using only directories.

15 Exercises for Learning a new Programming Language

Posted by admin | Systems Applications | Tuesday 22 December 2009 12:45 am

I’ve working knowledge of a bunch of programming languages but job demands to learn a new language frequently in a short time. Instead of reading hundreds manual/book pages, I quickly read 10-15 pages of tutorial or primer. (As you know google is the best search engine to look for such stuff). I keep printed copy of the language syntax reference card handy. (There are many reference cards available over internet. Type in ’language to learn’ + ’reference card’ in google.)

First of all, get familiar with Compiler, compiler option, editor shortcuts or integrated development environment (IDE). Start with a simple ’Hello World’ program. Compile it. Use basic functionalities of debugger like setting break points, printing variable values, moving to the next or specific position, stopping debugger etc.

To grasp basics of a new language quickly, here are the exercises I use. Remember some programs may not good for beginners.

(1) Display series of numbers (1,2,3,4, 5….etc) in an infinite loop. The program should quit if someone hits a specific key (Say ESCAPE key).

(2) Fibonacci series, swapping two variables, finding maximum/minimum among a list of numbers.

(3) Accepting series of numbers, strings from keyboard and sorting them ascending, descending order.

(4) Reynolds number is calculated using formula (D*v*rho)/mu Where D = Diameter, V= velocity, rho = density mu = viscosity Write a program that will accept all values in appropriate units (Don’t worry about unit conversion) If number is < 2100, display Laminar flow, If it’s between 2100 and 4000 display ’Transient flow’ and if more than ’4000’, display ’Turbulent Flow’ (If, else, then…)

(5) Modify the above program such that it will ask for ’Do you want to calculate again (y/n), if you say ’y’, it’ll again ask the parameters. If ’n’, it’ll exit. (Do while loop)

While running the program give value mu = 0. See what happens. Does it give ’DIVIDE BY ZERO’ error? Does it give ’Segmentation fault..core dump?’. How to handle this situation. Is there something built in the language itself? (Exception Handling)

(6) Scientific calculator supporting addition, subtraction, multiplication, division, square-root, square, cube, sin, cos, tan, Factorial, inverse, modulus

(7) Printing output in different formats (say rounding up to 5 decimal places, truncating after 4 decimal places, padding zeros to the right and left, right and left justification)(Input output operations)

(8) Open a text file and convert it into HTML file. (File operations/Strings)

(9) Time and Date : Get system time and convert it in different formats ’DD-MON-YYYY’, ’mm-dd-yyyy’, ’dd/mm/yy’ etc.

(10) Create files with date and time stamp appended to the name

(11) Input is HTML table, Remove all tags and put data in a comma/tab separated file.

(12) Extract uppercase words from a file, extract unique words

(13) Implement word wrapping feature (Observe how word wrap works in windows ’notepad’)

(14) Adding/removing items in the beginning, middle and end of the array.

(15) Are these features supported by your language: Operator overloading, virtual functions, references, pointers etc.

Is there something called ’namespace / package / module’ supported by your language? (Name mangling) -

10 Most Bizarre Programming Languages Ever Created

Posted by admin | Systems Applications | Tuesday 22 December 2009 12:42 am

There is nothing more frustrating for a web developer than spending hours at a time fixing a bug that should just work. Often I’ll get stuck in a programming state that feels like I have absolutely no idea what I’m doing, as if the language I’m using (CSS, PHP, whatever), is actually a foreign language.

1. Ook!
If you’ve ever felt like a monkey just banging away at a keyboard, then Ook! will make you feel right at home. It’s a language designed primarily for primates, specifically the orangutan. With Ook! you only use three syntax elements:

* Ook.
* Ook?
* Ook!

Here are a few examples of Ook! in action:

1. Ook. Ook?
2. Move the Memory Pointer to the next array cell.

Ook. Ook?
Move the Memory Pointer to the next array cell.

1. Ook? Ook.
2. Move the Memory Pointer to the previous array cell.

Ook? Ook.
Move the Memory Pointer to the previous array cell.

1. Ook. Ook.
2. Increment the array cell pointed at by the Memory Pointer.

Ook. Ook.
Increment the array cell pointed at by the Memory Pointer.

1. Ook! Ook!
2. Decrement the array cell pointed at by the Memory Pointer.

Ook! Ook!
Decrement the array cell pointed at by the Memory Pointer.

1. Ook. Ook!
2. Read a character from STDIN and put its ASCII value into the cell pointed at by the Memory Pointer.

2. Piet
For those appreciative of fine art, Piet is a language that you’ll surely enjoy. Inspired by the abstract artist Piet Mondrian, Piet is a programming language that converts programs into abstract geometric paintings. Programs are made up of 20 different colors, and then read by the compiler based on hex values to run a program.Check out some of the crazy examples that Piet programmers have come up with.

3. Whitespace
Unfortunately, the name for this programming language is exactly what it does: Whitespace creates programs based off of… whitespace. The Whitespace website has a great description of how the language works.

Most modern programming languages do not consider white space characters (spaces, tabs and newlines) syntax, ignoring them, as if they weren’t there. We consider this to be a gross injustice to these perfectly friendly members of the character set. Should they be ignored, just because they are invisible? Whitespace is a language that seeks to redress the balance. Any non whitespace characters are ignored; only spaces, tabs and newlines are considered syntax.

. LOLCODE
LOLCODE is my personal favorite among esoteric languages. The language is based off of the LOLCats phenomenon, and uses LOLCats syntax to make programs run. Or something like that.Just looking at a sample bit of an LOLCODE program will explain why it’s a fan favorite.
view plaincopy to clipboardprint?

1. HAI
2. CAN HAS STDIO?
3. PLZ OPEN FILE “LOLCATS.TXT”?
4. AWSUM THX
5. VISIBLE FILE
6. O NOES
7. INVISIBLE “ERROR!”
8. KTHXBYE

5. Shakespeare
Shakespeare is not as simple as LOLCODE to wrap your head around. In case you haven’t figured it out yet, Shakespeare is a programming language based on the writings of the great playwright. Each program contains a title, acts, scenes and characters to make brilliant source code that’s actually fun to read.Here’s Act I, Scene I of “Hello World”:
view plaincopy to clipboardprint?

1. The Infamous Hello World Program.
2.
3. Romeo, a young man with a remarkable patience.
4. Juliet, a likewise young woman of remarkable grace.
5. Ophelia, a remarkable woman much in dispute with Hamlet.
6. Hamlet, the flatterer of Andersen Insulting A/S.
7.
8. Act I: Hamlet’s insults and flattery.
9.
10. Scene I: The insulting of Romeo.
11.
12. [Enter Hamlet and Romeo]
13.
14. Hamlet:
15. You lying stupid fatherless big smelly half-witted coward!
16. You are as stupid as the difference between a handsome rich brave
17. hero and thyself! Speak your mind!
18.
19. You are as brave as the sum of your fat little stuffed misused dusty
20. old rotten codpiece and a beautiful fair warm peaceful sunny summer’s
21. day. You are as healthy as the difference between the sum of the
22. sweetest reddest rose and my father and yourself! Speak your mind!
23.
24. You are as cowardly as the sum of yourself and the difference
25. between a big mighty proud kingdom and a horse. Speak your mind.
26.
27. Speak your mind!
28.
29. [Exit Romeo]

6. Befunge
The goal for Chris Pressey, creator of the Befunge programming language, was simple: Create a language that was as difficult to compile as possible. Befunge accomplishes this by the two main features of the daunting language:

1. Self modifying – the p instruction can write new instructions into the playfield; and
2. Multi-dimensional – the same instruction can be executed in four different contexts (in a left-to-right series of instructions, or right-to-left, or upward or downward.)

Regardless, there are very smart people, (with way too much free time), who have created compilers for Befunge.

7. reMorse
reMorse is a language intended to look like morse code. Visions of submarines and telegrams come to mind with this simple yet incredibly challenging language. Here’s the reMorse version of “Hello World”:
view plaincopy to clipboardprint?

1. – - – ..- …-.—.;newline
2. – - – .-. – ..-.- …-. —.;!
3. – - – …- . . -.—.;d
4. —-. . . -.—.;l
5. —-. . -…—.;r
6. —-. -…—.;o
7. —-…-.- ..-. —.;W
8. //author didn’t feel like doing this part
9. -…………..;output all characters

- – - ..- …-.—.;newline
- – - .-. – ..-.- …-. —.;!
- – - …- . . -.—.;d
—-. . . -.—.;l
—-. . -…—.;r
—-. -…—.;o
—-…-.- ..-. —.;W
//author didn’t feel like doing this part
-…………..;output all characters

This language might be a tad on the difficult side for the rest of us (with the exception of amateur radio specialists). You know it’s a bear to program when the author of the language won’t finish all of the basic example, due to complexity.

8. FALSE
With an appropriate negative connotation, FALSE is a language meant to discourage even the cleverest programmers. Based on the Forth language, FALSE uses a punctuation based syntax (gross!) to help sour the programming experience.From the FALSE creator himself:

I designed this language with two particular objectives: confusing everyone with an obfuscated syntax, and designing as powerful a language as possible with a tiny implementation: in this case a compiler executable of just 1024 bytes (!), written in pure 68000 assembler.

Yet FALSE isn’t the most ridiculous of the esoteric languages, and could actually serve real world purposes, as the operations are reasonably sensible and the language isn’t extremely complex. Maybe somebody, someday, will make a useful real-world application out of the language…

False.

9. Whenever
Imagine a surly teenager as a programming language, and you’ve got yourself Whenever. Whenever is a simple language that does what it wants, when it wants.

It takes the program code and treats each line as an item in a to-do list. The interpreter chooses an item from the list at random to execute, and executes the statement. In some cases, the statement will contain a clause that specifies that it cannot be executed until certain conditions apply. This results in the statement being deferred and placed back on the to-do list.

Don’t think for a minute you can actually control a Whenever program. Imagine how hard this makes programming something like “99 Bottles of Beer”! The program would return something that read like it had already consumed all 99.
view plaincopy to clipboardprint?

1. defer (4 || N(1)
2. defer (4 || N(1)==N(2)) print(“Take one down and pass it around,”);
3. defer (4 || N(2)==N(3)) print(N(1)+” bottles of beer on the wall.”);
4. 1#98,2#98,3#98;

10. l33t
Ever wanted to speak like a “l33t H4xX0r5″? Now you can by learning the l33t programming language. Check out the l33t “Hello World” application:
view plaincopy to clipboardprint?

1. // Note that the views expressed in this source code do not necessarily coincide with those of the author :o )
2.
3. Gr34t l33tN3$$?
4. M3h…
5. iT 41n’t s0 7rIckY.
6.
7. l33t sP33k is U8er keWl 4nD eA5y wehn u 7hink 1t tHr0uGh.
8. 1f u w4nn4be UB3R-l33t u d3f1n1t3lY w4nt in 0n a b4d4sS h4xX0r1ng s1tE!!! ;p
9. w4r3Z c0ll3cT10n2 r 7eh l3Et3r!
10.
11. Qu4k3 cL4nS r 7eh bE5t tH1ng 1n teh 3nTIr3 w0rlD!!!
12. g4m3s wh3r3 u g3t to 5h00t ppl r 70tAl1_y w1cK1d!!
13. I’M teh fr4GM4stEr aN I’lL t0t41_1Ly wIpE teh phr34k1ng fL00r ***j3d1 5tYlE*** wItH y0uR h1dE!!!! L0L0L0L!
14. t3lEphR4gG1nG l4m3rs wit mY m8tes r34lLy k1kK$ A$$
15.
16. l33t hAxX0r$ CrE4t3 u8er- k3wL 5tUff lIkE n34t pR0gR4mm1nG lAnguidGe$…
17. s0m3tIm3$ teh l4nGu4gES l00k jUst l1k3 rE41_ 0neS 7o mAkE ppl Th1nk th3y’r3 ju$t n0rMal lEE7 5pEEk but th3y’re 5ecRetLy c0dE!!!!
18. n080DY unDer5tAnD$ l33t SpEaK 4p4rT fr0m j3d1!!!!!
19. 50mE kId 0n A me$$4gEb04rD m1ghT 8E a r0xX0r1nG hAxX0r wH0 w4nT2 t0 bR34k 5tuFf, 0r mAyb3 ju5t sh0w 7eh wAy5 l33t ppl cAn 8E m0re lIkE y0d4!!! hE i5 teh u8ER!!!!
20. 1t m1ght 8E 5omE v1rus 0r a Pl4ySt4tI0n ch34t c0dE.
21. 1t 3v3n MiTe jUs7 s4y “H3LL0 W0RLD!!!” u ju5t cAn’T gu3s5.
22. tH3r3’s n3v3r anY p0iNt l00KiNg sC3pT1c4l c0s th4t, be1_1Ev3 iT 0r n0t, 1s whAt th1s 1s!!!!!
23.
24. 5uxX0r5!!!L0L0L0L0L!!!!!!!

In real life, l33t is “teh sUxX0r” due to the fact that you can’t use it for anything useful. Ah well, back to hacking with all the other script kiddies and trolls!

What Makes a Good Programming Language?

Posted by admin | Systems Applications | Tuesday 22 December 2009 12:35 am

There are plenty of programming languages around. David Chisnall points out the various factors that determine what makes a “good” language. But note his caveat: These principles don’t always apply in any given set of circumstances!
What Is a Programming Language?

Programming languages, like spoken languages, are ways of communicating ideas. When two people who know the same language talk, they’re able to understand each other because they both know the rules that formalize how to translate sounds into meaning and vice versa.

Computers don’t understand human languages. Worse, the languages they do understand—their instruction sets—don’t mesh very well with how most humans speak. Imagine for a moment a French person talking to a Chinese person. Neither of them understands the other’s native language, but if they speak a common second language, such as English, they can still talk to each other. This is more or less the situation when it comes to programming languages.

The English skills of the speakers in that last example also have direct parallels in terms of programming languages. When you have one person speaking and another person listening, comprehension depends on two things:

* The speaker’s ability to translate ideas into the language
* The listener’s ability to translate the spoken words into ideas

The speaker’s ability is equivalent to the programmer’s skill, and the listener’s ability is equivalent to the compiler’s efficiency.

A programming language is a compromise. Translating a language such as English directly into a machine language is very difficult for a machine. Similarly, “speaking” a machine language well is very difficult for a human. A programming language is one that a human can speak reasonably well, and that a computer can translate into a language that it understands.
Language, Framework, and Runtime

Most languages are very small; for example, C contains only about 20 keywords. They control the flow of a program, but do little else. Writing a useful program using just the C language is almost impossible. Fortunately, the designers recognized this problem. The C language specification also defines some functions that must be available for C programs to call. The majority of these functions, known together as the C Standard Library, are themselves written in C, although a few primitive ones may need to be written in some language that’s yet more primitive.

Most languages have some kind of equivalent to the C Standard Library. Java, for example, has an enormous catalogue of classes in the java.* namespace that must be present for an implementation of the language to be called “Java.” Twenty years ago, Common Lisp had a similarly large collection of functions. In some cases, the language is most commonly used with a collection of libraries, usually referred to as a framework, that are specified separately from the language itself.

Sometimes the line between language and framework is blurry. It’s clear that C++ and the Microsoft Foundation Classes are separate entities, for example, but for Objective-C the distinction is less clear. The Objective-C specification defines very little by way of a standard library. (Although, because Objective-C is a proper superset of C, the C Standard Library is always there.) Objective-C is almost always used in conjunction with the OpenStep API; these days, the common implementations are Apple’s Cocoa and GNUstep.

When you start adding libraries to a language, you lose some of the clarity of what makes the language unique. Writing an OpenGL program in Java has a lot more in common with writing an OpenGL program in C than it does with writing a Swing application in Java.

Another source of confusion is the runtime system. Languages such as Smalltalk and Lisp were traditionally run in a virtual machine (although most current Lisp implementations are compiled into native machine code). This requirement can lead people to perceive a given language as slow. Interpreted code is almost always slower than compiled code. This doesn’t have anything to do with the language, but it is important. Code run in a Lisp interpreter will be much slower than compiled Lisp code.

When judging a language, it’s important to differentiate between characteristics of a language and characteristics of an implementation of the language. Early implementations of Java were very slow; the just-in-time compiler was little better than an interpreter. This led to people calling Java an “interpreted language.” The GNU project’s Java compiler destroyed this myth, although other design decisions in the Java language still prevent it from being run as fast as some other languages.

There are plenty of programming languages around. David Chisnall points out the various factors that determine what makes a “good” language. But note his caveat: These principles don’t always apply in any given set of circumstances!
Speed

How do you measure the speed of a language? The obvious way is to write some algorithms in it, run them, and see how long they take to execute. For the most part, this is a good, pragmatic solution. There are a few potential pitfalls, however:

*

Selecting the correct compiler. If you’re evaluating Lisp, for example, it wouldn’t be fair to benchmark an interpreted version of Lisp against compiled C++ or just-in-time compiled Java. But it would be fair to compare these languages with something like Perl, Ruby, or Python, in which the default (supported) implementation runs interpreted bytecode.
*

The fastest compiler isn’t always the correct one for your needs. For some time, the Microsoft Java runtime was the fastest implementation available. If you were looking for a language for cross-platform development, however, it would have been a mistake to select Java just because the Microsoft runtime was fast.

Be aware of the platform you’re targeting when you decide on a compiler. If you’re writing cross-platform code, you may want to standardize the compiler (or runtime) across all of your supported platforms to ensure that you have a minimum of issues from varying levels of language support across implementations. In this case, you might choose something like GCC, which is likely to produce code that’s slower than a compiler written for a specific architecture. Be sure to take this factor into account when performing a speed evaluation. Just because IBM’s XLC or Intel’s ICC produces faster code from C than whatever other language you’re evaluating, that doesn’t mean that you can always benefit from this speed

At the opposite extreme, you might need to support only one platform. In this case, you’re free to choose the best implementation available for that platform. Make sure that you do this for all of the languages you evaluate, however. It’s easy to read benchmarks showing that the Steel Bank Common Lisp compiler produces code that runs faster than C++ code, and miss the fact that it performs somewhat worse on register-starved architectures such as x86. If you’re targeting x86, this is an important factor.
*

Don’t place too much faith in micro-benchmarks. It’s quite easy to design an algorithm that plays to the strengths of a particular implementation—or to its weaknesses. Something that requires a lot of array accesses, for example, is likely to cripple Java’s performance. Something that requires a high degree of concurrency is likely to show off Erlang’s strengths. When you look at micro-benchmarks, try to imagine where you would use algorithms like the ones described in your own application. If you can’t, then disregard them.
*

Remember that speed isn’t always important. The CPU usage graph on my machine could almost be described as having two states: one showing 20% usage, and the other showing 100% usage. If you’re writing the kind of application that will contribute to the 20%, then you would be hard-pressed to select a language that the end user would notice was slow. If you’re writing an application that uses as much processing power as you can throw at it, or an embedded application in which processing power is still expensive, speed is a very important consideration.

There are plenty of programming languages around. David Chisnall points out the various factors that determine what makes a “good” language. But note his caveat: These principles don’t always apply in any given set of circumstances!
Expressiveness

The Church-Turing thesis is one of the foundation stones of computer science. It tells us that any programming language that can simulate a Turing Machine can be used to implement any algorithm. But this doesn’t tell us much about a language beyond a simple yes or no answer to the question “Is this language Turing-complete?” In almost all cases, the answer is yes; few useful languages are not Turing-complete. One example is Adobe’s Portable Document Format (PDF), which began life as a non-Turing-complete subset of PostScript. This was created so that the time required to render (and hence print) a document was bounded by its size. PostScript contains loop constructs that PDF lacks, and so it’s possible for a PostScript program never to terminate.

Anyone who has criticized C will be familiar with the defense “but you can implement that in C!” This is true, of course. Any Turing-complete language can be implemented in any other. Prolog, for example, can be implemented in about 20 lines of Lisp. If you write a program requiring 1,000 lines of Prolog and include with it a 20-line Prolog interpreter written in Lisp, is it fair to call it a Lisp program?

The same principle applies in many other languages. The Objective-C runtime is usually implemented in C, so obviously you can do anything in C that you can do in Objective-C. The question is whether this practice makes sense. Is it more sensible to write your own dynamic object system, or to use one that other people are working on and constantly optimizing?

Of course, we’re assuming that the features you would need to implement are actually useful. If a language lacks a feature that isn’t useful anyway, that’s not a limit to its expressiveness.

A good question to ask is how many language features you have to throw away to gain a useful feature. In Smalltalk, you send messages to objects. This is the equivalent of calling methods in a language such as C++ or Java. If the object doesn’t have an explicit handler for that message type, then the runtime system delivers this message and its arguments to the object’s doesNotUnderstand: method. This setup allows for a lot of flexibility in programming.

Consider Java’s RMI mechanism. Each class to be exposed through RMI must be run through a preprocessor that generates a proxy class, which passes the name and arguments of each method through to the RMI mechanism. In Smalltalk (or Objective-C, for that matter), you don’t need to do all this. You can just create a single proxy class that implements the doesNotUnderstand: method and passes the message to the remote class. This one class can be used as a proxy for any other class.

If you wanted to implement something comparable in C++, however, you would need to throw away the C++ method-call mechanism and replace it with your own custom message-passing system. Each C++ class would implement a single handleMessage() method, which would then call the “real” methods. By the time you’ve done this, you’ve thrown away a lot of the convenience of using C++ in the first place.

here are plenty of programming languages around. David Chisnall points out the various factors that determine what makes a “good” language. But note his caveat: These principles don’t always apply in any given set of circumstances!
Readability

Sometimes you can write code that gets used for a bit and then thrown away. Most of the time, you aren’t so lucky. Eventually you have to go back and read it, or someone does. If you know you’re leaving the company soon, and you hate your coworkers, you might consider a language like Intercal or C++, with baroque syntax and even more peculiar semantics. On the other hand, if there’s a chance that you might be stuck maintaining the code, or you want to be able to show it to other people without hanging your head in shame, the readability of the language is important.

A lot of factors go into determining whether a language is readable. The most obvious is familiarity. The human mind is very good at adaptation, and often it’s astonishing what the mind will perceive as “normal.” Familiarity only comes from constant exposure, though, which means that languages with relatively simple syntax become familiar more quickly. Lisp is at one extreme, with only one syntactic construct. It’s very easy to become familiar with Lisp, although grasping the large Common Lisp standard library is another matter. C++ is the popular language at the other extreme. Most C++ coders I have encountered use only a relatively small subset of the C++ language. Worse, everyone uses a slightly different subset, so C++ code written by other people may be quite difficult for you to read, even though you’re familiar with the language.

Another aspect of readability is the syntax itself. This is where Smalltalk-like languages tend to win. Since Objective-C allows the use of syntax that works for both C and Smalltalk, it’s a good language for an example. Apple provides a set of objects that are “toll-free bridged” between C and Objective-C. This means that a set of C functions are passed the Objective-C object as an opaque data type, so you can directly manipulate the Objective-C objects without having to translate them into some other form. This approach makes them ideal for a syntax comparison:

[array insertObject:anObject atIndex:12];
CFArrayInsertValueAtIndex(array, 12, anObject);

Both of these lines accomplish the same thing: inserting anObject into array at index 12. To understand this result from the first line above, you need to understand that the Objective-C message-passing syntax specified an object and then a list of parameter name:parameter pairs. To understand this result from the second example, you need to know how C function-calling works, that it’s conventional for the first argument in functions of this type to be the data structure being manipulated, and that the author of the function decided that the arguments for the function should be passed the opposite way to how they occur in the function name.

In this particular example, it’s quite easy to spot that 12 is the index, if you know that arrays are indexed by numbers. Now imagine that both arguments were variable names.

Of course, the biggest impact on readability comes not from the language, but from the developer. A poor developer can write illegible code in any language. A good developer? I’ve even seen well-written, readable Visual Basic code. (Once.)

here are plenty of programming languages around. David Chisnall points out the various factors that determine what makes a “good” language. But note his caveat: These principles don’t always apply in any given set of circumstances!
Summary

A lot of factors go into determining what makes a good language, and they don’t always apply in any given set of circumstances. A good language for a particular task may be a particularly bad choice in another situation. A good programmer will always pick the right tool for the job.

Shell Programming in Expert Systems Applications

Posted by admin | Systems Applications | Sunday 20 December 2009 11:23 pm

Artificial Intelligence Programs Use Shells to Interpret Data
Expert systems applications use small artificial intelligence programs called shells to interpret human knowledge. Shell programming requires quality data for success.

Expert Systems are artificial intelligence programs that apply logical arguments to a knowledge-base. Prior to the use of expert systems, and other AI applications, the data in a knowledge base could only be interpreted and used by the human brain. The use of expert systems provides a means to access and utilize the information stored without the need for human involvement. These systems, which use small processes called shells, have limitations, but can provide benefits to the business world, particularly in the area of Help-desk technology.

Shells in ES Software

ES Software typically contains shells for each domain of knowledge in the knowledge-base system. For example, in a Help-Desk Expert System, one shell might encompass all of the knowledge needed to solve the problem if an Internet user called in to ask for help with non-functioning Internet connection. Within one shell is all of the information needed to troubleshoot a DSL connection. The shell also contains a user interface, that asks questions to lead the shell to the correct conclusion. In between the user interface and the stored data is an inference engine, which decides which questions are appropriate, based on information already received.

In this example, the first question asked by the shell might be, “Is the modem’s power light on?” If the user responds negatively, the shell can conclude, with some degree of certainty, that the problem is due to a lack of power to the DSL modem. If the user responds that the power light is on, the shell can assume that the problem is not due to a lack of power. At that time, the shell will automatically rule out all possibilities that include power problems.

With each ensuing question and answer, the shell uses a previously identified set of rules to eliminate more potential answers, until reaching a conclusion based on the information provided and the rules set forth by the programmers.

Limitations of Expert Systems Applications

The limitations of expert systems applications lie in the input received. ES Software does not learn from experience, as a Neural Network does. An expert system receives knowledge as data input by experts, so the conclusions it reaches are only as good as the data it has been programmed with. In addition, in order to solve problems, it relies on answers and information received from a user. If the user enters inaccurate information, the expert system is unable to compensate for it. Finally, the rules set forth by the programmer influence the results reached by the shell.

An expert system is a perfect example of the phrase, “Garbage In, Garbage Out”. While expert systems have limitations, they are beneficial when executed carefully. If the information provided to the program is accurate, and the rules used to reach conclusions are logical, the shells can work together to reach logical conclusions for any situation they are programmed to address.