View mode: basic / threaded / horizontal-split · Log in · Help
March 15, 2012
Re: Dynamic language
On 3/15/12 3:58 AM, F i L wrote:
> Not really a help to you, but I honestly have no idea why people *want*
> to use dynamic programming languages. There is very little benefit I see
> in having your core object structure be complete dynamic. I remember
> watching this Google tech talk awhile ago, about V8 and improving
> Javascript performance. At one point, the speaker talks about how cool
> Dynamic objects *can* be, but then goes on later to say that 90% of code
> isn't structured that way (and thus justifying V8's JITed hidden classes).
>
> I think a language should be static first and dynamic second. C# does
> this nicely (anonymous and dynamic types, Link, etc) and I think D is at
> least partially there (in regards to dynamic objects) with std.variant +
> associative arrays.

Relevant insight: 
http://existentialtype.wordpress.com/2011/03/19/dynamic-languages-are-static-languages/

Andrei
March 15, 2012
Re: Dynamic language
On Thursday, 15 March 2012 at 07:09:39 UTC, so wrote:
> I want to invest some "quality" time on a dynamic language but 
> i am not sure which one. Would you please suggest one?

D!

I'm not kidding... let's look at a list of things
you might want:

* You mentioned lisp. One of the cooler things there
  are macros. (And I like the syntax too. It is weird,
  but elegant.)

You can go hog wild with lisp macros, generating all
kinds of new things.

In D, you can do similar metaprogramming with
templates and mixins. The syntax is different, of course,
but you can do much of the same stuff.

* Modifying builtin types and methods. In D, you can
achieve this with classes, UFCS, or alias this.

Javascript might do:

String.prototype.awesome = function() { return 
this.toUpperCase(); }

Then, you can call it like so:

"cool".awesome(); // returns "COOL"


In D, of course, you can just write:

string awesome(string s) {
    return toUpper(s);
}

"cool".awesome(); // returns "COOL"



The newest dmd extends this to more types than just arrays.



What about an integer that subtracts instead of adds?

struct Int {
   int payload;
   alias payload this;

   this(int a) { payload = a; }

   Int opBinary(string op : "+")(int rhs) {
       return Int(payload - rhs);
   }
}


Now use Int instead of int in your code:


void main() {
	Int a = 10;
	assert(a + 5 == 5);
}

and you can pass it to things that expect int, though
you won't get the magic behavior there.


* You might want to replace methods on a function that
doesn't expect it.


This is where we substitute our behavior in code that
doesn't expect it at all... and that's exactly what
class method overriding does.


* You want to get properties or behavior from some outside
  source.

This is where you might use something like Variant, or string
conversions depending on how you got the data.


Javascript:

var a = JSON.parse("[1,2,3]");
assert(a[0] == 1); // pretend js has assert...

D:

auto a = JSON.parse("[1,2,3]"); // see Robert Jacques std.json 
and std.variant, though the version I have doesn't compile right 
with new phobos, it can be fixed
assert(a[0] == 1);


* You want to build objects and properties on the fly.


Javascript:

var a = {};
a.sweet = 10;
a.cool = function() { this.sweet++; }
a.cool();
assert(a.sweet == 11);

D:

import std.variant;
struct Extendable {
    Variant[string] properties;
    Variant opDispatch(string name)() {
       return properties[name];
    }
    Variant opDispatch(string name, T)(T t) {
       properties[name] = t;
       return properties[name];
    }
}

void main() {
    auto a = Extendable();
    a.sweet = 10;
    a.cool = { a.sweet = a.sweet + 1; } // could probably fix ++ 
too..
    // fails with std.variant but the language *could* do it
    a.cool(); // exercise for the reader: maek this work! Gotta 
add opCall.
}





But, yeah, you can seriously use D to explore dynamic programming
as well as programmable programming languages if you want to.

It checks most the big boxes.
March 15, 2012
Re: Dynamic language
On Thursday, 15 March 2012 at 07:09:39 UTC, so wrote:
> If so Lisp will be my first choice.

I just talked about D because D rox, but if you are doing
it for education, Lisp is a good choice because it is fairly
unique.

For real jobs, I'd go with D or maybe Javascript if I wanted
scripting. (Javascript isn't a great language, but it is good
enough, well supported, and popular; people can pick it up
and go pretty easily. I've previously used Lisp for scripting -
you can make a Lisp interpreter in ~1,000 lines of code - but
JS has decent interpreters out there too.)


But for education, Lisp's uniqueness is a good thing -
experiencing the new syntax and playing with the macros
is a good way to learn things you might have not looked
at otherwise.


So I'll second Lisp if you don't want to play with D.
March 15, 2012
Re: Dynamic language
Thank you all!

On Thursday, 15 March 2012 at 17:30:49 UTC, Adam D. Ruppe wrote:
> On Thursday, 15 March 2012 at 07:09:39 UTC, so wrote:
>> If so Lisp will be my first choice.
>
> I just talked about D because D rox, but if you are doing
> it for education, Lisp is a good choice because it is fairly
> unique.

I'd love to use D but it is not an option is it? At least for the 
things i am after, say game scripting.

> But for education, Lisp's uniqueness is a good thing -
> experiencing the new syntax and playing with the macros
> is a good way to learn things you might have not looked
> at otherwise.

I wouldn't mind learning something new! Looks like either way 
Lisp will be on my reading list.
March 15, 2012
Re: Dynamic language
On 15 March 2012 20:59, so <so@so.so> wrote:

> Thank you all!
>
>
> On Thursday, 15 March 2012 at 17:30:49 UTC, Adam D. Ruppe wrote:
>
>> On Thursday, 15 March 2012 at 07:09:39 UTC, so wrote:
>>
>>> If so Lisp will be my first choice.
>>>
>>
>> I just talked about D because D rox, but if you are doing
>> it for education, Lisp is a good choice because it is fairly
>> unique.
>>
>
> I'd love to use D but it is not an option is it? At least for the things i
> am after, say game scripting.


I dunno, that sounds like a pretty interesting idea to me! :)
March 15, 2012
Re: Dynamic language
"so" <so@so.so> wrote in message 
news:uamqdkmnshxmvayeumbz@forum.dlang.org...
> Hello,
>
> Not related to D but this is a community which i can find at least a few 
> objective person. I want to invest some "quality" time on a dynamic 
> language but i am not sure which one. Would you please suggest one?
>
> To give you an idea what i am after:
> Of all one-liners i have heard only one gets me.
> "The programmable programming language". Is it true? If so Lisp will be my 
> first choice.
>


I'd say it depends:

- If can can tolerate the parenthesis-hell and goofy prefix notation 
(instead of infix), then LISP has been said to be the generalization of all 
other langauges. IIRC, I heard that it was created specifically as an 
example of a "programmable programming language".

- If you're looking for performace and practical real-world usage as a way 
to add scripting support to a program, Lua is considerd king for that.

- If you can stomach the indent-scoping, Python is very well-regarded and 
has a lot of fancy advanced features.

- If you don't like indent-scoping, Ruby is probably about the closest there 
is to a block-scoped Python.

- If you're looking for the most painful dynamic experince imaginable, 
ActionScript2 should be at the top of your list. Make sure to use all-Adobe 
tools, and the newest versions of each, so the whole experience will be 
*truly* unbearable.

I admit though, I'm not very familiar with the extent of the metaprogramming 
abilities of any of those languages.
March 15, 2012
Re: Dynamic language
"so" <so@so.so> wrote in message 
news:rxuivgogjashzlkeeknx@forum.dlang.org...
> Thank you all!
>
> On Thursday, 15 March 2012 at 17:30:49 UTC, Adam D. Ruppe wrote:
>> On Thursday, 15 March 2012 at 07:09:39 UTC, so wrote:
>>> If so Lisp will be my first choice.
>>
>> I just talked about D because D rox, but if you are doing
>> it for education, Lisp is a good choice because it is fairly
>> unique.
>
> I'd love to use D but it is not an option is it? At least for the things i 
> am after, say game scripting.
>

I've often thought about it. What you would do is compile & load the 
"script" sections as dynamic libraries. Then, even the game engine itself 
could just invoke the command-line statement to compile the "script" to a 
dynamic library, and then reload the new dynamic library.

Quake 2 used DLLs instead of a "scripting" language.

As for other langauges:

Lua is currently *king* for game scripting. It's used all over the gaming 
industry because it's fast and integrates with C very easily. Personally, I 
don't like it because it *is* a dynamic langauge. But if you're looking for 
a dynamic language, well, then there's that.

Back in the 90's, the game Abuse famously had all its gameplay code written 
in LISP. It's been open-sourced, so you can can find the source and look 
through it.
March 15, 2012
Re: Dynamic language
On Thursday, 15 March 2012 at 19:25:24 UTC, Nick Sabalausky wrote:
> "so" <so@so.so> wrote in message
> news:uamqdkmnshxmvayeumbz@forum.dlang.org...
>> Hello,
>>
>> Not related to D but this is a community which i can find at 
>> least a few objective person. I want to invest some "quality" 
>> time on a dynamic language but i am not sure which one. Would 
>> you please suggest one?
>>
>> To give you an idea what i am after:
>> Of all one-liners i have heard only one gets me.
>> "The programmable programming language". Is it true? If so 
>> Lisp will be my first choice.
>>
>
>
> I'd say it depends:
>
> - If can can tolerate the parenthesis-hell and goofy prefix 
> notation
> (instead of infix), then LISP has been said to be the 
> generalization of all
> other langauges. IIRC, I heard that it was created specifically 
> as an
> example of a "programmable programming language".
>
> - If you're looking for performace and practical real-world 
> usage as a way
> to add scripting support to a program, Lua is considerd king 
> for that.
>
> - If you can stomach the indent-scoping, Python is very 
> well-regarded and
> has a lot of fancy advanced features.
>
> - If you don't like indent-scoping, Ruby is probably about the 
> closest there
> is to a block-scoped Python.
>
> - If you're looking for the most painful dynamic experince 
> imaginable,
> ActionScript2 should be at the top of your list. Make sure to 
> use all-Adobe
> tools, and the newest versions of each, so the whole experience 
> will be
> *truly* unbearable.
>
> I admit though, I'm not very familiar with the extent of the 
> metaprogramming
> abilities of any of those languages.

Metaprogramming abilities is the first thing i check now. After 
the painful experience of C/C++. I just can't "repeat" codes and 
when i have no options, i just curse the language :)

Fanatics don't get it. How much a simple tool like "static if" 
improves the entire template mechanism and makes it something 
enjoyable. What the hell is a killer app if this is not for a 
programmer?
March 15, 2012
Re: Dynamic language
On Thursday, 15 March 2012 at 19:35:15 UTC, Nick Sabalausky wrote:

> As for other langauges:
>
> Lua is currently *king* for game scripting. It's used all over 
> the gaming
> industry because it's fast and integrates with C very easily. 
> Personally, I
> don't like it because it *is* a dynamic langauge. But if you're 
> looking for
> a dynamic language, well, then there's that.

Not just because i am looking for, how would you code a 
customizable ui (wow ui for example) without an interpreter? You 
got no other options AFAIK when it comes to customizable stuff.
March 15, 2012
Re: Dynamic language
On Thu, Mar 15, 2012 at 09:15:34PM +0200, Manu wrote:
> On 15 March 2012 20:59, so <so@so.so> wrote:
[...]
> > On Thursday, 15 March 2012 at 17:30:49 UTC, Adam D. Ruppe wrote:
[...]
> >> I just talked about D because D rox, but if you are doing it for
> >> education, Lisp is a good choice because it is fairly unique.
> >>
> >
> > I'd love to use D but it is not an option is it? At least for the
> > things i am after, say game scripting.
> 
> 
> I dunno, that sounds like a pretty interesting idea to me! :)

It certainly is, though it does bring up the problem of what to do if
the game scripting is editable at runtime. Does that mean we'll need to
bundle a D compiler with the game? Doesn't seem practical.


T

-- 
Государство делает вид, что платит нам зарплату, а мы делаем вид, что работаем.
1 2 3 4 5 6
Top | Discussion index | About this forum | D home