# C++ like script language

34 replies to this topic

### #21nopcoder

New Member

• Members
• 8 posts

Posted 01 February 2007 - 02:08 AM

eddie said:

strongly-typed is really over-rated in a scripting language: IMHO.

strongly-typed is really under-rated in a scripting language, IMHO.

Besides being less error-prone it makes clearer and potentially faster code, all of which could be nice.

### #22Reedbeta

DevMaster Staff

• 5344 posts
• LocationSanta Clara, CA

Posted 01 February 2007 - 04:10 AM

I agree - I really hate seeing things like
function foo (bar, baz)

I have no idea what type bar and baz are supposed to be. Numbers, strings, some ADT or object? Of course, one can document this in comments, but as we all know comments can get out of date or incorrect. Static typing (I'll use this term since 'strong typing' is sort of vague) isn't just a compile-time check on (a limited aspect of) program correctness, it's also means of documenting code, where the compiler can automatically verify that the documentation is correct.
reedbeta.com - developer blog, OpenGL demos, and other projects

### #23monjardin

Senior Member

• Members
• 1033 posts

Posted 01 February 2007 - 04:32 AM

I understand the value of both and usually prefer static typing as well. However, for the cases where I use Lua it's usually not necessary and would just slow thing down. I mean Lua only has one number type anyway (usually double unless you change it). So, everything is either a number, a string, a table or user data. Of course, Lua was meant as a configuration language. If the OP is looking for something beyond that then it seems completely fair to favor static, strong or whater-you-call it typing.

Altough, World of Warcraft seems to have done just fine with Lua for managing their UI. Others have used it much more extensively (e.g. Far Cray, Impossible Creatures, Baldur's Gate, Homeworld 2, et cetera.

EDIT: Just to make a point... :devil:
char *foo (int bar, double baz)

How is this much better? I still don't have a clue what the function does, much less any idea if it is working correctly without a unit test. ;)
monjardin's JwN Meter (1,2,3,4,5,6):
|----|----|----|----|----|----|----|----|----|----|
*

### #24eddie

Senior Member

• Members
• 751 posts

Posted 01 February 2007 - 05:12 AM

monjardin said:

EDIT: Just to make a point... :devil:

char *foo (int bar, double baz)


How is this much better? I still don't have a clue what the function does, much less any idea if it is working correctly without a unit test. ;)

At first I was wondering what your point was, but I see it now, and agree completely.

For me, in a scripting language, proper naming of variables/functions is of much higher importance than the static typing of things. i.e.:


function CalculateValue(scaleValue, index);



I don't really care what the heck the type is - I can pretty much assume what it would be anyhow (a number followed by some sort of key value - the domain'll dictate what that may be). I suppose you could complain that you're never certain if there is a return value or not, but documentation should *always* be present for any public API, in my opinion -- regardless of typing, otherwise you lose out on so much *other* valuable information (units, ownership, requisites, etc).

Don't get me wrong - there's a reason why I code the majority of my stuff in C++, and strong/static typing is a very helpful reason for that. Although, one of my larger projects is almost completely written in Lua, and I have yet to complain about the typing in that project.

Every language feature has it's drawbacks, and some are just more suitable to some people's way of thinking than others, I s'pose.

### #25nopcoder

New Member

• Members
• 8 posts

Posted 01 February 2007 - 06:19 AM

monjardin said:

char *foo (int bar, double baz)

How is this much better? I still don't have a clue what the function does, much less any idea if it is working correctly without a unit test. ;)

I know it wouldn't like me very much if a send it a string, I know it does "foo" whatever that is... and why would you give me a incorrectly working function? Don't you like me?

What I'm pointing out is: if the function works great, if it doesn't then fix it!
Static typing gives me a understanding of what a function wants, which I prefer with or without comments.

eddie said:

Every language feature has it's drawbacks, and some are just more suitable to some people's way of thinking than others, I s'pose.

I love language features that go "Now its a string. Now its float. Now its a string again, no wait still a float... I think... anyways nice keyboard you got there".

### #26eddie

Senior Member

• Members
• 751 posts

Posted 01 February 2007 - 06:34 AM

nopcoder said:

I love languages that go "Now its a string. Now its float. Now its a string again, no wait still a float... I think... anyways nice keyboard you got there".

What you illustrate is a problem with the programmer, not the language. Languages aren't bipolar, no such guarantee is given to the programmers who write in them, however. ;)

I can do the same thing you mention in C++ with a couple of C style casts, and it would be no less ugly. I concede the point that the compiler gives you a warning much sooner that you're doing something stupid -- but in practice I've found that to be more of a placebo than an actual "thank-God-I've-got-strict-typing!".

Sorry if I seem a little stuck on this topic. I just remember a time when I started work at a web company, and I *loathed* JavaScript. I slowly grew to realize that it was not JavaScript I had taken issue with (it's not the first on my list of languages to work with, granted), but rather the companies implementation and lack of understanding of the language. The schizophrenia of typing you depict is precisely what happened (among other stupidity), because programmers thought reusing variables was a 'good' thing and it led to all type (pun) of havoc (what's worse: their C++ code server-side was an even more tangled mess of ignorance).

Long story short: a new junior developer started and cited that "strict typing was the cure to all ills", and I debated endlessly with him, until even he conceded: while strict typing isn't a 'bad' thing - the problem here was discipline and understanding of the code, rather than assuming a language feature will make you a better coder.

Anyhow, I realize my points probably won't sway you either way, and I imagine that's because I'm rather neutral on the whole issue -- have your strict typing in everything if you want; I see it's merits. I just don't think it should be super high on a list of priorities, particularly for a scripting language. After all, look what great applications have been built in Lua, Python, JavaScript and the like.

### #27Reedbeta

DevMaster Staff

• 5344 posts
• LocationSanta Clara, CA

Posted 01 February 2007 - 07:23 AM

monjardin said:

EDIT: Just to make a point... :devil:
char *foo (int bar, double baz)

How is this much better? I still don't have a clue what the function does, much less any idea if it is working correctly without a unit test.

Granted, you still proper documentation and tests in any case. Still, including types in the function declaration makes it much easier to extract information about the function's behavior than reading comments, IMHO. Sometimes you already know what a function does and just need a brief reminder of what the arguments are.

It doesn't really matter so much if we're talking about strings vs numbers or whatever, but it matters a lot if we're talking about ADTs. For instance, I've worked on some web app projects in PHP where functions were passing around big datastructures that had to be in a particular format (e.g. an associative array containing some particular keys whose values were other associative arrays, etc.) - it's just easier to work with if you can define a class and declare the parameter to be an object of the class, rather than having to explain the whole structure in your comments all the time.

Moreover, the error messages generated by a static type system are IMHO much more informative than in a dynamic type system. If I mess up and pass the wrong thing to a function, I want to see "function foo: expected parameter of type bar, got baz" rather than "in function foo: bop does not have method gazonk" and then have to trace back to find what went wrong.

I'm not intending to bash Lua or Javascript or anything as I've also used them successfully (in small applications); I just think static typing is more convenient and safer to use, especially in larger projects. After all, why rely solely on your programmers to adhere to a certain discipline, when you can get the compiler to enforce that discipline automatically?
reedbeta.com - developer blog, OpenGL demos, and other projects

### #28Christian Weis

New Member

• Members
• 11 posts

Posted 01 February 2007 - 12:35 PM

I personally preffer a weak typed language with strong typed capabilities just because of flexibility. But why the hell should anyone bother by using weak typed only language or even worse a typeless language when you can have strong typeness with all its benefits? (as Reedbeta observed)

Don't get me wrong. I don't want to persuade anyone here. I've just denoted that strong typeness can help you writing more robust high-quality software. That holds for scripting too.

cu,
chris

### #29nopcoder

New Member

• Members
• 8 posts

Posted 05 February 2007 - 11:55 PM

I've chosen to go with Squirrel (its not strongly typed, I know).
Thanks for all your input, I appreciate it.

### #30monjardin

Senior Member

• Members
• 1033 posts

Posted 06 February 2007 - 12:30 AM

That sounds like a good choice. I've heard Squirrel called Lua++ in the past and I've been meaning to play with it. Please let us know how it works for you!
monjardin's JwN Meter (1,2,3,4,5,6):
|----|----|----|----|----|----|----|----|----|----|
*

Member

• Members
• 39 posts
• LocationAthens, Greece

Posted 15 February 2007 - 08:57 AM

I can give you UndeadScript, my scripting engine. It's syntax looks a lot like a mix of Java and JavaScript. Here is an example of a source code file and from here you can download a test host application.

Note that the above files are a bit older and have a few bugs/missing featurs (f.e. there is no "for" there). However these are fixed in my current code.

I will release the library to the public once i finish it's documentation and make my SlashDOC source code documentation tool to understand UndeadScript. Beyond docs, UndeadScript is to a usable state (actually, i used a premature version of it in my game Nikwi - but that's a very premature version, it doesn't even have functions :-)).

The language features strong typing, classes (with inheritance), garbage collection and an "interface description language" (USI - UndeadScript Interface) which you can use to 'export' functions and classes (and/or define new) from the host program.

Note that i'm not asking anyone to use UndeadScript! I made it to be used mostly be me and i'm giving it for free to anyone who may want it, but i'm not going to get into big endless discussions about "why UndeadScript is better than 3902323.77777777777777777777 other available scripting engines". Ok?

Thank you. Now if you want it, contact me at badsector@slashstone.com. I visit my email more often than this forum :-).

### #32.oisyn

DevMaster Staff

• Moderators
• 1842 posts

Posted 15 February 2007 - 10:43 AM

Note that i'm not asking anyone to use UndeadScript! I made it to be used mostly be me and i'm giving it for free to anyone who may want it, but i'm not going to get into big endless discussions about "why UndeadScript is better than 3902323.77777777777777777777 other available scripting engines". Ok?
If you don't want that discussion, don't plug your scripting language in a thread about scripting languages.

So, how *does* UndeadScript compare to other similar scripting languages?
-
Currently working on: the 3D engine for Tomb Raider.

Member

• Members
• 39 posts
• LocationAthens, Greece

Posted 15 February 2007 - 11:32 AM

Well i said about a "big endless discussion" :-).

The problem is that i don't actually know other languages, so i can't really answer on that one. From those i know, UndeadScript is very different from a syntax point of view since it's mostly Java/JavaScript-like. It's closer to AngelScript than anything else (...i know).

### #34.oisyn

DevMaster Staff

• Moderators
• 1842 posts

Posted 15 February 2007 - 11:36 AM

Ok so you made your engine more for fun than for lack of better alternatives? (which is a perfectly good reason of course, but I'm just curious)
-
Currently working on: the 3D engine for Tomb Raider.

Member

• Members
• 39 posts
• LocationAthens, Greece

Posted 15 February 2007 - 11:45 AM

Well, my method was simply to look how LUA and Python looks*, dislike what i saw, thought that i can do it better and end with UndeadScript :-).

Of course even if there was a better solution since i prefer to solve my problems with my own stuff, it's possible that i would write UndeadScript anyway :-).

*=that means that i googled for LUA and saw some code snippets and later did some python development to make a 3d object exported for Blender3D.

#### 1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users