Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-8081-120121-

javascript vs lua

Name: Anonymous 2012-01-24 20:47

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: Anonymous 2012-01-24 20:53

JS is more expressive and popular.

Name: Anonymous 2012-01-24 21:20

how short are these timeframes?

Name: Anonymous 2012-01-24 21:34

hundreds of thousands of times in short timeframes?

luajit

Name: Anonymous 2012-01-24 21:45

>>3
enough to be tolerably interactive, so <= 50ms or so

Name: Anonymous 2012-01-24 22:53

>>1
OP is writing a game where users are required to write bots.

Name: Anonymous 2012-01-24 23:01

>>5
He wasn't asking you how long your erections last.

Name: Anonymous 2012-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: 3 2012-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: Anonymous 2012-01-25 0:09

But be warned that your user's scripts will NOT be just (sqrt (random 1000))!

Name: Anonymous 2012-01-25 0:15

>>9
Wrong, read time specification.

Name: Anonymous 2012-01-25 0:25

>>11 ???

Name: Anonymous 2012-01-25 6:08

              JJJJJJJJJJJEEEEEEEEEEEEEEEEEEEEEEWWWWWWWW                           WWWWWWWW   SSSSSSSSSSSSSSS
              J:::::::::JE::::::::::::::::::::EW::::::W                           W::::::W SS:::::::::::::::S
              J:::::::::JE::::::::::::::::::::EW::::::W                           W::::::WS:::::SSSSSS::::::S
              JJ:::::::JJEE::::::EEEEEEEEE::::EW::::::W                           W::::::WS:::::S     SSSSSSS
                J:::::J    E:::::E       EEEEEE W:::::W           WWWWW           W:::::W S:::::S          
                J:::::J    E:::::E               W:::::W         W:::::W         W:::::W  S:::::S          
                J:::::J    E::::::EEEEEEEEEE      W:::::W       W:::::::W       W:::::W    S::::SSSS       
                J:::::j    E:::::::::::::::E       W:::::W     W:::::::::W     W:::::W      SS::::::SSSSS  
                J:::::J    E:::::::::::::::E        W:::::W   W:::::W:::::W   W:::::W         SSS::::::::SS
    JJJJJJJ     J:::::J    E::::::EEEEEEEEEE         W:::::W W:::::W W:::::W W:::::W             SSSSSS::::S
    J:::::J     J:::::J    E:::::E                    W:::::W:::::W   W:::::W:::::W                   S:::::S
    J::::::J   J::::::J    E:::::E       EEEEEE        W:::::::::W     W:::::::::W                    S:::::S
    J:::::::JJJ:::::::J  EE::::::EEEEEEEE:::::E         W:::::::W       W:::::::W         SSSSSSS     S:::::S
     JJ:::::::::::::JJ   E::::::::::::::::::::E          W:::::W         W:::::W          S::::::SSSSSS:::::S
       JJ:::::::::JJ     E::::::::::::::::::::E           W:::W           W:::W           S:::::::::::::::SS
         JJJJJJJJJ       EEEEEEEEEEEEEEEEEEEEEE            WWW             WWW             SSSSSSSSSSSSSSS 

Name: Anonymous 2012-01-25 6:12

              JJJJJJJJJJJEEEEEEEEEEEEEEEEEEEEEEWWWWWWWW                           WWWWWWWW   SSSSSSSSSSSSSSS
              J:::::::::JE::::::::::::::::::::EW::::::W                           W::::::W SS:::::::::::::::S
              J:::::::::JE::::::::::::::::::::EW::::::W                           W::::::WS:::::SSSSSS::::::S
              JJ:::::::JJEE::::::EEEEEEEEE::::EW::::::W                           W::::::WS:::::S     SSSSSSS
                J:::::J    E:::::E       EEEEEE W:::::W           WWWWW           W:::::W S:::::S          
                J:::::J    E:::::E               W:::::W         W:::::W         W:::::W  S:::::S          
                J:::::J    E::::::EEEEEEEEEE      W:::::W       W:::::::W       W:::::W    S::::SSSS       
                J:::::j    E:::::::::::::::E       W:::::W     W:::::::::W     W:::::W      SS::::::SSSSS  
                J:::::J    E:::::::::::::::E        W:::::W   W:::::W:::::W   W:::::W         SSS::::::::SS
    JJJJJJJ     J:::::J    E::::::EEEEEEEEEE         W:::::W W:::::W W:::::W W:::::W             SSSSSS::::S
    J:::::J     J:::::J    E:::::E                    W:::::W:::::W   W:::::W:::::W                   S:::::S
    J::::::J   J::::::J    E:::::E       EEEEEE        W:::::::::W     W:::::::::W                    S:::::S
    J:::::::JJJ:::::::J  EE::::::EEEEEEEE:::::E         W:::::::W       W:::::::W         SSSSSSS     S:::::S
     JJ:::::::::::::JJ   E::::::::::::::::::::E          W:::::W         W:::::W          S::::::SSSSSS:::::S
       JJ:::::::::JJ     E::::::::::::::::::::E           W:::W           W:::W           S:::::::::::::::SS
         JJJJJJJJJ       EEEEEEEEEEEEEEEEEEEEEE            WWW             WWW             SSSSSSSSSSSSSSS 

Name: Anonymous 2012-01-25 6:12

              JJJJJJJJJJJEEEEEEEEEEEEEEEEEEEEEEWWWWWWWW                           WWWWWWWW   SSSSSSSSSSSSSSS
              J:::::::::JE::::::::::::::::::::EW::::::W                           W::::::W SS:::::::::::::::S
              J:::::::::JE::::::::::::::::::::EW::::::W                           W::::::WS:::::SSSSSS::::::S
              JJ:::::::JJEE::::::EEEEEEEEE::::EW::::::W                           W::::::WS:::::S     SSSSSSS
                J:::::J    E:::::E       EEEEEE W:::::W           WWWWW           W:::::W S:::::S          
                J:::::J    E:::::E               W:::::W         W:::::W         W:::::W  S:::::S          
                J:::::J    E::::::EEEEEEEEEE      W:::::W       W:::::::W       W:::::W    S::::SSSS       
                J:::::j    E:::::::::::::::E       W:::::W     W:::::::::W     W:::::W      SS::::::SSSSS  
                J:::::J    E:::::::::::::::E        W:::::W   W:::::W:::::W   W:::::W         SSS::::::::SS
    JJJJJJJ     J:::::J    E::::::EEEEEEEEEE         W:::::W W:::::W W:::::W W:::::W             SSSSSS::::S
    J:::::J     J:::::J    E:::::E                    W:::::W:::::W   W:::::W:::::W                   S:::::S
    J::::::J   J::::::J    E:::::E       EEEEEE        W:::::::::W     W:::::::::W                    S:::::S
    J:::::::JJJ:::::::J  EE::::::EEEEEEEE:::::E         W:::::::W       W:::::::W         SSSSSSS     S:::::S
     JJ:::::::::::::JJ   E::::::::::::::::::::E          W:::::W         W:::::W          S::::::SSSSSS:::::S
       JJ:::::::::JJ     E::::::::::::::::::::E           W:::W           W:::W           S:::::::::::::::SS
         JJJJJJJJJ       EEEEEEEEEEEEEEEEEEEEEE            WWW             WWW             SSSSSSSSSSSSSSS 

Name: Anonymous 2012-01-25 6:12

              JJJJJJJJJJJEEEEEEEEEEEEEEEEEEEEEEWWWWWWWW                           WWWWWWWW   SSSSSSSSSSSSSSS
              J:::::::::JE::::::::::::::::::::EW::::::W                           W::::::W SS:::::::::::::::S
              J:::::::::JE::::::::::::::::::::EW::::::W                           W::::::WS:::::SSSSSS::::::S
              JJ:::::::JJEE::::::EEEEEEEEE::::EW::::::W                           W::::::WS:::::S     SSSSSSS
                J:::::J    E:::::E       EEEEEE W:::::W           WWWWW           W:::::W S:::::S          
                J:::::J    E:::::E               W:::::W         W:::::W         W:::::W  S:::::S          
                J:::::J    E::::::EEEEEEEEEE      W:::::W       W:::::::W       W:::::W    S::::SSSS       
                J:::::j    E:::::::::::::::E       W:::::W     W:::::::::W     W:::::W      SS::::::SSSSS  
                J:::::J    E:::::::::::::::E        W:::::W   W:::::W:::::W   W:::::W         SSS::::::::SS
    JJJJJJJ     J:::::J    E::::::EEEEEEEEEE         W:::::W W:::::W W:::::W W:::::W             SSSSSS::::S
    J:::::J     J:::::J    E:::::E                    W:::::W:::::W   W:::::W:::::W                   S:::::S
    J::::::J   J::::::J    E:::::E       EEEEEE        W:::::::::W     W:::::::::W                    S:::::S
    J:::::::JJJ:::::::J  EE::::::EEEEEEEE:::::E         W:::::::W       W:::::::W         SSSSSSS     S:::::S
     JJ:::::::::::::JJ   E::::::::::::::::::::E          W:::::W         W:::::W          S::::::SSSSSS:::::S
       JJ:::::::::JJ     E::::::::::::::::::::E           W:::W           W:::W           S:::::::::::::::SS
         JJJJJJJJJ       EEEEEEEEEEEEEEEEEEEEEE            WWW             WWW             SSSSSSSSSSSSSSS 

Name: Anonymous 2012-01-25 6:12

              JJJJJJJJJJJEEEEEEEEEEEEEEEEEEEEEEWWWWWWWW                           WWWWWWWW   SSSSSSSSSSSSSSS
              J:::::::::JE::::::::::::::::::::EW::::::W                           W::::::W SS:::::::::::::::S
              J:::::::::JE::::::::::::::::::::EW::::::W                           W::::::WS:::::SSSSSS::::::S
              JJ:::::::JJEE::::::EEEEEEEEE::::EW::::::W                           W::::::WS:::::S     SSSSSSS
                J:::::J    E:::::E       EEEEEE W:::::W           WWWWW           W:::::W S:::::S          
                J:::::J    E:::::E               W:::::W         W:::::W         W:::::W  S:::::S          
                J:::::J    E::::::EEEEEEEEEE      W:::::W       W:::::::W       W:::::W    S::::SSSS       
                J:::::j    E:::::::::::::::E       W:::::W     W:::::::::W     W:::::W      SS::::::SSSSS  
                J:::::J    E:::::::::::::::E        W:::::W   W:::::W:::::W   W:::::W         SSS::::::::SS
    JJJJJJJ     J:::::J    E::::::EEEEEEEEEE         W:::::W W:::::W W:::::W W:::::W             SSSSSS::::S
    J:::::J     J:::::J    E:::::E                    W:::::W:::::W   W:::::W:::::W                   S:::::S
    J::::::J   J::::::J    E:::::E       EEEEEE        W:::::::::W     W:::::::::W                    S:::::S
    J:::::::JJJ:::::::J  EE::::::EEEEEEEE:::::E         W:::::::W       W:::::::W         SSSSSSS     S:::::S
     JJ:::::::::::::JJ   E::::::::::::::::::::E          W:::::W         W:::::W          S::::::SSSSSS:::::S
       JJ:::::::::JJ     E::::::::::::::::::::E           W:::W           W:::W           S:::::::::::::::SS
         JJJJJJJJJ       EEEEEEEEEEEEEEEEEEEEEE            WWW             WWW             SSSSSSSSSSSSSSS 

Name: Anonymous 2012-01-25 6:12

              JJJJJJJJJJJEEEEEEEEEEEEEEEEEEEEEEWWWWWWWW                           WWWWWWWW   SSSSSSSSSSSSSSS
              J:::::::::JE::::::::::::::::::::EW::::::W                           W::::::W SS:::::::::::::::S
              J:::::::::JE::::::::::::::::::::EW::::::W                           W::::::WS:::::SSSSSS::::::S
              JJ:::::::JJEE::::::EEEEEEEEE::::EW::::::W                           W::::::WS:::::S     SSSSSSS
                J:::::J    E:::::E       EEEEEE W:::::W           WWWWW           W:::::W S:::::S          
                J:::::J    E:::::E               W:::::W         W:::::W         W:::::W  S:::::S          
                J:::::J    E::::::EEEEEEEEEE      W:::::W       W:::::::W       W:::::W    S::::SSSS       
                J:::::j    E:::::::::::::::E       W:::::W     W:::::::::W     W:::::W      SS::::::SSSSS  
                J:::::J    E:::::::::::::::E        W:::::W   W:::::W:::::W   W:::::W         SSS::::::::SS
    JJJJJJJ     J:::::J    E::::::EEEEEEEEEE         W:::::W W:::::W W:::::W W:::::W             SSSSSS::::S
    J:::::J     J:::::J    E:::::E                    W:::::W:::::W   W:::::W:::::W                   S:::::S
    J::::::J   J::::::J    E:::::E       EEEEEE        W:::::::::W     W:::::::::W                    S:::::S
    J:::::::JJJ:::::::J  EE::::::EEEEEEEE:::::E         W:::::::W       W:::::::W         SSSSSSS     S:::::S
     JJ:::::::::::::JJ   E::::::::::::::::::::E          W:::::W         W:::::W          S::::::SSSSSS:::::S
       JJ:::::::::JJ     E::::::::::::::::::::E           W:::W           W:::W           S:::::::::::::::SS
         JJJJJJJJJ       EEEEEEEEEEEEEEEEEEEEEE            WWW             WWW             SSSSSSSSSSSSSSS 

Name: Anonymous 2012-01-25 15:14

>>9 '
>running evals inside loops
>evals executing the same shit anyway

wat

Name: Anonymous 2012-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: Anonymous 2012-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: Anonymous 2012-01-25 21:30

dubs

Name: Anonymous 2012-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.

Name: Anonymous 2012-01-26 0:44

>>21
Well it does have better semantics. It's a shame though, there's a lot I like about Lua.

Name: Anonymous 2012-01-26 0:57

>>24

because it uses curly braces instead of end blocks? That's symbols, not semantics.

javascript:alert("" == 0);void(0)

Name: Anonymous 2012-01-26 0:59

>>24

anyways, you can get more specific if you'd like to.

Name: Anonymous 2012-01-26 1:39

JavaScript has very intuitive type coercion; not many languages are smart enough to give you NaN because you tried adding two objects together!

Name: Anonymous 2012-01-26 1:41

I always order naan with my saagpaneer.

Name: Anonymous 2012-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)
}


etc. has horrible semantics.

Name: Anonymous 2012-01-26 9:13

>>29

partial list of fucked things in javascript

typeof is fucked, instanceof is fucked, scoping is fucked, binding of "this" context is fucked, == is fucked, reflection is fucked, prototypes are fucked

Name: Anonymous 2012-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!

Name: Anonymous 2012-01-26 13:25

>>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: Anonymous 2012-01-26 13:42

check vs dubs

Name: Anonymous 2012-01-26 13:51

>>32
How much different would this be from eval()?

Name: Anonymous 2012-01-26 13:53

>>32
Why the Javascript hate? Seriously, why the Javascript hate.

Name: Anonymous 2012-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/

>>35
javascript hate because:

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: Anonymous 2012-01-26 14:21

I hope you mental midgets realize that the original javascript language was written in less than three days.

Name: Anonymous 2012-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."

Name: Anonymous 2012-01-26 14:30

>>38
I just farted.

Name: Anonymous 2012-01-26 14:32

>>39
You gassed the Jews, you Nazi!

Name: Anonymous 2012-01-26 14:37

>>40
Well, at least the Jews aren't gonna be after me!

Name: Anonymous 2012-01-26 14:38

>>36
1. it's one of the most widely deployed languages ever, and it is easy to hate on popular things
it's easy to hate on things that suck, and oh wait
2. the language design has a few bright spots
like what? probably shit that other languages have done better, even before javascript existed

>>37
and yet a lot of people still think it's a good language and get hard over the fact that mozilla is dead-set against accepting native support for other languages in the browser (unless it's javascript-derived shit, that is). i hope something like nacl will take off but i'm not getting my hopes up. so now if you want to use FIOC or sepples, that ``designed in less than 3 days'' language is now a ``designed in less than 3 days'' virtual machine with a ``designed in less than 3 days'' feature set. except now it uses 10 times as much ram as native code and runs 1/5 the speed if even that.

Name: kodak_gallery_programmer !!qmiXqQhekkGXVVD 2012-01-26 14:44

>>42
You wanna see some really slow ass shit? Trying using Prolog.

Name: Anonymous 2012-01-26 14:52

secret dubs!

Name: Anonymous 2012-01-26 14:56

>>42
2. the language design has a few bright spots
like what? probably shit that other languages have done better, even before javascript existed

some things i like about js

1. first class functions. almost every other functional and "scripting" language has this also, of course.

2. json. compact representation of maps/dicts/hashes/"objects" and arrays literals is quite nice

Name: Anonymous 2012-01-26 19:30

JEWSON

Name: Anonymous 2012-01-26 21:01

sgddsgfgsfd

Name: Anonymous 2012-01-26 22:26

>>43

to be fair, most prolog programs are compactly expressed brute force search with worst case exponential time. Although I could see well written code taking a while to run, given everything that is happening under the hood.

Name: Anonymous 2012-01-26 22:37

>>27

1. An object is not a number.
2. not a number plus not a number is not a number.
3. Therefore, an object plus an object is not a number.

easy peazy!

Name: Anonymous 2012-01-26 22:43

>>49
i would expect an object plus an object would be a type error unless addition is overloaded by the programmer... which is yet another thing javascript fails at having

Name: Anonymous 2012-01-26 23:18

>>50


a = {};
b = {};

a.valueOf = function(){ return "Type" };
b.valueOf = function(){ return "Error" };

a + b;
=> "TypeError"


fixed!

Name: Anonymous 2012-01-26 23:21

>>49
Here is what my C view on the same thing...

"A value is the /meaning/ of an object (considered as a particular
type).  The key word here is /meaning/ - a 'value' is an
abstraction, an idea, not something that can be held in a
program, but a point in an abstract value space that follows
certain rules (eg, mathematical addition, etc).


It's true that bit patterns stored in objects are used to
represent values (again, under a particuilar type).  However, the
value itself -- the "meaning" -- is something that does not
depend on any object for its existence:  an unchanging, abstract
idea (such as, for example, the number 3).


When the Standard says an expression yields a certain value, what
that means is the program produces something whose "meaning" is
the same if the abstract value were stored into an object that
has the same type as that of the value.  (All values in C
programs are effectively indexed by what type they are.)  More
concretely, an expression like


   21 + 21


yields the same value (ie, the same meaning) as is held by
the variable 'x' (an object) after


   int x = 42;


Viewed from this perspective, what is produced by evaluating an
expression has the same meaning as some bit pattern stored in an
object.  Because it has the same meaning, it is the same value.
To say that another way, objects do hold patterns of bits that
represent values, but values don't depend on objects for their
existence -- if something has the same meaning as a certain bit
pattern would if held in an object, then that is the same value
as the object would have, whether an object is present or not.
(As always, subject to the necessary qualifications about types.)
"

Name: Anonymous 2012-01-26 23:25

>>49
2. not a number plus not a number is not a number.


typeof (NaN + NaN)
=> "number"


that's right, "not a number" is a "number"

Name: Anonymous 2012-01-27 0:17

>>53

yes. Type tree:


number
|- not a number
   |- object

Name: Anonymous 2012-01-27 0:19

Okay, but who really cares about these addition edge cases? Yeah, the plus sign is overloaded with meaning. That's because the natural expectation for adding two strings is concatenation.

But is it so obvious with arrays? Do you want to concat them, sum them, or treat them as strings (and therefore, concat them)?

And what about objects? Are you comparing them as hashes, or as an instance you want to extend with another (concat)?

There is an underlying logic to it in Javascript (valueOf, toString), so it's only incomprehensible until you take the time to comprehend it. But more importantly, there's no reason to have an expectation, because only an idiot would think the + should be expected to read your mind about what you want to do.

What happens if you put aluminum foil in an inkjet printer? I don't fucking know man, but that's a retarded idea, because printers are intended to work with paper. In theory you could do it, but you'd be a dumbass to do so. There are other ways to get ink onto surfaces that don't present the same limitations due to streamlining.

Name: Anonymous 2012-01-27 0:44

>>55'
But is it so obvious with arrays? Do you want to concat them, sum them, or treat them as strings (and therefore, concat them)?
because only an idiot would think the + should be expected to read your mind about what you want to do

wouldn't be an issue if there were a dedicated string concatenation operator, and if array -> string required an explicit conversion. then + wouldn't have to read your mind

And what about objects? Are you comparing them as hashes, or as an instance you want to extend with another (concat)?
for +? what?

>What happens if you put aluminum foil in an inkjet printer?
NaN

Name: Anonymous 2012-01-27 1:06

dedicated string concatenation operator
Oh, you mean like . in PHP, the veritable pinnacle of language design?

+ is absolutely fine. It sums numbers and concatenates strings. Really, that's not too complex for you to remember, is it?

The rest of it is the not the result of + being broken, but of type coercion being tricky. Making sure the values coming in are within expected bounds is a bread and butter programming task. + doesn't deserve any of type sanitation's backlash.

Name: Anonymous 2012-01-27 1:11

Lua is JS done right. It's pretty obvious.

Name: Anonymous 2012-01-27 1:14

>>57
+ is absolutely fine. It sums numbers and concatenates strings.

But addition is commutative and concatenation is not.

Name: Anonymous 2012-01-27 1:16

Tcl.

Name: Anonymous 2012-01-27 1:27

>>29
use map/filter/reduce

js is functional, don't treat it like C and get angry.

js has lots of problems, but libs like underscore.js make almost all of them go away.

Name: Anonymous 2012-01-27 2:02

>>59
So what? Javascript expressions are evaluated left to right.

Name: Anonymous 2012-01-27 2:14

>>58
but Javascript is a much better Scheme. Lua doesn't even try!

Name: Anonymous 2012-01-27 2:20

>>63
In fact, Lua just mooches off Python nowadays. Seriously, FIOC of all things?

Name: Anonymous 2012-01-27 2:30

>>63

once you start using all of lua's features, it gets a little insane. you can write some functions, start mapping tables, mapping iterators, composing iterators with functions, using coroutines to abstract complex algorithms as iterators, have multiple algorithms passing values back and forth to each other, using composed functions to apply filters to their inputs and outputs. The ease of functional programming is there, but there is also the convenient data entry. And it's fast, which is nice. The lack of static typing makes things hairy once it gets large though. More time is spent debugging and testing. But it can be nice for doing some quick table crunching. Although it doesn't come close to perl for text processing.

Name: Anonymous 2012-01-27 2:30

>>64

eh, you should learn more about lua.

Name: >>66 2012-01-27 3:31

it does look a lot like python at a glance though. It has some of it's features, while others are missing. Using immutable tupples for keys would have been nice. There are work arounds, but they aren't necessairly as convenient or as efficient, which is a drag.

Name: Anonymous 2012-01-27 19:54

>>65,66
i would rather have forced stringification of keys destroying my object references

Name: Anonymous 2012-01-27 23:12

Lua's equals and not equals operators are fucked up

Name: Anonymous 2012-01-27 23:23

>>69

why? because of overloading? or is just the ~= ?

Name: Anonymous 2012-01-28 0:43

>>70
Of course it's just the ~=. People here are retarted this much.

Name: Anonymous 2012-01-28 1:01

>>71
maybe it's because it doesn't fuck with the operands beforehand

Name: Anonymous 2012-01-28 1:03

>>72
You're wrong.
~-san totally fucked the shit out of ==-kun, and it's how ~=-chan was born.

Name: Anonymous 2012-01-28 18:36

>>73
bitches don't know bout my #

Name: Anonymous 2012-01-29 3:59

Lua is the coolest scripting language.

But scripting languages are kind of lame. Mostly because of the whole "mutable objects" thing. They tends to only go part way down the functional rabbit hole and I find that to be awkward.

Name: Anonymous 2012-01-29 12:25

>>1
both suck, end thread

Name: Anonymous 2012-01-29 12:25

>>76
check dubs, end thread

Name: Anonymous 2012-01-29 18:34

>>76
javascript does NOT suck, ``faggot''

Name: Anonymous 2012-01-29 19:38

$ lua
Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
x = 1
x
>>
>> ;
stdin:3: '=' expected near ';'

WTF is this shit? Do I have to wrap everything in a print() call just to see what something evaluates to?

Name: Anonymous 2012-01-29 20:00

>>79
= x

Name: Anonymous 2012-01-29 20:14

>>80
Thanks. That's kind of stupid, though.

Name: Anonymous 2012-01-30 15:41

>>80
> = "1" == 1
false

wat

Name: Anonymous 2012-01-30 17:37

>>82
Nothing wrong with that. It's far better than coercion that fails to do what you want roughly half of the time.

Name: Anonymous 2012-01-30 22:40

>>82
creten

Name: Anonymous 2012-01-31 0:08

>>82
You're not very good at any of this programming stuff are you?

Name: Anonymous 2012-01-31 2:14

>>83-85
we'll see who's laughing when browsers take over

Name: Anonymous 2012-01-31 2:27

>>86
Please elaborate on what the fuck you just said so the rest of us can start laughing now.

Name: Anonymous 2012-01-31 5:29

I prefer Javascript as it's Scheme with C style syntax.

Name: Anonymous 2012-01-31 14:00

>>86
as in, 2-3 years from now, there will be no more "native" programs apart from browsers themselves

and browsers === javascript! you'll enjoy it, trust me.

Name: Anonymous 2012-01-31 14:08

>>87
I think homegirl is talking about a loss of precision in numbers when a value undergoes an integral promotion. Oh wait, never mind. I don't think this foolholio has an ounce of programmer blood in it!

Name: Anonymous 2012-01-31 14:59

>>90
you're just mad javascript is more popular than your toy lisp

deal with it

Name: Anonymous 2012-01-31 15:02

>>89
Obviously not going to happen. Even ChomeOS is just Google Linux.

Supposing it did happen, there are languages that compile to JS, many of which are pretty damn strict about semantics. Plus you'd be out of a job. You don't even seem to know JS very well.

Name: Anonymous 2012-01-31 15:03

>>91
Javascript is toy Lisp! How is that not obvious‽

Name: Anonymous 2012-01-31 15:26

>>93
i'd like to see your lisp being used for real software

Name: >>93 2012-01-31 15:56

>>94
I wouldn't.

Name: Anonymous 2012-01-31 19:25

>>95
i wouldn't either! javascript all the way!

Name: Anonymous 2012-01-31 22:50

>>94

it was once.

Name: Anonymous 2012-01-31 22:58

>>96 see >>93

Name: Anonymous 2012-02-01 0:24

>>98
more like: lisp is toy javascript

Name: Anonymous 2012-02-01 0:46

motherfucker

Name: Anonymous 2012-02-01 16:33

I like how Lua isn't even considered OO yet it handles method calls better than Javascript

Name: Anonymous 2012-02-10 17:59

Name: Anonymous 2012-02-10 18:11

>>102
Except that both Lua and LuaJIT are less than a megabyte.

Name: Anonymous 2012-02-10 18:13

And have a great interface to C.

Name: Anonymous 2012-02-10 18:17

>>103
except they aren't javascript

Name: Anonymous 2012-02-10 18:55

>>105
And that's good!

Name: Anonymous 2012-02-10 19:12

>>106
did you even read that page, or the wiki it linked to? lua doesn't have any of that

it's obsolete

Name: Anonymous 2012-02-10 19:21

Lua is good. Just don't use vanilla Lua.

Use LuaJIT, it's what all of the professional game developers use, it has way better performance and way better C/C++ bindings.

http://luajit.org/

Name: Anonymous 2012-02-10 21:01

>>108
still doesnt add all those awesome features

Name: Anonymous 2012-02-10 21:24

>>111
sweet trips bro

Name: Anonymous 2012-02-10 21:25

>>110
Thanks homey.

Name: Anonymous 2012-02-10 21:26

>>111
anytime broski

we true tomodachi

Name: Anonymous 2012-02-11 18:19

>>102
i like the weak maps bit:
- they're exclusively weak-keyed
- they aren't enumerable, because the gc collecting fields would fuck up the iteration

in contrast to lua's weak tables (a paper on which is even mentioned in the wiki entry):
- they can be set to be weak-keyed only, weak-valued only, or both
- they can be enumerated, because next/pairs will not get confused if fields suddenly go missing

so that's at least one javascriptified feature

Name: Anonymous 2012-02-11 19:52

>>107
I laught at your .............

Name: Anonymous 2012-02-14 18:55

>>9

Right... and:

$ cat > time.lua
function analyze(s)
    local start = os.clock()
    local f = loadstring(s)
    for i = 1, 100000 do
        f()
    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    s

Multiplying loop counter by 1000 (for i = 1, 100000000 do)

$ luajit2 time.lua
math.sqrt(math.random(1000))
0.57    s

Seems like the Lua version runs in just 0.00057s...

The benchmark is pretty meaningless. It's mostly stressing parser and math.random implementation.

For math.random(), LuaJIT uses Tausworthe PRNG with period of 2^223.

V8 uses much lower quality PRNG; two 16-bit MWCs combined together. this should yield period of about 2^61, give or take.

Name: Anonymous 2012-02-14 22:30

>>115
>mfw loadstring lets you reuse what you just compiled
head full of fuck

loadstring considered unharmful

Name: Anonymous 2012-02-15 0:11

>>116
damn straight. It's like the only intelligent eval out there.

Name: Anonymous 2012-02-15 4:38

write it in python/ruby and then redo the innerloop in c

Name: Anonymous 2012-02-15 9:29

>>102

1) Lexical scoping.
Fixes Javascript specific scoping issues. About time!

2) Collections.
All you need is a Lua table, seriously. You get arrays and maps in one data type. LuaJIT gives you C-structs, with C-like memory consumption as well.

3) Weak maps.
As mentioned before, great addition. Lua has the same feature as well.

4) Proxies.
Analogous to Lua metamethods. Although Lua implementation will be more verbose, because you might need to keep one hidden 'backing' table.

Name: Anonymous 2012-02-15 12:58

>>119
Why can't ECMA or W3C just create a new language or choose a more fully-featured existing language for HTML scripting rather than bolt more hacks onto JavaScript and turn it into Frankenstein's monster? The script tag has a lang attribute for a reason.

Name: Anonymous 2012-02-15 13:09

>>119
weak maps that can't be iterated, which is really convenient considering i iterate them in the vast majority of cases i use them:

local objects = setmetatable({ }, { __mode = "k" })
local function Object (x, y)
    local o = { x = tonumber(x) or 0, y = tonumber(y) or 0 }
    objects[o] = true
    return o
end

while true do
    for o in pairs(objects) do
        some_update_function(o)
    end
end

Name: Anonymous 2012-02-15 13:11

>>120
mozilla really really wants people to use poor old javascript, thank you very much! the internet is a nacl-free zone!

Name: Anonymous 2012-02-15 13:50

>>122
nacl is great for exploiting hidden hardware exploits through injection of arbitrary code

Name: Anonymous 2012-02-15 22:58

>>113
>- they aren't enumerable, because the gc collecting fields would fuck up the iteration

what a bunch of retards.

Name: Anonymous 2012-02-15 23:57

>>124
The next thing you know, JavaScript programmers will be declaring types and calling free() because idiots are trying to abuse the poor language for purposes it was never intended for. JavaScript was a simple language designed for small client-side scripts that run inside a webpage, not distributed computing, binary file manipulation, huge games, or enterprise frameworks. "Web app developers" need to find a new language for client-side scripting before they turn JavaScript into the "Objective-C++/CLI" of the web.

Name: Anonymous 2012-02-16 0:01

>>125
but it's already the ``x86 of the web*''!!!

* http://lambda-the-ultimate.org/node/3851#comment-57671

calling something the x86 of anything sure is a compliment!

Name: Anonymous 2012-02-16 0:03

>>126
"I was convinced that we needed to build-in a programming language, but the developers, Tim first, were very much opposed. It had to remain completely declarative. Maybe, but the net result is that the programming-vacuum filled itself with the most horrible kluge in the history of computing: Javascript." - Robert Cailliau
the most horrible kluge in the history of computing
x86 of the web
Sounds about right.

Name: Anonymous 2012-02-16 3:23

>>127
x86 supremacy.

your goy shit will never make it.

Name: Anonymous 2012-02-16 3:29

>>125
I just don't understand why weak maps would be supported, but not iteration on them. Just sayin, that's kind of retarded.

Name: Anonymous 2012-02-16 14:36

>>128
Go suck an infant's cock you mental mohel.

Name: Anonymous 2012-02-17 6:02

>>130
Damn pedo.

Name: Anonymous 2012-02-17 12:09

Name: Anonymous 2012-02-17 12:19

>>130
Penis envy will get you nowhere.

Name: Anonymous 2012-02-17 12:23

>>131
Don't give unmeaningful excuses .

Name: Anonymous 2012-02-17 12:24

>>134
>>132 is unmeaningful.

Name: Anonymous 2012-02-17 19:06

but javascript has v8

Name: Anonymous 2012-02-17 20:16

>>136
but libluajit.so is just ~400k when libv8.so is near 3MB
and is quite competitive, even faster on some benchmarks, for example, n-body:

$ time luajit2 a.lua 5000000
-0.169075164
-0.169083134

real    0m2.926s
user    0m2.896s
sys    0m0.003s
$ time d8 --nodebugger a.js -- 5000000
-0.169075164
-0.169083134

real    0m5.834s
user    0m5.893s
sys    0m0.050s


Code from here http://shootout.alioth.debian.org/u32/program.php?test=nbody&lang=v8&id=1
 and here http://shootout.alioth.debian.org/u32/program.php?test=nbody&lang=lua&id=4

Name: Anonymous 2012-02-17 20:18

my mistake, luajit2 is near 700k, and v8 near 3M

Name: Anonymous 2012-02-17 21:18

>>138
it's 300k for me; you're probably thinking of the source archive

Name: Anonymous 2012-02-18 13:56

http://news.ycombinator.com/item?id=3607207
see that? javascript! don't see them considering lua anywhere!

seriously, quit wasting time and just use v8

Name: Anonymous 2012-02-18 16:11

>>140

why?

Name: Anonymous 2012-02-18 17:00

I'd use lua just because its not jabbashits. The DOM tainted that language forever.

Name: Anonymous 2012-02-18 17:52

Just tried lua.js. Works pretty nice, some built-in functions missing, notably table.concat. No showstoppers, though. All IO is also missing, except print, which outputs to console. I guess someone should write XHR, websockets and local storage library for it. Canvas, events and maybe some DOM-support would be nice too...

https://github.com/mherkender/lua.js

Name: Anonymous 2012-02-18 18:15

Seems like you can run Lua on following platforms, ie. pretty much anywhere.

Nearly all desktop operating systems; All Linux, 32/64-bit Windows, OS X, *BSD, Solaris, Haiku, etc.

Nearly all smartphone platforms: Symbian (incl. Java ME), Android, iOS, Windows Phone 7 (LuaCLR, Kopi Lua, etc.), BlackBerry

Web platforms; Web browsers capable for running Javascript, Adobe Flash, Wikipedia templates

Bytecode based VMs; .net, JVM, LLVM.

Embedded platforms; Many PS3 and Xbox 360 games use Lua, most Canon cameras via CHDK and Magic Lantern, MP3 players supported by Rockbox, large memory (128kB+ RAM) microcontrollers (eLua), many wireless routers (dd-wrt, Tomato, etc.), and a lot more.

Some more implementations here: http://lua-users.org/wiki/LuaImplementations

Name: Anonymous 2012-02-18 18:42

>>143
__mode and __gc metamethods are not supported
lol javascript

harmony mode: only the 'k' option of __mode is supported and iterating the table is a bad idea please dont do it

Name: Anonymous 2012-02-18 18:45

JavaScript is an abomination. The only good thing about it is that it's "higher-level than C." Wow! Of course a scripting language for the web is higher-level than a compiled systems language!

Name: Anonymous 2012-02-18 19:27

>>140

Ported their fib benchmark (javascript version) to Lua.

Windows 7 x64, 2.66 GHz i5, 4GB RAM. Compiled luajit 2.0.0-beta9 using "Microsoft (R) C/C++ Optimizing Compiler Version 16.00.30319.01 for x64".

luajit.exe fib_julia.lua
Lua,fib,0.113

This compares favorably to their benchmarks: http://julialang.org/
https://github.com/JuliaLang/julia/tree/48d39c542f1b2f6049d1d21585e92e3c90705397/test/perf

--

function fib(n)
    if n < 2 then return n end
    return fib(n-1) + fib(n-2)
end

tmin = math.huge
for i=1, 5, 1 do
    t = os.clock()
    for j=1, 1000, 1 do
        assert(fib(20) == 6765)
    end
    t = os.clock()-t
    if t < tmin then tmin = t end
end

print("Lua,fib," .. tmin)

Name: Anonymous 2012-02-18 19:44

So fibs is officially the benchmark of 2012?

Name: Anonymous 2012-02-18 23:56

No, but when trying to convert js perf tests to lua, I've spotted more than two variable scoping bugs..

>>147
And for fibs on my machine..
luajit2 has got ~0.00022s
v8 has got ~0.241ms

>>140 I won't consider v8 anymore, thank you.

Name: Anonymous 2012-02-19 1:15

>>140

This code runs 20% faster. Making function fib local helps a lot.

local function fib(n)
    if n < 2 then return n end
    return fib(n-1) + fib(n-2)
end

local tmin = math.huge

for i=1, 5, 1 do
    local t = os.clock()
    for j=1, 1000, 1 do
        assert(fib(20) == 6765)
    end
    t = os.clock()-t
    if t < tmin then tmin = t end
end

print("Lua,fib," .. tmin)

Name: Anonymous 2012-02-19 1:16

Ooops, meant >>147, not >>140.

Name: Anonymous 2012-02-19 4:07

APL, 18 characters:
↑¨+.×\⎕⍴⊂1 0∘.∨1 0

Name: Anonymous 2012-02-19 5:16

>>150
I see what you've done there... :3

Name: Anonymous 2012-02-19 6:09

I did the julialang.org perftest with luajit2.
$ luajit2 test.lua
luajit2,fib,0.21
luajit2,parse_int,0.53
luajit2,mandel,4.8
luajit2,quicksort,2.3
luajit2,pi_sum,34
luajit2,rand_mat_stat,110
luajit2,rand_mat_mul,16.84
$ node test.js
javascript,fib,0.242
javascript,parse_int,0.497
javascript,mandel,1.376
javascript,quicksort,3.08
javascript,pi_sum,32.2
javascript,rand_mat_stat,66
javascript,rand_mat_mul,62354


But I don't think this is valid, I've found things like 1 < x < 10, unused variables, arithmetic on undefined and NaN values...

Anyway, Luajit is quite on par with V8, but totally outperforms V8's rand_mat_mul time. With this, I can conclude that V8 is amazing, but it was really designed for the web, not as a scientific scripting language, and -- Lua, I choose you!

Name: Anonymous 2012-02-19 8:02

>>154
Nice work there. That's good to know.

Name: Anonymous 2012-11-16 1:13

>>39
I was reading this thread just now, and farted loudly in the middle of reading >>38.
Then, I scrolled down, saw your post, and was so amused by the coincidence that I had to tell you about it.

Don't change these.
Name: Email:
Entire Thread Thread List