views:

246

answers:

4

I stumbled upon Pike and got very interested in it's structure and setup. It seems like a simplified and safer C++. (though interpreted).

Though it has a small number of libraries. The ones available make it interesting to use. It is something I will definitely look at but since there was no Pike question here on SO. I thought I'd start the ball rolling with these.

  • Why should I use Pike?
  • What are its pro's and con's?
  • What are its gotchas?
+8  A: 

I have only played with Pike, never written a real program with it, but it has many interesting features. The best is tagged unions. This is a weak version of what is called an Algebraic Data Type in the functional world.

Imagine you have a piece of memory in C, and you would like to store either an integer or a string (pointer) in it. You can do this with a union:

union {
  int myint;
  const char *mystr;
} foo;

Then you can write: foo.mystr = "hello world"; To store a string. The problem is you can then access it as an integer:

foo.mystr = "hi";
printf("foo=%d", foo.myint);

This doesn't make any sense. Pike uses its type system to stop you from doing this:

int main() {
  int|string foo;
  foo = "hello";
  write("foo=%d\n", foo);

  return 0;
}

Gives:

sprintf: Wrong type for argument 2: expected integer, got string.
src/modules/files/file.c:3913: Fd(1)->write("foo=%d\n","hello")
test.pike:5: /home/crawshaw/test()->main()

If you change the %d to a %s, you get the result you would expect.

That said, the type system is not as powerful as it could be. Much testing is done at runtime, and the use of match cases are not enforced (as they would be in ML/Haskell). If you're interested in languages that stretch the mind, try Haskell. If you want a gentle introduction to fancy type systems and you're from a C background, you may want to experiment with OCaml. If you come from Java, try Scala. Pike is far more of an 'everyday' language for the C programmer than these languages, though they are all useful. (Indeed, my day job is OCaml programming.)

As with all uncommon languages, Pike has the drawback of being, well, uncommon. Fewer libraries, fewer jobs. But that should not deter you from experimentation!

David Crawshaw
Great answer David. Specially mentioning those other languages.
Ólafur Waage
+4  A: 

Personally, I think Pike has an interesting history as well. It evolved from LPC, a language used for programming MUDs back in the day (and I guess still, don't play anymore). To be honest, I got my first taste of OOP from working with LPC developing for a MUD back in '99. LPC itself was derived from C, so you get a feel for what you're doing from the get-go if you have any experience with programming C or a similar language.

Sadly, I think one of the biggest drawbacks to it right now is the lack of good documentation. There's one book out there for Pike last time I looked, and it's basically the Beginner's Tutorial from the main Pike website in book form.

It's a shame, really. Having a bit of experience with LPC, I was looking forward to getting into Pike. But as of yet, it hasn't happened.

Charasan
+1  A: 

I only have little experience with Pike, but maybe it helps others considering to use/ avoid it

Why should I use Pike?

  • it has a rather simple yet elegant syntax
  • it is interpreted and thus rather easy to learn
  • it has quite good performance for an interpreted language
  • Open Source

What are its pro's (see above) and con's?

  • personally, I dislike it b/c of a type system that gives me headaches (eg. there are three different 0 types that are hard to understand and can lead to unexpected results)
  • the supposed consistency in the language is not always in-line with what one would expect (this is a rather polite way to express the headaches some of my friends got of the language; see what David has written for some examples)
  • no debugger available
  • very limited support in other tools (just an emacs major mode and an eclipse plugin, that's about it)
  • "hilfe" is useful, but cannot compete with tools like ipython
  • virtually no community to ask when running into some of the issues :(
  • limited set of libraries
  • no up to date packages for any current Linux distribution (eg. the 7.6 Debian packages are really out of date compared to the current 7.8)
  • the performance comparisons formerly on Pike's homepage were long outdated and thus possibly wrong for the compared languages which might have vastly increased in performance
  • only a c-implementation of the interpreter (nothing like Jython, pypy etc)

What are its gotchas?

  • see above, but the list can be continued ;)
Gerald Senarclens de Grancy
A: 

If coming from C/C++ it's very easy to learn but I agree with some points already mentioned, especially about community support. I have also had several problem with pike on windows, it seems to work better on linux. I have used it quite a lot but would not start up any new projects using it.

Zitrax