Languages

Posted by Beale on Mon 08 Nov 2004 09:03 PM — 25 posts, 95,282 views.

#0
Just out of curiosity and for recommendation's sake, what languages do the collective 'you' use to script in MUSHClient, and why?

I personally use both VBScript and Python, VBScript to export for other people as plugins, and Python to experiment with for myself.
Australia Forum Administrator #1
Personally I usually use VBscript. It is not that I particularly *like* VB, however it does have some things to recommend it:

  • It is generally available by default, as VBscript (and probably JScript as well) are normally installed as part of Internet Explorer. If not, it is readly available as a download from Microsoft. If I were to do plugins or examples in (say) Python or Perl, then the end-user may not have that installed.
  • It has a fairly simple interface to COM objects, and thus to the MUSHclient "world" interface. MUSHclient calls that return arrays look a bit clumsy in JScript and Perlscript.

    If you compare the code in:

    http://www.gammon.com.au/scripts/doc.php?function=GetVariableList

    JScript needs the extra step of "toArray()" and Perlscript needs "foreach $item (Win32::OLE::in ($world->GetVariableList))".

    Admittedly Python looks pretty neat.
  • For me, since VBscript was the first script language I used with MUSHclient I tend to know its features better than other languages.


USA #2
I use VBScript myself. It is something I am familiar with. Though I would prefer something with more Python like capabilities, Python has its own flaws, not the least being forcing you to use specific indentation as part of the syntax. It also tends to be slightly more obscure in terms of how you link things in, etc. (though with VB it is more a case of you can't anyway.) I would love to see something in between the two, but...
#3
I started out using VB script mostly because it looked familiar to me. I grew up using computers like the C64 and Basic is an old old language now. It's pretty easy to learn for anyone who can map something out in a step-by-step, logical fashion. Also, as Nick said, it's widely available and probably already installed on your computer.

I recently started using Python because I found VB script lacking some things that I needed to write more complicated scripts for MUDs like Achaea. After I created my first list in Python, I was hooked.

It's a pretty easy language to learn. The indentation is odd at first, but as you start to learn the language, you'll see why it's nice. I think it's a great feature.

The obscure parts, if you ask me, are the documentation. Don't misunderstand, it is well documented. It was just hard to make the transition from VB script. I should have just started out in Python.

Since you're already using Python, I would say, just keep at it. It's much more powerful. People who want to use your plugins can use them in Python.

It doesn't appear that there are more than a couple of us using Python regularly, so I secretly hope everyone reads this and then looks at something like diveintopython.org so that section of the forum takes off and then Nick decides to really try it out. (I'm telling you, Nick. Don't play with it or you will never use VB script again.)
USA #4
Well, the problem people have with the indention isn't that it is 'bad', but just that it breaks language standards, which usually ignore white space, so you can use any indentation you want. When they force it on you... The only other language requiring that was some ancient one used with card punch machines, since the machine needed to be able to tell commands to the card punch appart from the program code. There is no excuses for such a anachronism in a modern language imho. I agree with the documentation issue though.
Greece #5
I agree 100% with the indentation being forced in Python. I hate code that isn't indented, and Python forces you to write great code. The only reason I don't write in Python is that most people don't have it installed...
USA #6
The only reason to not write with indentation is if you're writing in bad style, so it's not much of a problem to enforce it. It's hardly an 'anachronism'.

And in fact not all modern languages ignore whitespace - for instance, newlines are often used as statement terminators and to span a command over multiple lines you need to use escape characters e.g. \ at the end of the line.
#7
I sure is nice to not have to look and your subroutine and think:
"Okay, there's.....1, 2, 3 'end ifs' and then an 'end select' and another 'end if' and why doesn't it work?? arg! Oh wait, I forgot the 'end sub'. Heh.
USA #8
The thing is that even C or whatever programmers simply should not be writing code without using proper indentation one way or another anyways.

Now different people indent in different ways, e.g. my style tends to be:

void foo()
{
  if ( something )
  {
    // do some stuff
  }
}

whereas other people write like so:
void foo()
  {
  if ( something )
    {
    // do some stuff
    }
  }


Either way the structure is clear. The point is that a programmer who is not using indents is just as guilty of bad style as an author who writes text without paragraphs.

The only advantage, as far as I can see, of not enforcing indents is that sometimes there are cases where it's ok to use 'shorthand', e.g.
if ( a < 1 ) b += 6;

but typically, this kind of code is discouraged and should only be used when both the condition and the action are pretty short.
Amended on Tue 09 Nov 2004 10:37 PM by David Haley
USA #9
I agree with indention, I just want it to be 'my' indention, not something forced on me by the language.
USA #10
Well, ok, then just say so and don't start blasting it with 'anachronism' etc. :-)
USA #11
Should not.
Can not.
Different things.

Anyway, did we all wake up on the wrong side of the keyboard today or something?

Theyre languages, they each have their strengths and shortcomings, which is why MC has a few for us to choose from.

Lets steer this back to a constructive discussion, to help new people figure out what language they might want to use.

I think the obvious 'newbie' script language is VBscript, since a lot of people grew up with BASIC in some form or another, and even more have been introduced it with a lot of other things.
It's reasonably forgiving with syntax. The only drawback is Variants, and the problems they have.
You can 'easily' incorperate COM objects (since its designed to work well with Windows), and its on most (if not all) windows boxes.
USA #12
Yes. VB defintely has a major problem with variants. The problem is not so much that it uses them, but that it doesn't allow for more strict definitions. All COM programs use variants to talk to each other. Most languages convert to and from them to the more specific types at either end. MS decided to over simplify matters by making VB 'only' use them and nothing else. Usually this is not a problem, but some times it causes real annoyances.
USA #13
Huh? VB definitely has the ability for a strict type system. 'Dim I as Integer' means that I is an integer, and if you try to assign a string to it, it will either give you a type mismatch or it will try to convert. More likely, a type mismatch. If you declare something as a string, and try to assign an int to it, it'll convert, I think - it definitely will if you use the concatenate operator.

There's no way to 'have your cake and eat it do'. Variants are a very powerful system - Perl uses them as does PHP. If you're communicating arbitrary information across application borders, you need to have *some* way of representing an arbitrary type. C uses void*, which is basically a variant in the sense that you cast it.

But VB most certainly has type casting so that you can convert variants to specific types. I believe the function in vb6 is called CInt to convert to ints, CString to convert to string, etc. The thing is that most of the time these conversions are done implicitly, but you can use them to do explicit conversions.
USA #14
He's talking about VBScript.
And we're talking about ALL the issues with using getvariable and adding stuff to it, and getting funky results.
Or trying and compare things with conditionals.

And yes, VBScript does have casting, it's probably the single most thing we have people 'fix'. Well, that and loops in code.

But thats just it. We have to fix it. Even though you JUST set something as a number, and now youre trying to do something with it, the engine MIGHT think that it's a string and then choose one of a few ways to deal with the 'type mismatch'.
Greece #15
That's VB only, in VBScript you get an error if you declare something as a type. By the way, Shadowfyr, I'm curious to see how you indent, could you paste a sample? :p
USA #16
That entirely depends on the language Poromenos. With VBScript it is a tad easier, but with something more C like, such as the POVRay SDL, you can do it several dozen ways:

sphere{<0,0,0>,1 pigment{color rgbt <1,1,1,1>}}

sphere {<0,0,0>,1
  pigment{
    color rgbt <1,1,1,1>
  }
}

sphere
  {<0,0,0>,1
  pigment
  {
    color rgbt <1,1,1,1>
  }
}

And so on... I generally use two spaces and the second format, but others might use three spaces, tabs, or any number of different points of indention. However, if the SDL 'required' you to indent as part of the language, you wouldn't get 3D signitures or one line shortest code contests entries like:

background{rgb<.5.7,1>}global_settings{radiosity{error_bound.5count 99}ambient_light#local _=function{pattern{agate turbulence 1octaves 9}}0}isosurface{function{(y+.07-_(x+9,y,z)*.115)/20}accuracy 1e-5pigment{rgb 1}}light_source{5<8,4,2>}

You can see the result of this as the second one down at this site:

http://astronomy.swin.edu.au/~pbourke/povray/scc3/final/

Yeah, that is a bit of a silly reason to not use indention, but the point is, the option exists. ;)
Amended on Wed 10 Nov 2004 11:16 PM by Shadowfyr
Greece #17
Did you forget to add the code tags to that? I don't see the spaces. Also, I agree with the special syntax (I enjoy the looks on people's faces when they see my database program spelled out as large "Poromenos" ASCII art :), but you can't do that in VB either, and if you have a language whose line endings are \n you might as well take it a step further and enforce indentation, since it is very ugly to see unindented code. So, essentially, the argument is a C-style vs VB-style one, and not at all about enforcing indentation.
USA #18
It's not a C vs. VB argument. What you're talking about - the ASCII art - is "cute". When one writes code for real, one does not write "cute" code. There are tons of reasons, for instance cute code is extremely difficult to maintain. If you were a programmer and turned in code that wasn't indented according to the company style guides, people would be very unhappy with you. If you're a student in a programming class and don't turn in indented code, your grader will be very unhappy with you. If you're just submitting random code to your peers, they'll be unhappy with you if it's not indented.

'Cute' code certainly has its purposes, e.g., well, when you're trying to be cute. :) But when you're trying to write a program that does something useful and that you plan on maintaining, expanding and debugging, 'cute' good is a Very Bad Idea no matter what language it's in.
Australia Forum Administrator #19
Quote:

(I'm telling you, Nick. Don't play with it [Python] or you will never use VB script again.)


Well, I have been playing with Lua recently, and am rather impressed with that. However I haven't found a COM interface for it yet, so if that were to be added to MUSHclient it would be a bigger undertaking.

As for what Poremenos was talking about, there are competitions for who can write the most obscure C, obviously not for any sort of production environment.

See this site: http://www.ioccc.org/

Here is an example:


#include <stdio.h>
int l;int main(int o,char **O,
int I){char c,*D=O[1];if(o>0){
for(l=0;D[l              ];D[l
++]-=10){D   [l++]-=120;D[l]-=
110;while   (!main(0,O,l))D[l]
+=   20;   putchar((D[l]+1032)
/20   )   ;}putchar(10);}else{
c=o+     (D[I]+82)%10-(I>l/2)*
(D[I-l+I]+72)/10-9;D[I]+=I<0?0
:!(o=main(c/10,O,I-1))*((c+999
)%10-(D[I]+92)%10);}return o;}

Operation

Compile normally and run with one argument, an integer with 2n digits.

Program will return the integer part of its square root (n-digits).

For example,

       > gcc -o cheong cheong.c
       > cheong 1234567890
       35136
       > cheong 0200000000000000000000000000
       14142135623730
       >

#20
I use Python for scripting. That's what made me use Mushclient.

I must agree with Nick on Lua too. Its really nice. I also like Ruby but that isn't supported.
Greece #21
Cuteness isn't very bad as long as it's optional. You still can be cute or indent and be pretty whenever appropriate. And yes, the Obfuscated C Contest has some great programs :P There's one where the entire program is written in preprocessor directives, try to find it. I still don't know how he did that :P
USA #22
Trust me, if you ever have to maintain a large codebase that does something moderately useful, the last thing you will want to see is somebody being "cute" if that means you have to spend even just a few more minutes trying to figure out what they were trying to do/say. :-)
Greece #23
You obviously wouldn't do that, since "cute" code might be very cute, but it's impossible to debug. I'm talking about this:


s::l86                      );;;l33=
e.  l87    ();   y(1)       ;}h   l31  ::l35     (v  &r){r   .l41    ((a*)  &q ,x        (q))    ;r.l41    ((a*)     &l33,x
(l33))      ;y    (1)       ;;}l31::  l31   (){  u();;      }h   l31  ::  l67  (l26   a*l36,l26  a*   l37 ){v    r;   l38
l40  ;r.    l39  (l36       ,s        ::   l54    |s       ::    l46  );   l40  .l39   (l37      ,s    :: l72    |s    ::l46
|s::l69       );c(r.        l42         ()||     l40         .l42     ()    )y   (0)      ;l35(  r);  l45  ();l63   (r,l40
                  );
             r.l47
();l40.l47();y(1);}l28 l31::l63(v&e,l38&p){f a n=0;f a z=0;f a k=0;h g=0;f l79 l66=l33;w*b=d;l48(l66){c(!k){e.l41((a*
        )&n,x(n));c(e.l60())l59;k=128;}z=n&k;k>>=1;c(z)b=b->m;t b=b->j;c(b->l34){p.l43((a* )&b->l27,x(b->l27
            ));l66--;b=d;}}}l28 l83(h l80,a*l30[]){l32 l52;l31 l65;c(l80==4){c(l76(l30[1],"\x2d\x63")==
                0&&l52.l49(l30[2]))l52.l58(l30[2],l30[3]);t c(l76(l30[1],"\x2d\x64")==0&&l65.l49(
                                   l30[2]))l65.l67(l30[2],l30[3]);}}
USA #24
That's exactly the kind of stuff I'm talking about. Sure, it's nice to be able to write "cute" code for "cute code contests" or "hard to read code contests" but beyond that, the ability to write "cute" code is absolutely useless for any kind of production environment. In other words, the ability to not indent is only useful if you're not writing in a production environment where code is shared/maintained/developed/etc.