# Open Source What is expected from a scripting language?

This topic is 369 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi,

I've been working on extending an existing scripting language which lacks some important features, especially classes and inheritance.

To implement that feature, I have used a approach similar to how they did it with Lua tables. It turned out pretty good. But I wanted more, I want scripted classes to be able to inherit from real classes like a Lua table extending a C++ class. However, I realized that would be impossible or at least take a good amount of time to implement.

I haven't made many games so I can't answer this question myself: Is the ability to inherit from real classes expected from a scripting language?

If not, it would save me plenty of time. And I think, if someone really needs that feature, they are probably write too much in scripts instead of code.

TL;DR: Is the ability of scripted classes to inherit from real classes necessary for a scripting language?

##### Share on other sites

Inheritance is hardly important as a linguistic construct. The Epoch language for example has no notion of inheritance, and deliberately so.

If you can do composition and polymorphism, you can eliminate inheritance as a feature entirely. I don't know the specifics of your language implementation, obviously, but I'd venture to guess that getting those two things working is either already done or easy to do.

##### Share on other sites
3 hours ago, ApochPiQ said:

If you can do composition and polymorphism, you can eliminate inheritance as a feature entirely.

Don't you need inheritance to polymorphism?

##### Share on other sites

Regarding polymorphism, it can be implemented with anything that allows for indirection, including a collection of function pointers.  All that matters is that you have a way to jump to the code, and a way for that code to switch between one destination or another based on what kind of thing you've got. Function tables (including vtables) to implement polymorphic behavior have been around much longer than the fancy descriptions people give them.

Back to the general question, scripting languages aren't a magical tool. They are an alternative additional source code language used to build the game. You get all the struggles of an additional source code, all the pain points of another data source, a bunch of extra stuff to test, all this plus the time to create the code in your new language. Scripting languages tend to only make sense on very large teams. The ability to derive from another class or inherit behavior from another are irrelevant to the nature of a scripting language.  If you write code in the scripting language then it needs to do whatever you need for your game, not what some arbitrary people online said that a language should do or should not do.

Can you create the game you want without adding that functionality?  If so, then don't create it, it is a waste of time. If not, then it is something your product needs and you should get on that.  My hunch is that it is not necessary for the task, otherwise you wouldn't be asking.

##### Share on other sites
1 hour ago, Alpha_ProgDes said:

Don't you need inheritance to polymorphism?

Duck typing or just compositional objects (like in JS - similar principle) could be used as an easy substitute. In duck typed languages an object will respond to any valid member operation regardless of its type.

For example, in Ruby:

class Dog
def speak
puts "Woof!"
end
end

class Cat
def speak
puts "Meow!"
end
end

ary = [ Dog.new, Cat.new ]

for animal in ary
animal.speak
end

Output is as expected.

Edited by Khatharr

##### Share on other sites
9 hours ago, ApochPiQ said:

Inheritance is hardly important as a linguistic construct. The Epoch language for example has no notion of inheritance, and deliberately so.

If you can do composition and polymorphism, you can eliminate inheritance as a feature entirely. I don't know the specifics of your language implementation, obviously, but I'd venture to guess that getting those two things working is either already done or easy to do.

1

Ooh, I see. Thank you for the answer Apoch! Cool to see that you have written your own Epoch language!

Indeed, the language which I'm working on already has composition and polymorphism before I came to add inheritance to it. But now you can create a new script object extending another user-created script object and classes written in code but the only thing is polymorphism doesn't work between script objects and coded classes. I'll just leave it like that unless someone asks for it.

Also thanks to Alpha_ProgDes, frob and Khatharr for discussing polymorphism.

1. 1
Rutin
19
2. 2
3. 3
JoeJ
16
4. 4
5. 5

• 27
• 20
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631700
• Total Posts
3001791
×