let's say i might be working on something ``secret'' and i want to embed a scripting language that isn't too off the wall for end users. i hear luajit is kinda fast and v8 is really fast and speed would be quite nice since user scripts might be called hundreds of thousands of times in short timeframes
i've heard javascript has better semantics and is generally more pleasant to use, but i want /prog/'s opinion so i don't fuck up and regret it later
Name:
Anonymous2012-01-24 20:53
JS is more expressive and popular.
Name:
Anonymous2012-01-24 21:20
how short are these timeframes?
Name:
Anonymous2012-01-24 21:34
hundreds of thousands of times in short timeframes?
luajit
Name:
Anonymous2012-01-24 21:45
>>3
enough to be tolerably interactive, so <= 50ms or so
Name:
Anonymous2012-01-24 22:53
>>1
OP is writing a game where users are required to write bots.
Name:
Anonymous2012-01-24 23:01
>>5
He wasn't asking you how long your erections last.
Name:
Anonymous2012-01-24 23:09
I find lua nice, and the built in hash tables are nice and has convenient syntax. It can be easy to create a table of string values to arbitrary keys in javascript, but you'll have to get creative if you want to use arbitrary objects as keys.
Name:
32012-01-25 0:07
>>1 hundreds of thousands of times (sic)
<= 50ms
V8 wins.
$ cat > time.lisp
(defun analyze (s)
(time
(loop for i from 1 to 100000 do
(eval s))))
(loop (analyze (read)))
$ sbcl --script time.lisp
Evaluation took:
0.241 seconds of real time
0.239984 seconds of total run time (0.236651 user, 0.003333 system)
99.59% CPU
300,000 forms interpreted
674,617,678 processor cycles
14,415,488 bytes consed
$ cat > time.lua
function analyze(s)
local start = os.clock()
for i = 1, 100000 do
assert(loadstring(s))()
end
print(os.clock() - start, "s")
end
for expr in io.lines() do
analyze(expr)
end
$ luajit2 time.lua
math.sqrt(math.random(1000))
0.17 s
$ cat > time.js
function analyze(s) {
var start = (new Date).getTime();
for (var i = 0; i < 100000; i++) {
eval(s);
}
print((new Date).getTime() - start, "ms");
}
while (expr = readline()) {
analyze(expr);
}
$ d8 time.js
Math.sqrt(Math.random(1000))
36 ms
Name:
Anonymous2012-01-25 0:09
But be warned that your user's scripts will NOT be just (sqrt (random 1000))!
>>9'
>running evals inside loops
>evals executing the same shit anyway
wat
Name:
Anonymous2012-01-25 17:04
>>9
hmm... i noticed the lua version doing an extra function call after the loadstring: assert(loadstring(s))()
looks i could just store the compiled code in a variable and reuse it all i want, instead of having to reload the user code on each update (or iteration in this case). pretty neat!
once i moved that above the loop, the execution time dropped below the timer resolution
Name:
Anonymous2012-01-25 19:22
i've heard javascript has better semantics
Wait what? You heard this out of a justin bieber song being played backwards?
Name:
Anonymous2012-01-25 21:30
dubs
Name:
Anonymous2012-01-26 0:40
Its too bad luajit was taken out of that language shootout, and the luajit.org benchmarks are only in comparison with lua for some reason. The shootout guy should have just picked luajit over lua if he wanted just one lua, since luajit is more in the performance game than the reference.
JavaScript has very intuitive type coercion; not many languages are smart enough to give you NaN because you tried adding two objects together!
Name:
Anonymous2012-01-26 1:41
I always order naan with my saagpaneer.
Name:
Anonymous2012-01-26 8:00
>>24
Are we talking about the same language? Lua isn't as nice to program in as ruby/python because of how minimal it is but it has very simple and sane semantics. Javascript on the other hand with its mess of undefined/false/zero values, different comparison operators, often unintuitive coercions, control structures not making a new scope so you have to use this abomination:
for(i=0;i<something;i++){
function(localvar){
...
}(i)
}
typeof is fucked, instanceof is fucked, scoping is fucked, binding of "this" context is fucked, == is fucked, reflection is fucked, prototypes are fucked
Name:
Anonymous2012-01-26 13:15
>>29 control structures not making a new scope so you have to use this abomination
Ha-ha, and you don't have proper macros to fix it either!
>>31
I recall reading somewhere that macros are planned for a future Javascript version.
I'm expecting they won't be hygienic, and because this is Javascript they will be totally broken. Oh and IE won't support them either. Mozilla and Google will add mutually incompatible extensions to their implementations.
But Javascript and HTML5 are the ``future of programming'' so it's OK!
Name:
Anonymous2012-01-26 13:42
check vs dubs
Name:
Anonymous2012-01-26 13:51
>>32
How much different would this be from eval()?
Name:
Anonymous2012-01-26 13:53
>>32
Why the Javascript hate? Seriously, why the Javascript hate.
Name:
Anonymous2012-01-26 14:09
>>32
i doubt proper macros will be added. javascript syntax would be very painful and clunky to deal with via macros.
there are some tools to mess with the js syntax tree like http://jsshaper.org/
1. it's one of the most widely deployed languages ever, and it is easy to hate on popular things
2. the language design has a few bright spots, but many dumb blunders that won't ever get fixed
Name:
Anonymous2012-01-26 14:21
I hope you mental midgets realize that the original javascript language was written in less than three days.
Name:
Anonymous2012-01-26 14:26
>>37
yes we know. he did a good job given the time constraints. that doesn't excuse persisting poor design. also, it wasn't less than three days you dummy:
"As you may know, I wrote JavaScript in ten days."