Pike (programming language)
Pike logo | |
Paradigm | multi-paradigm: object-oriented, functional, procedural |
---|---|
Designed by | Fredrik Hübinette |
Developer | Fredrik Hübinette & Roxen employees |
First appeared | 1994 |
Stable release | 7.6.66
/ January 29, 2006 |
Typing discipline | weak, static, explicit |
Website | pike |
Major implementations | |
Pike | |
Influenced by | |
LPC, C, ųLPC |
Pike is an interpreted, general-purpose, high-level, cross-platform, dynamic programming language, with a syntax similar to that of C. Unlike many other dynamic languages, Pike is statically typed, and requires explicit type definitions. It features a flexible type system that allows the rapid development and flexible code of dynamically typed languages, while still providing the benefits of a statically typed language.
Pike features garbage collection, advanced data types, and first-class anonymous functions, and supports many programming paradigms, including object-oriented, functional, aspect-oriented and imperative programming. Pike is free software, released under the GPL, LGPL and MPL licenses.
History
Pike has its roots in LPC, which was a language developed for MUDs . LPC's license did not allow use for commercial purposes, and so a new GPL implementation was written in 1994, called ųLPC. In 1996, ųLPC was renamed to Pike in order to provide a more commercially viable name. Although the name of the company has changed over the years, the company now known as Roxen Internet Software employed many Pike developers, and provided resources for Pikes development. In 2002, the programming environment laboratory at Linköping University took over maintenance of Pike from Roxen.
Syntax Highlights
Hello World
- For an explanation of the tradition of programming "Hello World", see Hello world program.
int main() { write("Hello world!"); return 0; }
The syntax above requires some explanations for some. Those who are familiar with C or C++ should pick it up right away.
- The first line contains the main function, that line tells the interpreter where to start executing program commands
- The write function sends a string literal to the standard output buffer, which in most cases is a command line interface
- The third line tells the program in what state the program exited
- The last line lets the interpreter know that it has reached the end of the main function
Data Types
The following list shows all the standard data types that Pike provides. Advanced data types such as sequences, queues, heaps, stacks, etc. are available in the ADT module which is included with Pike.
Basic data types:
- int
- float
- string
Container types:
- array
- mapping
- multiset
Reference types:
- program (the compiled representation of a class)
- object (an instance of a class)
- function
Pike requires explicit type definitions for all variables. Being a statically typed language, it uses this information to report type errors at compile time. In the following example, a compile time error is produced. The message indicates that the variable, "MyNumber", is mistakenly being used in the assignment of incorrect data types(floating point value and string values).
int MyNumber; // integer variable, it only accepts integers MyNumber = 5.5; // 5.5 is a floating point value, error MyNumber = "5"; // "5" is a string, not the integer value 5, error
That kind of behaviour is traditionally considered restrictive and limiting by proponents of dynamically typed language. However unlike C, C++, and Java Pike is a scripting language so it also uses a more flexible type system. The system allows programmers to declare variables that may be of multiple types. The following demonstrates a variable that can be either an integer or a floating point number.
int|float MyNumber; // integer OR float variable MyNumber = 5; // this is legal MyNumber = 5.5; // this is legal also
Additionally, there is a special "mixed" data type. That definition allows a variable to be any kind of data type.
mixed MyMixedVar; MyMixedVar = 5; // number is now the integer value 5 MyMixedVar = 5.5; // number is now the float value 5.5 MyMixedVar = "5"; // number is now the string value 5
In order to convert a value from one type to another, Pike can use an explicit cast:
mixed MyMixedVar; MyMixedVar = (int)5; // number is now the integer value 5 MyMixedVar = (string)number; // number is now the string value 5