The Squirrel Programming Language
squirrel-lang.org
squirrel-lang.org
Example:
class Klass
//struct Klass
{
int_t i;
//constructor()
Klass()
{
print("Klass constructor", i);
}
~Klass()
{
print("Klass destructor");
}
}
Klass k = new Klass();
typedef int_t int;
int test10(int x)
{
dente:
if(x > 10)
{
goto dente;
goto done;
return true;
}
done:
return false;
}
print(test10(23));
output:
test-class-constructor.nut:22:6 warning labels are only parsed right now
test-class-constructor.nut:25:7 warning goto is only parsed right now
test-class-constructor.nut:26:7 warning goto is only parsed right now
test-class-constructor.nut:29:5 warning labels are only parsed right now
Klass constructor (null : 0x(nil))
truehttps://computerscomputing.wordpress.com/2013/02/18/lua-and-...
Huh, it actually seems like an older language, it's been around for a while and it's used in some major studio games.
* C++ < ANSI C
* two null types < one nil type
* separate types for arrays and dicts < tables
* C syntax < plain english
* Builtin classes < make-your-own classes
That's just my opinion though :)
Instead, you could just use an OOP library, or implement the parts of OOP you want in like 20 lines of Lua.
The great thing about this is you can fine-tune it to your needs. Want transparent encapsulation, or multiple inheritance? It just takes an extra 10-20 lines of code! Now you don't have to pester the Squirrel developers to put it in. :p
- there is exactly one way to do it
- objects can be transported between codebases without wrappers
- beginners know where to look and everybody can understand everybody's codebase
- the compiler can optimise them better- generally the syntax is nicer, looking at some object implementations in lua I must say that they are hideous, very similar to object implementations in javascript before ES6
For the beginners thing: most beginners who use Lua don't even touch OOP. The main idea for Lua is to have concepts that are super easy for a layman to fit in their head; OOP is like this huge convoluted "idea" that has a bunch of different possible implementations and approaches.
Plus... setting up the userscript/metatable structure goes a long way in abstracting it for beginners; look at how Garry's Mod does it for in-game weapons. It doesn't even use full OOP, all it has is inheritance and it doesn't even call it that; opting to call superclasses the "base" weapon. It was easy enough for me as a 12 year old non-programmer to grasp.
Plus... seeing words like "class" or "constructor" would for sure deter beginners. It's not expressive enough. When I started out, I remember looking at the curly braces for a table and thinking it was some advanced programmer stuff, and I avoided it as much as possible. That feeling would probably be 10x for something like full-blown OOP.
Once you force them to leave the editor to learn some concept on Wikipedia, you lost IMO.
I agree with you on the optimization/syntax thing, but I think it's a necessary tradeoff. Any feature that is built into the language can get some sort of buff from that sort of stuff. I just don't think the pros outweigh the cons... Lua isn't the kind of language to leverage OOP much (other than inheritance).
For me, this is pretty much the extent of OOP I've needed in Lua (along with transparent encapsulation, but I cut that code out because it would add around 10-15 more lines):
OBJECT = {}
function OBJECT:new()
local obj = {}
setmetatable(obj, {__index = self})
return obj
end
local subclass = OBJECT:new()
This, combined with tables and closures, has suited me just fine.No? Use lua.
Why?
Types.
I cannot stand the road that new languages are on, abandoning the type system, or making it optional, or not explicit. Given that I appear to be a minority, I thank you for reading my rant... Have a good day :(
On the other side of the spectrum, type systems get stronger and more powerful. Read about dependent typing in Idris, F*. Also, nearly all academic work focuses on improved type systems.
I listen to a lot of podcasts. My god, I just want a decent show that is NOT focused on web development. Is that so much to ask? Oh, and not ios/windows focused, 'cus then literally everything you talk about no longer applies to me. And not "a new language every week" because my god, you can't deep-delve into anything like that. Hell, not even javascript can be covered in an hour.
- Type hinting is a significant new feature in PHP 7.x: http://php.net/manual/en/migration70.new-features.php
- Python 3.5 introduces type hinting: https://docs.python.org/3/library/typing.html
- Ruby is talking about possibly adding a static typing system to Ruby 3.x (this is very early stage, but there appears to be interest): https://codon.com/consider-static-typing. Also 24 days ago Matz talked about possibly adding type inference to Ruby3x3: https://bugs.ruby-lang.org/issues/9999
- Flow and TypeScript add types to JavaScript.
- JavaScript is adding more structure to its type system with ES6 classes.
- Newer languages such as Swift and Dart are certainly more typed than the Python/Ruby/JavaScript generation.
- Rust is typed to the max.
I guess what I'm saying is that if you like type systems, the future is bright. :)
// Method in some class in squirrel script
function Move()
{
// ...
Jump();
// ...
}So... Where is the implementation of function Jump? In this class? Or in C++ class, which might add some methods to squirrel? Or it's in base class of squirrel? Or in C++ class of that base[squirrel] class? Also methods might be overridden. So... You need to find last implementation of that function.
You also need manually build an inheritance tree.
It's impossible to navigate in it's code. While you can use Sublime and it's Find. You still need to look through all the usages of function Jump in entire game.
Squirrel made me love all static typed languages with it's instant jump to implementation of some function.
You should certainly have a look at "less mainstream" languages whose type systems are more expressive and still simpler to use than those of the "mainstream" languages. For example (list is incomplete, but you'll get the idea):
* Haskell (very popular, hard to reason about performance, though)
* OCaml (possible to reason about performance, except for garbage collection)
* Idris (type system with dependent types!)
* Rust (type system that allows to reason about memory usage, aliasing, etc.)
* Elm (meant to replace JavaScript for user interfaces in the browser)I'm not quite agreed on the effects bit being useful, but it's a good demo of what the type system can do. My main disagreement with the whole approach is that effects don't commute (in general) and so representing effects as such isn't quite valid.
[1] I'm still baffled as to why they named it thusly. I mean, I can guess at motivations, but it really deserves a much catchier name!
That trend is so 10 years ago. Today the pendulum is swinging the other way again. ML is having a comeback. Look at F#, Rust and Swift. They are mainstream and they are strongly typed (mostly)functional languages.
One of the more interesting contenders in the "compile to Javascript" universe is Elm, which is also statically typed.
Perhaps are simply unaware of what the major "new languages" are.
I'd like to note that what you're talking about isn't "typing" versus "no typing", it's static typing versus dynamic typing. Both of them have type systems - it's just a question of whether the compiler refuses to compile programs unless it can prove that your usage of types is 100% correct. Since you sound like you're an autodidact, you might want to read up on some of the theory behind type systems - particularly the competing ideas of "soundness" and "completeness".
There are also good reasons why many people choose to use languages like Python or Ruby - they aren't just blindly ignorant of type theory or the benefits of type checking. They write different kinds of software than you do and have different needs. It's not a contest, other people using languages with dynamic typing does not mean there aren't great choices if you prefer static typing.
Edit: Squirrel also isn't a new language. It's from 2003, and it was designed for the niche of game scripting where its main competitors (Python, Lua) are all very dynamic too.
You have to declare types in the languages you mention. You shouldn't have to. Type inference was figured out decades ago, it can be done by the compiler, and in some languages, it is.