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

node.js is the new java

Name: Anonymous 2012-09-09 8:35

it greatly improves on it's predecessors
familiar syntax
it's designed to be practical, to the chagrin of CS purists
next-generation of applications being built (hadoop, palantir, runsecape :  asana, meteor)

Name: Anonymous 2012-09-09 9:14

"runsecape"

Is that suppose to be runescape, runescape or what?

Name: Anonymous 2012-09-09 9:32

The Achilles Heel of JavaScript is its inconsistent behavior across implementations. It is virtually impossible to use it to do anything robust on the client side.

JavaScript is weakly typed, and the automatic coercions that it does can produce surprising results. "2" + "3" is "23" (+, when applied to two strings, performs concatenation); "2" * "3" is 6. (Multiplication not defined for strings; so the language tries converting them to numerals, succeeds, and multiplies those). This can be surprising.

Rather annoying gotcha in array constructor. new Array() produces empty array; new Array(2,3) produces array with 2 and 3 as its elements. new Array(5) does not produce array with 5 as its single element; instead, it returns a 5-element array!

Whereas most languages have one universal singular value (null/nil/Void/whatever); JavaScript has three - "false", "null" and "undefined". That leads to confusing and irregular semantics.

No integral types - the only numeric type supported is an IEEE754 double-precision float. For a scripting language, this limitation is probably less obnoxious than it would be elsewhere.

Language has LexicalScoping, but with an interesting twist. Unlike JavaScripts brethen C/C++/Java/C#/etc, where variables introduced in an anonymous block within a function are only valid within that block; in JavaScript such variables are valid for the entire function.

Every script is executed in a single global namespace that is accessible in browsers with the window object.

Automatic type conversion between strings and numbers, combined with '+' overloaded to mean concatenation and addition. This creates very counterintuitive effects if you accidentally convert a number to a string:

 var i = 1; 
 // some code
 i = i + ""; // oops!
 // some more code
 i + 1;  // evaluates to the String '11'
 i - 1;  // evaluates to the Number 0

The automatic type conversion of the + function also leads to the intuitive effect that += 1 is different then the ++ operator:

 var j = "1";
 j++; // j becomes 2
 
 var k = "1";
 k += 1; // k becomes "11"


'' == '0' //false
0 == '' //true
0 == '0' //true
false == 'false' //false
false == '0' //true
false == undefined //false
false == null //false
null == undefined //true
typeof NaN //number
NaN == NaN //false

var a = [123];
var b = 123;
a == b; //true
a[0] == b[0]; //false

var a = [0];
a == a;  //true
a == !a; //true

" \t\r\n" == 0 // true
Math.min() < Math.max(); // false
",,," == Array((null,'cool',false,NaN,4)); // true

new Array([],null,undefined,null) == ",,,"; // true

var foo = [0];
foo == foo  // true
foo == !foo // true

function toInt(number) {return number && + number | 0 || 0;}
toInt("1");  // 1
toInt("1.2");  // 1
toInt("-1.2");  // -1
toInt(1.2);  // 1
toInt(0);  // 0
toInt("0");  // 0
toInt(Number.NaN);  // 0
toInt(1/0);  // 0


[] + [] //
[] + {} // [object Object]
{} + [] // 0
{} + {} // NaN
"S" - 1 // NaN


$ js --version
JavaScript-C 1.7.0 2007-10-03
usage: js [-PswWxCi] [-b branchlimit] [-c stackchunksize] [-v version] [-f scriptfile] [-e script] [-S maxstacksize] [scriptfile] [scriptarg...]
$ js
js> 0 == ''
true
js> false == 'false'
false
js> false == '0'
true
js> false == undefined
false
js> " \t\r\n" == 0
true
js> Math.min() < Math.max()
false
js> ",,," == Array((null,'cool',false,NaN,4))
true
js> var foo = [0]
js> foo == foo
true
js> foo == !foo
true
js> function toInt(number) {return number && + number | 0 || 0;}
js> toInt("1")
1
js> toInt("1.2")
1
js> toInt("-1.2")
-1
js> toInt(1/0)
0
js>

Name: Anonymous 2012-09-09 9:42

designed to be practical

Symta:

point X Y = [X=X; Y=Y; add P = point X+P.X Y+P.Y]


JavaScript:

function point(X,Y)
{
  this.X = X;
  this.Y = Y;
  this.add = function (P) { return point (this.X + P.X, this.Y + P.Y); }
}

Name: replying to a pasta 2012-09-09 10:06

>>3
>Rather annoying gotcha in array constructor.
Only PHP ``programmers'' call the constructor by its name, everybody else uses [].
>has LexicalScoping
and gets it right. u mad?
>Every script is executed in a single global namespace that is accessible in browsers with the window object.
Just wrong. Is that copied from c2, I thought they knew their Closures?

But yeah the type system is fucked up.

Name: Anonymous 2012-09-09 10:16

>>5
replying to a pasta
I bet you also has habit talking to bots. Is that because real girls ignore you, jerk-script faggot?

Name: Anonymous 2012-09-09 12:32

>verbose
>no operator overloading
>js jits use almost as much ram as jvm
>impressive in benchmarks and not so much outside of it

Name: Anonymous 2012-09-09 12:38

It is a web.scripting language that can't even multithread. Only idiots think node is good.

Name: Anonymous 2012-09-09 12:45

node.js? more like 'nad.jizz!

Name: Anonymous 2012-09-09 12:49

>>5
Lexical scoping in JS would be okay if there was a let statement so you wouldn't have to do

  for (i = 0; i < N; i++) {
      (function (item) {
          add_event_handler(function () {
              /* use item, can't use items[i] since i it contains a new value */
          });
      })(items[i]);
  }


The distance between where the name item is introduced and the place it is assigned is not good.

Instead it should look something like this

  for (i = 0; i < N; i++) {
      let {
          var item = items[i];
          add_event_handler(function () {
              /* item is a new lexically scoped name and is invisible outside of the let block */
          });
      }
  }

Name: Anonymous 2012-09-09 12:54

>>10
you're just jelly your toy language doesn't have javascript-tier closures

Name: Anonymous 2012-09-09 15:29

Name: Anonymous 2012-09-09 17:08

>>3
thanks for extending my metaphor. java also had a ton of gotchas, but the underlying principles were a step above every language that came before it.

Name: Anonymous 2012-09-09 17:35

Java is shit.

node.js is the new shit?

Name: Anonymous 2012-09-09 17:51

>>13
but the underlying principles were a step above every language that came before it.
MaximumTrollingOverdrive

Name: Anonymous 2012-09-09 20:57

>>4
Have you released any versions newer than 0.1?

Name: Anonymous 2012-09-10 0:14

>>16
I'm working on a video game right now.

Name: Anonymous 2012-09-10 1:32

Shaw is the original writer of the Mongrel web server for Ruby web applications. Mongrel was the first web server used by Twitter, and inspired Node.js according to Ryan Dahl
http://en.wikipedia.org/wiki/Zed_Shaw

Name: Anonymouth 2012-09-10 5:18

>>3
Where is this copy pasta? It's awesome I need to give this to my colleges.

I think I wanted to make Lua the new web browser .js, but Lisp sounds like a better choice.

And recommendations /prog/

Name: Anonymous 2012-09-10 5:20

Name: Anonymous 2012-09-10 6:25

wtf is "Symta" ? I can't find it on the internets. halp!

Name: Anonymous 2012-09-10 6:28

>>21
Some example code in it...

m:with @Xs X \= $X $@Xs

_ X -> y
_? X -> ptrEq _ X

abort = cl (abort)
tag X = cl (`get-type` X)

bound? X = cl (boundp X)

prn X = cl (prn X)

pp X = say X p:ø = X


m:i   X \= cl (let ((&X @$X)) (declare (fixnum &X)) &X)
m:f4  X \= cl (let ((&X @$X)) (declare (`single-float` &X)) &X)
m:i8  X \= cl (let ((&X @$X)) (declare (`double-float` &X)) &X)
m:is  X \= cl (let ((&X @$X)) (declare ((`simple-array` fixnum) &X)) &X)
m:f4s X \= cl (let ((&X @$X)) (declare ((`simple-array` `single-float`) &X)) &X)
m:f8s X \= cl (let ((&X @$X)) (declare ((`simple-array` `double-float`) &X)) &X)

m:unsafe @Body \= cl (locally (declare (optimize (safety 0) (speed 3))) @$Body)

// Usage: alias vlfn veryLongFunctionName
m:alias A B \= (m:$A @Xs = «$$B $@Xs»)

dasm X = cl (disassemble X) = ø

immediate? X = cl (and (imm? X) (not (`fn-sym?` X)))
m:dup N @X = {lt X,len 2 && immediate? X,0 = «vec $N init:$X,0»; «vec $N | map <&A=@$X>»}

// not beginning with, like ^ in regexps (use with pattern matcher)
m:nb X = \<&L = ne (lhd &L) $X>

// usage: foo X:of,«A B C» = say "X is one of the first three letters"
m:of Xs \= <&X = fnd &X $Xs>
sconc a b = conc a b | sym

filter f Xs = fold <A B = {f B = [@A It]; A}> [[]@Xs]
flat [@Xs] = mapc flat Xs;  X=[X]
includes P [X:_:@!P @_]=X; P [_@Xs] = includes P Xs

rmap f [@Xs] = map (rmap f ?) Xs | f
    ;f X = f X

digits X = map num X,prn,str

//insert `sep` between elements of a list `l`
//Usage: infix "+" {a b c}
//Example: map ?,hex "LISP" | infix " " | fold sconc
//TODO: add flag to create (`+` A (`+` B C)) like lists
infix Sep L = fold [@? Sep ??] [(take 1 L) @L,ltl]
join S Xs = infix S Xs | fold conc

cut P S Xs = drop P Xs | take S

// mappend from CL
// Example: maps I=" " ?,hex str,"LISP"
mapc f Xs I:{ø} = map f !Xs = {I = infix I !Xs} = fold conc Xs

subst Src Dst L = map <!Src=Dst; X=X> L

// takeInit odd? [1 5 1 2 3 1 1 2 3] --> (1 5 1)
takeInit P [@Xs @(nb P)] = Xs // Take initial elements for which `p` is true

trim Xs S:{" "} I:{ø} L:{√} R:{√}
 = Xs:Xs,str
   X:{L &&  (pos (ne ? S) Xs) = It; 0}
   Y:{R && ~(pos (ne ? S) Xs) = It; 0}
 = {I = conc (take X Xs) (take Y Xs); drop Y (drop X Xs)} | sym

// break list into piles of `n` items
grp N [@Xs] = [(take N Xs) @(drop N Xs | grp N)]

// partition by `f`
part f Xs = R:ø = map <X=[@!R.(f X) X]> Xs = map ?,1 R

// Example1: unfold <1=ø; X=[X-1 1]> 7
// Example2: qsort Xs = Xs |
//             unfold <[X]    = X
//                    ;[X@Xs] = [(keep (lt ? X) Xs) [X] (keep (gt ? X) Xs)]>
unfold f O = f O | <ø=[O]; Xs = mapc (unfold f ?) Xs>

// counts the number of ones in the bit representation of an integer
// use it to calculate size of bitmasks
bitCount X = cl (logcount X)

// bit-length of an integer:  2^(log 2 ? | ceil)
bitLen X = cl (`integer-length` X)

// inverts `bits` bits in `value` (bitwise not)
inv Bits Value = cl (logxor (ash 1 Bits)-1 Value)

exp X = cl (exp X)
log Base X = cl (log X Base)
sin X = cl (sin X)
cos X = cl (cos X)
tan X = cl (tan X)
asin X = cl (asin X)
acos X = cl (acos X)
atan X = cl (atan X)

sum S = fold `+` [0@S]
prod S = fold `*` [1@S]
avg Xs = Xs,sum/Xs,len
dot Xs Ys = cl (`dot-lists` Xs Ys)
abs X = {num? X = cl abs X; cl (`dot-lists` X X) | sqrt}
norm V = V/V,abs
transpose V = N:0 = [V,lhd,len++(map <X = I:N = !N+1 = X,I> V)]


pick Xs:y? = cl (ind Xs (random (len Xs)))
randRng S E = (abs E+1-S),rand+S
//shuffle Xs = sort Xs by:<X=1.0,rand>
//shuffle Xs:y? = I:Xs,len,rand = [Xs,I @(shuffle ~@Xs,I)]

// convert list to set (an ordered list that does not have duplicated elements)
uniq L = L,sort,<[@A X X @B]=[@A @[X @B],r]; E=E>

// set operations
union A B = A,<[X@Xs] = {fnd X B =    Xs,r ; [X@Xs,r]}; _=B>
isect A B = A,<[X@Xs] = {fnd X B = [X@Xs,r];    Xs,r}>
diff A B = union (skip (fnd ? B) A) (skip (fnd ? A) B)
ss [X@Xs] = R:{ss Xs; [ø]} [@R @(map [X @?] R)]

m:ldb Pos Size Value \= <P S V = (cl ldb (byte S P) V)> $Pos $Size $Value

maximize p [M@Xs]
 = S:M,p = fe <X = NS:X,p = {NS > S = (M=X) = (S=NS)}> Xs = M
 
minimize p [M@Xs]
 = S:M,p = fe <X = NS:X,p = {NS < S = (M=X) = (S=NS)}> Xs = M

m:while Test @Expr \= fc <= {$Test = $Expr = r}>
m:until Test @Expr \= while (n? $Test) $@Expr
m:loop Expr \= fc <:&r = $Expr = &r>

// Usage: times I:10 say i
m:times Head @Expr = C:Head,<[":" C N]=C; _=\&C>
                     N:Head,<[":" C N]=N; X=X  >
                  \= &E:$N = 0,<:&r (&E) $C = $Expr = &r $C+1>

// for (I:0; I<6; !I+1) say I
m:for «$@V; $@C; $@I» @Body = \(= $@V = cl (while @$C @$Body $@(map \@$? I)))
     ;[":" $X $Xs] @Body \= fe <$X=$@Body> $Xs

// usage: gen X^2 for X:1..10 if X,odd?
//        gen [X Y Z] for X:1..21 Y:X..21 Z:Y..21 if X^2 + Y^2 == Z^2
//m:gen @E \for @F \if @C
//  \= &Xs:n try &Xs $@(map <[O A B]=[O A \(amb $B)]> F)
//       {$@C = [@!&Xs $@E]}
//       bt


// these will generate list of ascending/descending numbers
// FIXME: merge these into `..`
asc Start = seq Start (asc Start+1)
dsc Start = seq Start (dsc Start-1)

// repeat sequence
rep [@Xs] = N:Xs,len 0,<I = seq Xs,(I%N) (r I+1)>


seqMap f [X@Xs] = seq X,f (seqMap f Xs)
seqConc [A@As] Bs = seq A (seqConc As Bs)
       ;  _    Bs = Bs
seqAdd [A@As] [B@Bs] = seq A+B (seqAdd As Bs)


words S = subst "\n" " " S,str | split " " | skip n? | map sym
lines S = split "\n" S,str
flines Name = fget Name | split "\n",int | map utf8dec

// maps values in sorted list
bmap f Xs = map <[K V]=[K V,f]> Xs

// count number of P occurencies in Xs
cnt P Xs = C:0 = for X:Xs {eq X P = !C+1} = C

zip A B = map [? ??] A B
enum Xs = I:~1 = map [!I+1 ?] Xs

m:pop L = \(&R:(lhd $L) = ltl !$L = &R)

Name: Anonymous 2012-09-10 6:31

>>22
nevermind then. looks like Perl and Haskell had a threesome with PHP.

Name: Anonymous 2012-09-10 6:34

>>21,23
No. It's the “In-Lisp” DSL.

Name: Anonymous 2012-09-10 6:34

>>23
despite it has nothing to do with them.

Name: Anonymous 2012-09-10 6:35

>>24
“In-Your-Mom” DSL.

Name: Anonymous 2012-09-10 8:11

>>21,25
Ok then, any link to a spec, tutorial or anything? I honestly can't find anything on the internet on this "Symta", not even a blurb on wikipedia..

Name: Anonymous 2012-09-10 8:41

>>27
It's a proprietary language for exclusive use by the “In-Lisp guy”.

Name: Anonymous 2012-09-10 8:46

Name: Anonymous 2012-09-10 9:15

>>28
Well he did release an implementation back when he trolled us with the Warcraft screenshots.

Name: FrozenAnus 2012-09-10 9:58

This place hasn't changed in the 3 years since I left it.


-----
Sent from my iPad

Name: Anonymous 2012-09-10 10:40

I honestly hate JS but Node.js is too damn easy to use to ignore it. Why isn't asynchronous programming easy to use in other languages as well?

Name: Anonymous 2012-09-10 11:14

>>32
I don't know Node.js but asynchronous programming is a misfeature in almost all cases because it obscures code even more than spaghetti and it actually has lower performance than proper synchronous programming.

Name: Anonymous 2012-09-10 11:35

>it actually has lower performance than proper synchronous programming.

Please provide some examples for that ludicrous claim.

Name: 33 2012-09-10 12:15

>>34
The mental and technical overhead of handling asynchronicity outweigh its advantages, since it has none. There really is no place for asynchronous callbacks outside of a hardware interrupt queueing events in a buffer and waking a thread up from select or similar.
Think about it and if you still think my claim is ludicrous afterwards, ask again for examples.

Name: Anonymous 2012-09-10 12:22

>>35
- node.js uses [code]select[code] to wait for network events
- network events are largely asynchronous
- networking is one of the project's primary intentions (http support is built-in)
Ergo your wrong bitch.

Name: Anonymous 2012-09-10 12:26

>>36
posting without my BBcode compiler

Name: Anonymous 2012-09-10 12:29

Java
GC is shit.

Name: 33,35 2012-09-10 12:33

>>36
I'm afraid your reasoning is flawed. The POSIX Programmer's Manual explicitly says that select is “synchronous I/O multiplexing”.

Name: Anonymous 2012-09-10 12:45

>>39
I'm afraid your anus is flawed. You can write async javascript even when the underlying network ballsack is ``synchronous I/O multiplexing''. Such is abstraction.

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