Thoughts On The Pike Programming Language?
bilboyablan asks: "Ive stumbled upon the Roxen Web server , mostly implemented in the
Pike programming language.
I got curious about Roxen, but even more about Pike, and it seems to me like a quite solid scripting OO language, with a C-like syntax, and with a quite good documentation (user manual) to boot. So it seems intriguing to me why Pike hasnt gotten a wider acceptance.
So, if some of you fellow Slashdotters have had any experience with Pike (outside of Roxen), could you maybe drop a few lines on it?
"
well that is a strange statement. Most script languages are hard to use for those who do not know how to use them.
Here is another one: Unix IS user-friendly, it just chooses its friends very carefully.
Why are scripting languages hard to use? I use sh, csh, ksh, awk, sed, Perl, Python, jsp, asp and even Dos batch files in primitive basic. What is so hard about 'em?
Translated languages under Unix/Linux have the same precedence level as compiled binaries (under DOS bat files are secondary). Translated languages don't even have to be compiled! It is true that I have not seing a good IDE for awk or csh but it does not mean the language is bad.
You can't handle the truth.
Pike is close to java in that they are both follow C syntax somewhat, extending it to OO concepts.
/* constructor */
It is unlike java in that while Java is strongly typed and you have to use typecast, Pike is as strongly-typed as you wish. You can use the mixed type to completely defeat any typechecking, or you can use classes and call them by name to be as strongly-typed as you wish.
Also notice that pike's concept of "class compatibility" is somewhat different from all other strongly typed OO languages, as it doesn't call into play inheritance. If two classes have similar signatures (names and types of public methods and variables), they are compatible.
Another novel approach Pike has is to function and operator overloading.
With C++ (and Java, if I remember correctly), overloading is defined by having different functions take different numbers and types of arguments: i.e.
void foo (int arg);
void foo (char* arg);
They are distinguishable at compile-time because the function signature is extended to its arguments' types, usually via name mangling.
Pike insteads allows arguments to be of different types. The above example would translate to:
void foo (int|string arg).
The programmer can then use runtime type information to discriminate.
Pike has both refcounting and garbage collection. It is quite uncommon to see the gc in action, as it will kick in when some percentage (I think half) of the object references are deemed garbage (it uses some adaptive algorithm to determine when to run). Or when explicitly invoked.
About static typing, see above. It can be as strict (or as lax) as the programmer wishes. It is refreshing to have some "mixed tmp" variable in a function and use it for loops etc.
About control flow structures, it has some more than C (i.e. foreach()).
The preprocessor if used wisely can be a nice weapon. For instance, you can detect the interpreter's version and use threads when possible. Of course, this also means that it allows people to write messy code. But they'd do it anyways...
It can be as dynamic as you wish. For instance, setting a method of another object can be done using a "function"-type variable:
class foo {
private int foo_bar() {
werror "foo";
}
function bar=_bar;
}
class gazonk {
private int gazonk_bar() {
werror "gazonk";
}
object foo_object=foo();
void create() {
foo_object->bar=gazonk_bar;
}
}
I could have also used anonymous functions (lambda) here.
i.e.
function foo_bar=lambda() {werror "foo";}
A nice thing about the language is that it doesn't try to hide details from the user. It is known what is handled by reference (every composite type, classes, objects, functions) and what is by value (basic types). It allows runtime inspection (via the indices, and typeof operators), remote objects, etc.
Since functions are primary objects, the whole runtime library follows a very consistent callbacks-based approach. This comes very handy when doing asynchronous I/O (one of Pike's strong points) or GTK programming.
About its "product placement" in terms of heavy-ness. It has some at-large programming helpers (more than TCL), and its syntax is less shell-ish than TCL's. Perl is IMO simpler for very simple tasks, but heavier for more complex ones (especially when need to go further than the string-array-hash types, and references come into play. Pike is much easier in this respect).
Python, I don't know really.I've never used it. I suspect that Pike and Python play roughly in the same league, neither clearly besting the other. I find Pike very convenient in I/O-related task, X programming (although here TCL/TK is better), and some simple text-manipulation tasks, requiring little text manipulation and a bit of variables-juggling.
About the runtime environment, Pike offers a two-pass compiler (no forward declarations), a mixed static+dynamic names binding model (intra-object references are static, inter-object they are dynamic), and a nice (but not comparable to CPAN) runtime library, including some nice DB-connectivity options.