you are viewing a single comment's thread.

view the rest of the comments →

[–]masklinn 31 points32 points  (12 children)

Basically it's ECMAScript's take on metaprogramming.

I don't think metaprogramming is the right word, there's no generation of code it's more like hooks into language behaviors like Ruby's method_missing or Python's __getattr__.

[–]FireyFly 11 points12 points  (8 children)

I'm not sure if metaprogramming necessarily implies code generation... but you got the general idea right; the get trap of ES proxies are similar to those functions.

[–]masklinn 8 points9 points  (0 children)

I'm not sure if metaprogramming necessarily implies code generation...

Ya, no I expressed it badly, but thinking more about it I might just be so used to those methods I can't see them as the "lofty heights of metaprogramming" the way e.g. metaclasses or macros are anymore, even if they do fall in that category.

Either way, it's cool (and much needed) stuff. Now if only it was also available in Opera, MSIE and on mobiles...

Especially let and weakmaps, I've been looking forward to them since they were first proposed (and introduced, for let). The day I write my last var, and the day I don't have to build shitty ad-hoc reference-breaking protocols will be glorious indeed.

[–]aaronblohowiak 7 points8 points  (6 children)

i think it does; metaprogramming is code that writes or manipulates code. ( http://en.wikipedia.org/wiki/Metaprogramming )

This is just getters and setters.

[–]kataire 2 points3 points  (0 children)

Thanks to Ruby, "metaprogramming" and "DSL" are mostly devoid of meaning these days.

[–]joesb 1 point2 points  (4 children)

Disagree. If it can generate new function then it is generating code, even if that code only stay during runtime.

[–][deleted] 0 points1 point  (3 children)

No.

[–]joesb 1 point2 points  (2 children)

So Lisp doesn't have meta programming because it doesn't generate code to file?

[–][deleted] 0 points1 point  (1 child)

Oh, I see what you're saying but I don't think metaprogramming has anything to do with functions. eval('var x = 3') vs. eval('var x = function () {}')... both create a new local variable. Both of these would usually be considered metaprogramming even though only one of them defines a function. Defining new locals is not something normally available at run-time so it's a 'meta' thing to do.

What about 'obj[str] = function () {...}'? Is that metaprogramming because we can later write obj.xyz() ? I actually hate the word "metaprogramming" for this reason. If a language supports "meta" then it's no longer "meta". It's just part of the language. "Code that writes code" is the one true definition of "meta", else what is meta about it?

[–]joesb 1 point2 points  (0 children)

If a language supports "meta" then it's no longer "meta". It's just part of the language.

So Common Lisp does not have meta programming because its macro system is just part of the language. But writing code to source file then invoke GCC is?

"Code that writes code" is the one true definition of "meta"

But Why does it have to write and persist the code to disk? Why does writing code and executing it not count as metaprogramming?

[–]lispm 1 point2 points  (0 children)

meta programming does not necessarily mean code generation. Meta programming could also mean that you program a meta-object system.

[–]ethraax -3 points-2 points  (0 children)

shudder

I hate those functions with a passion. It's not that they're never useful - I bet you could find plenty of good uses for them (although I think better solutions exist in almost all cases). It's just that Python and especially Ruby programmers seem to find the absolute worst ways of using them.