Programming FAQ

Status
Not open for further replies.

Iron_Cross

Daemon Poster
Messages
549
Location
Bamberg, Germany
Programming FAQ v1.2.13

We often see people asking the same question over and over, "How do I learn to program, and where do I start?" Some people may take that question to the next level by asking, "Which language should I learn first?" The answer to those questions is fairly simple, but also a little subjective. So weÂ’re going to attempt to help solve those very valid, logical questions.

How do I program?
Programming is the act of giving the computer information and directions to complete a certain task. Most often programming is achieved by typing in a certain "Programming Language" into a normal text editor, then compiled (or 'made' into machine language that the computer can understand) into native or interpreted code, which I'll explain soon. There are also several programs that are called IDE's or Integrated Development Environments. These are useful in several aspects. For one, they look similar to a normal text editor, but they color coordinate your code, to make it easier to read at a glance. They can also perform automated tasks for you that ease up the amount of typing you have to do. They also provide a single area to write, compile, link, test, and run your programs, without having to use several different utilities. This a big help when it comes to large projects. Keep in mind, you are not forced to use an IDE, it just makes your job, as the programmer, much easier. Now, you can't just use any IDE you want, most often, IDEs are specialized for a certain language. Search for the proper one for your language (programming language, not spoken).

How do I learn to program?
Reading and practicing. That is the short and sweet answer. Search the internet, at places such as google, yahoo, dogpile, lycos, hotbot, and any other popular search engines for tutorials and books on the specific language you are trying to learn. I also recommend buying a book, books will help tremendously. You could go down to your local book store, or search amazon.com for a specific book. I don't recommend going to your library, because you will be forced to read and 'cram' the knowledge into your head, which is not good. Plus libraries rarely have up-to-date versions of the books you need. With the rapid development and updates of programming languages today, you need to find the most recent edition of a book you can, or you may miss out on valuable information. I have also added a few simple resources at the end of each section to help you find the information you need.

What all can I do with [Insert Language]?
The possibilities are limitless. So long as you're a creative person, you can do just about anything. Of course some languages are better suited for certain tasks, but still. If you've got the will, it's possible. To see what languages are good for your task, see the below sections.

How long does it take to learn to program?
This is very hard to answer. Some small scripting languages you can pick up in a few hours. Other major languages, such as C++, you may be able to grasp the basics within a few days or weeks, but would take years to fully master. It all depends on how dedicated you are, how well you learn concepts, how much time you spend reading learning and practicing, as well as which language(s) you choose to learn.

What language is best?
There really is no telling. Some languages are better suited for some tasks, while other languages are better for other tasks. For instance, you wouldn't use C++ for a web based application, you'd probably choose a web scripting language, or Java or Perl. Each language has its own strengths and weaknesses, which brings me to the next question.

What is OOP (Object Oriented Programming) and should I learn it?
Object Oriented Programming, or OOP for short, is a programming paradigm that says everything is a unique object. You build applications with "objects". Such as, you'd build a car with different unique "parts", the same is true with a program. You as the programmer are responsible for "making" each part (Actually making a blueprint of the part) then putting them together to do something useful. Procedural programming is mentioned a lot when you hear of OOP, Procedural programming is where you program by making a "to-do list" for the computer, which it then goes down the list. Being that many applications and companies are using OOP as a standard itÂ’s a must learn. This is not to say that procedural is wrong, or even not used, procedural languages are still used heavily on UNIX systems as well as many games and commercial applications. All in all, learning a programming language that implements OOP is definitely not going to be a waste of your time, though it's not required.

Which language should I learn first?
The only way to answer this is to know why you want to program. Each language has its strengths and weaknesses. Here is a VERY short rundown of some popular major languages:

C - Perhaps one of the most famous programming languages. C is robust, procedural (as apposed to Object oriented) extremely fast language. C is used in many commercial games and applications because of it's speed. Yet C also it's drawbacks, being that it's not object oriented, and there are many languages that could do C's job, only slower. But with today's market for productivity and such amazing computers, the speed difference is slowly slipping away. Many people ask if they should learn C before tackling C++, the answer is that you don't have to. Some would even say it's not very good for you to. I stand in between, if you learn C first, it might be a little easier, but you'll have to unlearn a lot when you move to C++. Personally, I think they are equally challenging, so I would say to go ahead and learn C++ if that's your goal, but that's just my opinion.

Pros:
-- Large usage base. Easy to find help, other programmers, libraries etc.
-- Small core language, with further functionality being added through the use of libraries.
-- Very powerful. If your computer can do it, it can do it through C.
-- Low-level unchecked access to computer memory using of pointers.
-- One of the fasted running languages.
-- C code can be used in C++ applications.
-- Programs are compiled and stand alone, no need for interpreters (sometimes external libraries will need to be installed on the target PC).

Cons:
-- Relatively difficult to learn.
-- Very little safety net. If you choose (accidentally or otherwise) to make a program that will access memory incorrectly and horribly break your system, it won't stop you. It only pulls you up on compile errors.
-- Non trivial programs could be hard to port. Programs have to be compiled for each specific platform.
-- Code can get messy easily.

Resources:
Tutorial


C++ - A very powerful, and a very 'complete' language. C++ is an Object Oriented Programming (or OOP) which has some VERY good qualities to it. It has strengths such as speed, performance, and flexibility. But it's weaknesses consist of it being overwhelming to new programmers, and it is not platform independent. C++ code can easily get very complex, yet it's performance normally makes up for this. C++ is mainly used for many desktop applications, such as many of those run on Microsoft Windows and other Operating Systems, and some games (such as Quake III). This is a very nice language, yet extremely large and complex. Tackle this language if you need a fast application and are willing to WORK at it.

Pros:
-- As close to a universal programming language as you're likely to get at the moment. It's used everywhere.
-- Object oriented technology included, highly supported and recommended, but not forced upon you.
-- Programs are stand alone, no need for interpreters (sometimes external libraries will need to be installed on the target PC).
-- Easy to port to other platforms if standard C++ guidelines are adhered to.
-- Many libraries available for added functionality.

Cons:
-- Quite difficult to learn. You'll never really stop learning new things about it (which is also a pro, I guess)
-- Non-trivial programs aren't easily ported
-- Programs can be slightly larger and slower than those programmed in C.

Resources:
About
Tutorial
Info, Tutorials, etc
Compiler/IDE



Java - Java is actually my favorite language, tied by C# (see below). Some hate it, some swear by it. Its syntax is very similar to C++ syntax, yet it is much simpler due to the fact that its creators decided to leave out the complex features of C++. Java is a very flexible and powerful language, but is slower than C++. Java is a partially interpreted language, which means its code is not completely compiled into native machine code but instead compiled into byte code interpreted by the runtime environment. And because of this it runs slower, yet is platform independent, meaning you can write one program and run it on nearly any operating system that has a Java Runtime Environment (JRE). Java code is much shorter, and easier to learn than C++ (in my opinion). Java is also 'pure' OOP. Which has some major strengths. Major improvements are being made to eliminate Java's speed problems, and we hope java code will be just as fast as native C++ code. Some improvements include optimizations, and the ability to compile into complete native machine code, yet you will lose some portability, or platform independency. Java is used a lot on the web, and networks, but can also be used to make windowed applications as well.

Pros:
-- Java is platform independent; it can be run on everything.
-- It's free; you can just download the SDK and go.
-- It's easy to learn if you know C or C++.
-- Provides automatic memory management.
-- Large library of pre-built classes and many more available from around the net
-- It's quite safe. It's fairly hard (if not impossible) to damage your computer through programming in Java.

Cons:
-- Speed. Java is quite slow, because it is essential compiled at run-time by the system's virtual machine.
-- Difficult to compile into a stand-alone application.
-- Explicit memory management is not allowed
-- Some people dislike being forced into object oriented programming.

Resources:
Info, Tutorials, Compilers, etc
IDE
Free IDE
Another Free IDE


C# - Pronounced See-Sharp, this language would be tied for first on my favorites list. C# derives much of it's syntax from Java, and C++. Some have referred to C# as the "Java-Killer" because it's similar to an enhanced version of Java. Instead of taking out the complex features of C++, the C# creators decided to allow the programmer to use them, but not make it mandatory. C# is a master at building Windows applications on the .NET Framework. Similar to Java, C# compiles it's code into an IL code, or Intermediate Language (much like Java's ByteCode), which is then compiled and interpreted by the CLR, Common Language Runtime (akin to Java's Java Virtual Machine). This in turn produces native, efficient machine code. C#'s speed doesn't necessarily suffer as much as Sun's Java does. But in some instances, such as trig. math, Java kicks the snot out of C# (said with respect for both languages). All in all, C# is (as of now) a much less portable language than Java, but has many more features, and possibilities, in my opinion, than Java. Microsoft claims to be working on porting the .NET runtime to other OSs, but no promises. So far the Mono Project has brought the .NET runtime to GNU/Linux which is a great step given C#'s power.

Resources:
Info, Tutorials, etc
Compiler/SDK
Tutorials
Tutorials/Help
Info/Tutorials
IDE



.Net Environment - Not really a programming language, but closely related.
The .Net environment is a relatively new creation of Microsoft's. It adds an overall cohesiveness to various programming languages by compiling them into a standard form that is interpreted by an intermediate language between the code and the OS. In this way it is similar to Java. The creation of the .Net environment means that the method of programming basically comes down to personal preference.

Pros:
-- Easy-to-use tools may increase programmer productivity
-- Has a strong framework for building rich graphical user interfaces
-- Gives developers choice of working in more than 20 programming languages
-- Is tightly integrated with Microsoft's operating system and enterprise server software
-- Has built-in support for Web services standards

Cons:
-- Framework runs only on Windows
-- Users of prior Microsoft tools and technology face a potentially steep learning curve
-- Choice of integrated development environments is limited
-- Getting older applications to run in new .Net environment may require effort



VisualBasic/VB.NET - Most people don't care for VB all too much, yet it is used very widely in the job industry. The main reason for people not liking this language is the fact that projects could become VERY unreadable and unmanageable when they extend past a few pages of code. The major reason VB is being used is because of it's time-to-market aspect, meaning it only takes a short while to create, debug, and market your applications. You could make a Windows or web application in VB VERY quickly. VB is also a very easy language to learn. The drawbacks are that it teaches bad programming practice habits and syntax. If you do decide to start with VisualBasic or QBasic or Basic (or any other of the *Basic languages), move on to something else as soon as you get moderately comfortable with the language and idea of programming.
Visual Basic is a very easy language to use. It's code is similar to Pseudo-code, and many times the developer can simply type what they think should work and it does. Which is cool.

Pros:
-- Very easy to learn
-- Quick to implement an application or algorithm
-- Lots of in-built functionality
-- Recently added complete OOP support with the .Net upgrade.

Cons:
-- Not as flexible as other languages. Can't do as much.
-- Runs slower than C/C++
-- Purely a Microsoft product and Windows based.


Python - Python is a relatively small language, but very powerful. Compared to Java or C++ it takes no time at all to create a program. For example to create a small program that prints the string "Hello World!" to the screen, compare these three languages:

In C++:
Code:
#include <iostream>
using namespace std;
int main()
{
    cout << "Hello Worl!" << endl;
    return 0;
}
In Java:

Code:
public class HelloWorld {
    public static void main(String[] args){
        System.out.println("Hello World!");
    }
}
In Python:
code:
Code:
print "Hello World!"
As you can see, python is a bit shorter. Python is also OOP. I suggest you start with Python then move on to something more powerful, such as Java or C++. But again, that is just my personal opinion. Python is used fairly widely in scripting for games, and other such scripts.

Resources:
Info, Interpeter, Tutorials



Perl - Perl is a nice language, but mainly used for web and CGI (Common Gateway Interface), and UNIX/Linux programming. But Perl can also be used on MS Windows machines as well. The nice thing about Perl is that there is such a nice developers community. You could find nearly and modules you ever need just by looking on the internet for 30 seconds in CPAN.org. The drawback is that it's more of a scripting langauge, and used on UNIX more than Windows. The other drawback is that Perl code can get extremely cryptic. Because their are so many ways to do the exact same thing. This is not to say Perl is a bad langauge, by all means I love Perl, it simply can get cryptic when trying to decipher what someone else has done. But so long as you use good programming practice this should not happen. This is not to say you shouldn't learn it, if you are into UNIX or Linux systems, Perl would be a great language for you to learn. Or if you are into web design and CGI programming. Or if you just need a robust language for a round about task, Perl is your language.

Resources:
Interpeter
Info

ASM - This is practically pure machine code. Which means optimizations can be made from OS to OS. But there is zilch portability. I suggest you learn ASM only after learning a high level language, such as C++ or Java, and then want to better understand architecture. ASM would be a very nice language for making optimizations on an application that is extremely dependant on speed and performance. Or for a VERY low level programming language.
It is not widely used, as the sample "Hello World!" program shows, it takes a lot of memory pushing to print out a string.. As it is very processor specific, it can take advantage of many advanced features of one particular processor. Thus dramatically increase the performance of your program. ASM is mostly used to optimize C/C++ code for performance. Used in simulations, high performance games, and encryption/decryption.
pros:
-- generates very efficient machine code (ASM is hardwired into processor since the early 1980s).
-- take advantage of special features of a processor
-- if you want to write drivers or doing low-level allocating such as a boot sector, you will want to use ASM
-- integrate very well with c/c++ code (I read a book on it, got too depressed in ASM, and dropped any hope of understanding ASM thoroughly..)
cons
-- very low level, means you have to do a lot of memory pushing to accomplish what high level language can do in one line
-- not worth the time, as machine time gets cheaper, programmer time gets more expensive
Code:
;; ; This program displays "Hello, World!" on IBM-PC
dosseg
.model small
.stack 100h

.data
hello_message db 'Hello, World!',0dh,0ah,'$'

.code
main  proc
      mov    ax,@data
      mov    ds,ax

      mov    ah,9
      mov    dx,offset hello_message
      int    21h

      mov    ax,4C00h
      int    21h
main  endp
end   main

Delphi - Delphi is, at heart, a Pascal compiler. It was designed to be a visual rapid application development environment without the limitations of other similar products. Delphi was the first to combine a visual development interface, an optimizing native-code compiler, a scalable database access engine and other features.

Pros:
-- Rapid development environment that is very fast to make programs in.
-- Easy to learn and program in.
-- Faster compiler than many other languages
-- Powerful database architecture that can be changed if desired
-- Solid OO Design encouraged, helping to keep code clean.

Cons:
-- Visual Studio's interface is more customizable.
-- VB can edit code while in Debug mode but Delphi can't.
-- Compiled code is slightly slower than (good) C and C++ compilers'
-- No operator overloading

Code Example (Prints "Hello World" to the screen"):
Code:
uses
  SysUtils;

begin
  Writeln('Hello World!');
  Readln;
end.

Quick Basic - Quick Basic is generally well known for being the easiest language to learn. Just though I would add the language I am currently interested in. I've known qbasic for quite some time now, and now I'm getting back into it. After finally realizing that the new 7.1 edition comes with a compiler

Pros:
--Extremely easy to learn
--Somewhat flexible as to what you can do
--Also somewhat powerful as to what you can do
--Can be compiled into a .exe file for use with other systems and can be used as a stand-alone program

Cons:
--Since its easy to learn, you can't do as much with it as the other languages like c++


Ada - Originally designed by the Department of Defense, this language is a very strongly typed language that is excellent for learning how to program. Ada will not allow a programmer to "get away" with bad code such as C or C++ would, the compiler will not compile the program if an error is in the code. (Syntax error, not logic error.) Ada95 is completely object oriented, and code can be compiled for the three major operating systems currently used today: Windows, Mac OS, and Linux.
The largest draw backs to this language are many programmers don't use it (perhaps they were scarred by the fact it was developed by the department of defense?), and due to that it's hard making a program look "native" to the operating system's GUI.

Lisp - Perhaps one of the most elite language you can master. It is never meant to be a language at all, it's a theorical problem John McCarthy try to solve that resulted in a compiler to be written thus effectively turning lisp into a programming language. What is the theorical problem? What is the smallest number of element you need to build the most powerful language in the world. It turns out there are several, 12 to be exact.. once you combine those, rest of the lisp in theory can be build on those operators. However, in practice, lisp might do some optimization to speed up the implementation. It is also the mother of all high level languages. It invented conditional loop (if... else if... else), Garbage collection (30 years before java). and 7 other things out of which 5 is in mainstream languages.. read this page for more: http://www.paulgraham.com/diff.html.
Pros:
-- the most powerful abstraction system. We talk about reusable software. Have you ever stopped to ask what is more reusable than a programming language? That is exactly one thing lisp is set out to accomplish with it's true macro system. You can redefine it's whole syntax structure, by writing macros that work on lisp parse tree. Making it excel in defining new programming languages, or embedded languages.
-- excel at solving some of the hardest problems. AI(artificial intelligence) problems. After all, the goal of lisp is to make expressing algorithms easier.
-- an extremely compact coding system. It is said that lisp can write code 20 times shorter than a equivalent C++ program. Takes way more if you solve problem lisp excel at, at which point you have to construct an ad-hoc lisp interpreter in order to make it work.
-- extremely flexible, don't feel like typing any patterns today? write a piece of code to abstract the code away! It's all about giving as much power to the programmer as possible without endangering the core. Such as the garbage collector.
-- speedy compiled code when compared to java/python/perl and all other "modern" languages. it can be 20 times faster than Java if optimized correctly. Lisp fastest code is only slower by a factor of 2 max 3 than fastest C code. Why? It is pushed by old hardware. During 1980s, AI labs use lisp for everything, they are pushing compilers to the extend it needs to be to squeeze performance out of old boxes (run moores law backwards for 20 years and you know how slow those machines are).

Cons:
-- not the most popular language in the world. You can count on, however, those people in the #lisp irc and comp.lang.lisp to be top hackers. As only the most dedicated programmers bother to learn it. Read this article: http://www.paulgraham.com/iflisp.html
can't really think of other cons, give me some reasons?

Code Example (Prints "Hello World" to the console):
Some ways to generate them and their respective return values:

Code:
CL-USER> (print "Hello world")  
"Hello world"  
"Hello world" 
CL-USER> (format t "~A" "Hello World!") 
Hello World! 
NIL 
CL-USER> '("Hello World!") 
("Hello World!") 
CL-USER> (defun hello ()
 	       (print "Hello World!")) 
HELLO
CL-USER> (hello)
"Hello world!"
"Hello world!"

Resources:
A new book discuss practical aspect of lisp
A book on the advance techniques of lisp
A great intro book
The full language manual
of course, let's not forget comp.lang.lisp also #lisp on freenode.org
and of course, pm me if you need help, or clarifications on my description, i'm always willing to help fellow programmers




Web Languages
These languages are mainly used for web applications and rarely used offline.
Some very nice ones to check into are PHP, JSP, ASP, JavaScript, VBScript, and CGI.
Web languages are mainly divided into 2 groups, client side and server side programming. Client side (like JavaScript and VBScript) interact with the client and browser. The 'client' side of the internet. Things such as PHP, ASP, and CGI focus more on the server side of things. They are used to program and tell the server what to do with information provided by the client. Often you can use more than one of these languages in a single webpage for a single job.

PHP - PHP (PHP Hypertext Preprocessor) is an interpreted programming language that is usually used for (but not limited to) generating dynamic content on websites. However, it can be used for other tasks as well. It is powerful, and fairly easy to learn. The syntax is nice and clean as well. Its OOP support is also getting considerably better as it matures.

Resources:
Tutorials
Info, Tutorials, Downloads



ASP/ASP.NET - Developed by Microsoft ASP (Active Server Pages) used the syntax of VBScript, but in ASP.NET you may use the C# or Visual Basic. This is a great improvement because of C#'s ease of use. ASP.NET also hides a lot of the boiler plate code from the programmer, making it a whole lot easier to create quick server script. If you know the .NET framework, C#, or VB ASP.NET would be a very sound choice.

Resources:
ASP Tutorial
ASP.NET Tutorial




JSP - JSP Stands for Java Server Pages. Using the syntax of Java, one can use an extremely powerful sever side programming language. If you know Java, then JSP is for you! A huge number of websites are now using this great language.




JavaScript - Not to be confused with Sun's Java, Java and JavaScript are NOT the same thing. JavaScript was created by Netscape, not Sun. JavaScript is also not the same as Microsoft's JScript, so don't confuse the two. JS is great client side scripting language with an incredible amount of power in that area. Nearly all WebPages include some amount of JS. Another awesome thing about JS is that it's also Object Oriented, making for great code reuse and user friendliness. JavaScript used with DHTML can create some amazing dynamic pages, this one is defiantly worth learning if you're into web development.

Resources:
Tutorials



VBScript - VBScript, or VisualBasicScript, needless to say, uses the syntax of Visual Basic. To keep things short, it's used in the same way that JavaScript is used, in client side programming. Personally I think JavaScript is a better use of your time, unless you're wanting to program in ASP (classic, not .NET).

Resources:
Tutorials



Perl/CGI - CGI Stands for Common Gateway Interface, and uses Per's syntax. CGI is starting to become a bit dated simply because other languages are able to do much more complex things, only with less programming. CGI is still good for making things like ImageMaps or Bulletin Board Systems (BBS). CGI is not out the door yet, but in my opinion, it will only remain because of "legacy sites".


Markup Languages
These languages, aren't so much languages, they're more "Ways to present data" They can include HTML, DHTML, XML, CSS, and a few others. These are pretty much what make up WebPages you see from day to day. If you're into web design learning some of these is a must.

Resources:
HTML Tutorial
DHTML Tutorial
CSS Tutorial
XML Tutorial

If you have any question you'd like me to add, or question on what I've said. Feel free to post up. Or you may comment on just about anything you like.
Enjoy.

Authors/Editors:
-- Iron_Cross
-- Sippin Codeine
-- Punch-M6.net
-- NeoNemesis
-- Puckdropper
-- Jag3k
-- UnknownUsr
-- furtivefelon
-- runixd
 
What the!!!!

Iron_Cross,

You wrote this article by yourself?:eek: . I didnt read it fully thou, but that is a well written article[If you have done it]. Good work!;)
 
Myself, and a few others worked together. I started the main article, then some people added some sections about their favorite languages.
Thanks for the reply :)
 
can i ask several questions here?

1) What is the difference between Microsoft JScript and JavaScript?Besides, what are the differences between Sun's Java and Java?

2) How about the making of a search engine? What techniques are applied for that?

--------------------------------------------------------------------------------
thank you :)
 
There's only some subtle differences between JScript and JavaScript. Not really much, it's just MS's version of javascript.
Java and Sun's Java are the exact same thing. Sun is the maker of Java.

As for a search engine, I'm not sure how'd you do that. I've never tried :p
I'm in the middle of making this into a .CHM so you use it like a book. I'm also adding tons of content...so look foreward to that :)
 
ahh.. let's add a few languages:

Lisp - perhaps one of the most elite language you can master. It is never meant to be a language at all, it's a theorical problem John McCarthy try to solve that resulted in a compiler to be written thus effectively turning lisp into a programming language. What is the theorical problem? What is the smallest number of element you need to build the most powerful language in the world. It turns out there are several, 12 to be exact.. once you combine those, rest of the lisp in theory can be build on those operators. However, in practice, lisp might do some optimization to speed up the implementation. It is also the mother of all high level languages. It invented conditional loop (if... else if... else), Garbage collection (30 years before java). and 7 other things out of which 5 is in mainstream languages.. read this page for more: http://www.paulgraham.com/diff.html.
Pros:
- the most powerful abstraction system. We talk about resuseable softwares. Have you ever stopped to ask what is more reuseable than a programming language? That is exactly one thing lisp is set out to accomplish with it's true macro system. You can redefine it's whole syntax structure, by writing macros that work on lisp parse tree. Making it excel in defining new programming languages, or embedded languages.
- excel at solving some of the hardest problems. AI(artifical intelligence) problems. After all, the goal of lisp is to make expressing algrithims easier.
- an extremely compact coding system. It is said that lisp can write code 20 times shorter than a equivalent C++ program. Takes way more if you solve problem lisp excel at, at which point you have to construct an ad-hoc lisp interpreter in order to make it work.
- extremely flexible, don't feel like typing any patterns today? write a piece of code to abstract the code away! It's all about giving as much power to the programmer as possible without endangering the core. Such as the garbage collector.
- speedy compiled code when compared to java/python/perl and all other "modern" languages. it can be 20 times faster than Java if optimized correctly. Lisp fastest code is only slower by a factor of 2 max 3 than fastest C code. Why? It is pushed by old hardware. During 1980s, AI labs use lisp for everything, they are pushing compilers to the extend it needs to be to squeeze performance out of old boxes (run moores law backwards for 20 years and you know how slow those machines are).

Cons:
- not the most popular language in the world. You can count on, however, those people in the #lisp irc and comp.lang.lisp to be top hackers. As only the most dedicated programmers bother to learn it. Read this article: http://www.paulgraham.com/iflisp.html
can't really think of other cons, give me some reasons?


Sample hello world:
Some ways to generate them and their respective return values:

Code:
CL-USER> (print "Hello world")  
"Hello world"  
"Hello world" 
CL-USER> (format t "~A" "Hello World!") 
Hello World! 
NIL 
CL-USER> '("Hello World!") 
("Hello World!") 
CL-USER> (defun hello ()
 	       (print "Hello World!")) 
HELLO
CL-USER> (hello)
"Hello world!"
"Hello world!"

Resources:
http://www.gigamonkeys.com/book/ - a new book discuss practical aspect of lisp
http://www.paulgraham.com/onlisp.html - a book on the advance techniques of lisp
http://www.paulgraham.com/acl.html - a great intro book
http://www.lispworks.com/documentation/HyperSpec/Front/ - the full language manual
of course, let's not forget comp.lang.lisp also #lisp on freenode.org
and of course, pm me if you need help, or clarifications on my description, i'm always willing to help fellow programmers :D

Ruby - personally i'm still learning the language, but i'm convinced it does OOP much more purely than Java does and ever will - It does it the smalltalk way, which is the first OO language, arguably the purest OO language. Probably some better Ruby hacker could elaborate on that? If no one does, i'll do some more programming and write back hopefully in next couple of weeks :D
 
mmm.. this article would be an intereesting addition to the FAQ :D: http://paulgraham.com/langdes.html

and some more excellent code examples than hello world compiled by Paul Graham:
The problem: Write a function foo that takes a number n and returns a function that takes a number i, and returns n incremented by i.

Note: (a) that's number, not integer, (b) that's incremented by, not plus.
Code:
C++                   template<typename T>
                      struct Acc {
                        Acc(T n)
                        : n(n) {}

                        template<typename U>
                        Acc(const Acc<U>& u)
                        : n(u.n) {}

                        template<typename U>
                        T operator()(U i) {
                            return n += i;
                        }

                        T n;
                      };

                      template<typename T>
                      Acc<T> foo(T n)
                      {
                        return Acc<T>(n);
                      }

Dylan                 define function foo (n)
                        method (i) n := n + i end;
                      end function;

E                     def foo (var n) :any {
                        def inc (i) :any { n += i }
                      }

Erlang                foop(N)->
                        receive
                          {P,I}-> S =N+I, P!S, foop(S)
                        end.

                      foo(N)->
                        P=spawn(foo,foop,[N]),
                        fun(I)->
                          P!{self(),I},
                          receive V->V end
                        end.

Haskell               import IOExts
                      foo n = do
                        r <- newIORef n
                        return (\i -> do
                          modifyIORef r (+i)
                          readIORef r)

Javascript            function foo (n) {
                        return function (i) {
                                 return n += i } }

Lisp: Arc             (def foo (n) [++ n _])

Lisp: Common Lisp     (defun foo (n) 
                        (lambda (i) (incf n i)))

Lisp: Goo             (df foo (n) (op incf n _))

Lisp: Scheme          (define (foo n)
                        (lambda (i)
                          (set! n (+ n i))
                          n))

Lua                   function foo(n)
                        return function (i)
                                 n = n + i
                                 return n
                               end
                      end

Maple                 foo := proc(n)
                               local s;
                               s := n;
                               proc(i) s := s + i   
                                 end
                             end

Mathematica           foo[n_] := 
                        Module[{s = n},
                          Function[i, s += i]]

Mozart                fun {Foo N}
                        A = {NewCell N}
                      in
                         fun {$ B} C D in
                            {Exchange A C D}
                            if {IsInt C}
                               andthen {IsFloat B}
                            then
                               D = {IntToFloat C}+B
                            elseif {IsFloat C}
                               andthen {IsInt B}
                            then
                               D = C+{IntToFloat B}
                            else D = C+B end
                            {Access A}
                         end
                      end

NewtonScript          foo := func (n)
                               func (i)
                                 n := n + i ;

Perl 5                sub foo {
                        my ($n) = @_;
                        sub {$n += shift}
                      }

Python                class foo:
                        def __init__(self, n):
                            self.n = n
                        def __call__(self, i):
                            self.n += i
                            return self.n

Rebol                 foo: func [ n ] 
                       [ func [ i ] [ n: n + i ] ]

Ruby                  def foo (n)
                        lambda {|i| n += i } end

Smalltalk             foo: n
                        |s|
                        s := n.
                        ^[:i| s := s + i. ]

VBScript              Class acc
                        Private n
                        Public Default Function inc(i)
                          n = n + i
                          inc = n
                        End Function
                      End Class

                      Function foo(n)
                        Dim bar
                        Set bar = New acc
                        bar(n)
                        Set foo = bar
                      End Function

Some languages are not represented here, either because you can't write this program in them (short of Greenspun's Tenth Rule) or because no one has yet sent me the code for that language. If you know how to write this program in a language that isn't listed here, please send it along.

Credits: C++, Brendan Corfman and Daniel Cowgill; Dylan, Neel Krishnaswami; E, Darius Bacon; Erlang, Heinz Eriksson; Goo, Jonathan Bachrach; Haskell, Malcolm Wallace and Tom Pledger; Javascript, Anton van Straaten; Lua, Chris Laurel; Maple, Stefan Vorkoetter; Mathematica, David Cabana; Mozart, Kari Pahula; NewtonScript, Sean Luke; Perl, Dan Giffin and Trevor Blackwell; Python, Jeremy Hylton; Rebol, Andreas Bolka; Ruby, Stephan Schmidt; Smalltalk, Trevor Blackwell; VBScript, Stefan Holm.

BTW. in his "Revenge of the nerds": http://www.paulgraham.com/icad.html, he pointed out that in Java you fall short of the spec, the following code is how close you can get without being especially awkward :|
Code:
public interface Inttoint {
  public int call(int i);
}

public static Inttoint foo(final int n) {
  return new Inttoint() {
    int s = n;
    public int call(int i) {
    s = s + i;
    return s;
    }};
}
as quoted: "This falls short of the spec because it only works for integers. After many email exchanges with Java hackers, I would say that writing a properly polymorphic version that behaves like the preceding examples is somewhere between damned awkward and impossible."

another interesting quote:
"It's not literally true that you can't solve this problem in other languages, of course. The fact that all these languages are Turing-equivalent means that, strictly speaking, you can write any program in any of them. So how would you do it? In the limit case, by writing a Lisp interpreter in the less powerful language.

That sounds like a joke, but it happens so often to varying degrees in large programming projects that there is a name for the phenomenon, Greenspun's Tenth Rule:
Any sufficiently complicated C or Fortran program contains an ad hoc informally-specified bug-ridden slow implementation of half of Common Lisp. "

mmm.. interesting things to add :D
 
better description for ASM:
ASM: This is the only non-portable language still in use today. It is not widely used, as the sample "Hello World!" program shows, it takes alot of memory pushing to print out a string.. As it is very processor specific, it can take advantage of many advanced features of one particular processor. Thus dramatically increase the performance of your program. ASM is mostly used to optimize C/C++ code for performance. Used in simulations, high performance games, and encryption/decryption.
pros:
-- generates very effcient machine code (ASM is hardwired into processor since the early 1980s).
-- take advantage of special features of a processor
-- if you want to write drivers or doing low-level allocating such as a boot sector, you will want to use ASM
-- integrate very well with c/c++ code (i read a book on it, got too depressed in ASM, and dropped any hope of understanding ASM thoroughly..)
cons
-- very low level, means you have to do alot of memory pushing to accomplish what high level language can do in one line
-- not worth the time, as machine time gets cheaper, programmer time gets more expensive
Code:
;; ; This program displays "Hello, World!" on IBM-PC
dosseg
.model small
.stack 100h

.data
hello_message db 'Hello, World!',0dh,0ah,'$'

.code
main  proc
      mov    ax,@data
      mov    ds,ax

      mov    ah,9
      mov    dx,offset hello_message
      int    21h

      mov    ax,4C00h
      int    21h
main  endp
end   main

hello world in perl:
Code:
print "Hello World\n";

hello world in PHP:
PHP:
<?php echo "Hello World!" ?>
 
Status
Not open for further replies.
Back
Top Bottom