Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Kekekela
Oct 28, 2004
Some of the poo poo in that waterline article, dear god.

Adbot
ADBOT LOVES YOU

geeves
Sep 16, 2004

German Joey posted:

Yeah, I just saw that too, and its finally the tipping point for me where I just gave up on node.js completely and go back to Django, or maybe Flask or Mojolicious, I haven't 100% decided yet. But absolutely that blogpost was the moment that I just said "gently caress it, I'm out, I can't deal with this node.js poo poo anymore." I'd rather spend a couple weeks rewriting my entire project then waste one more day fighting with a broken library. Maybe Sequelize is good now (I remember looking at that one specifically a few years ago and it being inadequate, although that was probably an early version because this looks OK), but the trend is pointing to probably not. I'm so sick of every loving javascript library being terrible!!! ARRGHH! Time after time after time, every new thing I look at has some flashy splash page but lovely, outdated, and inconsistent documentation. Every framework has ten trillion pointless preprocessors being stapled to it that otherwise reinvent the same drat wheel. If you need layers upon layers upon layers of build tools for your server-side javascript, then what the gently caress is the point of using javascript on the server side to begin with? Isn't the whole point that both client/server are in the same language, a language that everyone in the entire drat world happens to know and have access to - a language that any ten year old can start playing around with by pressing ctrl-shift-j in their browser? That's why I got into node.js to begin with!

And why is there so many broken rear end libraries/tools in the javascript ecosystem that do the exact same thing and NONE of them work right? It is a pandemic in the Javascript world that completely unlike any other language community I've seen. Even Perl's CPAN, which has shitloads of silly (e.g. the entire Acme:: namespace) and half-baked modules is nowhere near as bad as Javascript's situation because the vast majority of modules there are well-documented, automatically tested, reviewed... and centralized so you can see everything relevant at once. In contrast, new alternatives for the most minor goddamn poo poo are all over the web, especially client libraries. I find that raw jQuery is consistently the only thing I feel I can put my faith in. When I try searching for a new javascript library, I've realized that my initial expectation of *anything* I find is that it will not work or be what I need until proven otherwise. The general trend is to try to make easy poo poo even easier (why? why so much effort on something people can already do just fine?) while very few care about trying to make hard poo poo possible.

Sails/Waterline was the one framework I'd seen that even seemed like it was trying to move in the right direction, and then that turns out to be riddled with mind-bogglingly inane poo poo like this? "mystery 50ms sleep calls in put/post requests" "The .count function used to work by pulling the entire table into memory and checking the length of the resulting array." "table joins randomly deleting tables" "i don't even know what to say about this" I just need code that's supposed to work to just actually work, goddammit!

Next time I'm in an interview, if I'm asked about node.js this will be my answer :hfive:

Odette
Mar 19, 2011

Is node.js really that bad?

Just wondering cause I'm trying to learn the MEAN stack as opposed to a standard LAMP stack.

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

Odette posted:

Is node.js really that bad?

Just wondering cause I'm trying to learn the MEAN stack as opposed to a standard LAMP stack.
A lot of the problems are overblown, especially since io.js was merged back in and Node itself seems to be going in a sane direction again, but there is a problem with a lot of Node.js libraries and frameworks being real poo poo. Your average NPM package has about the average quality of something from PEAR.

Video Nasty
Jun 17, 2003

node.js is cool, if you don't rely on it or associated repo's for anything in production environments.

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.
node.js is cool and good as long as you, er, don't ever give it write access to your datastores it seems. Node.js is great for what it's good at, which is more front end style tasks like templating and lightweight communications. It is not a good option for the entire stack because the libraries that get you to a full stack are just not there, as evidenced by projects like Waterline being one of the main SQL access libraries, yet making a mockery of things like Data Integrity.

Maluco Marinero fucked around with this message at 01:12 on Sep 9, 2015

piratepilates
Mar 28, 2004

So I will learn to live with it. Because I can live with it. I can live with it.



As much as we hate on node.js (and I'm pretty sure most of us still have jobs paying us to work with it that we go along with) I feel like it's a way better idea than any LAMP stack.

Node.js has some very boneheaded stuff in it but you can still go pretty far if you pick the things you're using in it right.

Knifegrab
Jul 30, 2014

Gadzooks! I'm terrified of this little child who is going to stab me with a knife. I must wrest the knife away from his control and therefore gain the upperhand.
Speaking of node and js, what is the standard way to declare functions? is it:

code:
function myFunc(poop) {};
OR

code:
var myFunc = function(poop) {};
I've seen both ways, both being used by novice and expert coders alike.

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

Knifegrab posted:

Speaking of node and js, what is the standard way to declare functions? is it:

code:
function myFunc(poop) {};
OR

code:
var myFunc = function(poop) {};
I've seen both ways, both being used by novice and expert coders alike.
It really just depends on where you want the function's name scoped

obstipator
Nov 8, 2009

by FactsAreUseless

Knifegrab posted:

Speaking of node and js, what is the standard way to declare functions? is it:

code:
function myFunc(poop) {};
OR

code:
var myFunc = function(poop) {};
I've seen both ways, both being used by novice and expert coders alike.

It's all about hoisting. When you type the first one, as the javascript compiles, it notices that there's a function definition and it "processes" it's instructions up before everything else in scope. With the variablized version, it doesn't jump ahead and take care of it's existence until it hits the line it's defined on.

console.log(poo poo());
var poo poo = function(){};
// errors because "poo poo" hasn't been defined yet

console.log(poop());
function poop(){}
// works, because poop's definition gets moved to the top of the current scope.

function poop(){} should be used more for a constant definition that cannot change. The variable'd version should be used when you could possibly want to swap out the function that the variable holds, if that makes sense.

And with a file required by node, you have to do the exports.poo poo = function(){} in order to make the function public to outside files.

German Joey
Dec 18, 2004

Odette posted:

Is node.js really that bad?

Just wondering cause I'm trying to learn the MEAN stack as opposed to a standard LAMP stack.

I feel like node.js in isolation is cool and very suitable to be the core of some types of webapps, like the one i've been working on. However, the problem is that you're never going to be "just" using node.js itself, as, surprisingly, its much more "close to the metal" than you'd expect. Your app is thus node.js + something, and in fact more like node.js + express + something + something + something + something + something + etc; not even counting your database or frontend stuff. Essentially, you'll absolutely need some sort of framework to help you manage the complexity of a large application, and all that other stuff... that's where you start the downward spiral into a world of poo poo.

Worlds of poo poo inside worlds of poo poo inside worlds of poo poo... turds all the way down, each more solid than the last... and finally, at the core, you'll find the node.js server engine itself. Perhaps it truly is made of solid gold..? But how long will you need to boil it in bleach to remove that smell..?

German Joey fucked around with this message at 01:52 on Sep 9, 2015

Kekekela
Oct 28, 2004
"and I'm pretty sure most of us still have jobs paying us to work with it that we go along with"
Oddly enough I write C#/ASP.NET stuff for a living and honestly just find the whole node.js ecosystem fun to gently caress around with (especially since all I really need is sublime and a command prompt), in addition to getting warm and fuzzies from contributing to open source projects which its kind of enabled for me. I'm also pretty sure its contributed in weird and good ways to the msft stuff I write.

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS

piratepilates posted:

As much as we hate on node.js (and I'm pretty sure most of us still have jobs paying us to work with it that we go along with) I feel like it's a way better idea than any LAMP stack.

Node.js has some very boneheaded stuff in it but you can still go pretty far if you pick the things you're using in it right.

Disagree. While it's still a miserable language, PHP has made leaps and bounds since PHP 4 or even PHP 5.3. It's not great, but PHP 5.6 and the more modern frameworks make working with the language tolerable rather than maddeningly frustrating like node.js.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
Does node.js have sane error handling yet? That's the one thing I've hated, though, to be fair, a lot of other languages and frameworks are also much worse. Promises just made things worse by having things drop errors on the floor by default.

piratepilates
Mar 28, 2004

So I will learn to live with it. Because I can live with it. I can live with it.



Suspicious Dish posted:

Does node.js have sane error handling yet? That's the one thing I've hated, though, to be fair, a lot of other languages and frameworks are also much worse. Promises just made things worse by having things drop errors on the floor by default.

Bluebird made uncaught errors in promises throw on the event loop, I know the major browsers do the same with native Promises, and probably iojs too.

RobertKerans
Aug 25, 2006

There is a heppy lend
Fur, fur aw-a-a-ay.
I'm playing around with the bind operator, and just for the experiment's sake I was trying to figure out how to have an optional first parameter that defaults to this.
So I have lib of a virtual functions, looks something like this:
code:
const List = {
  delete(item) {
    let index = this.indexOf(item)
    if(!index in this) return this

    return this.filter((_, i) => index !== i)
  },

  delete_at(index) {
    if(!index in this) return this

    return this.filter((_, i) => index !== i)
  }
}
Where I can do something like this, ie exactly the same as method chaining:

code:
> [0,1,2,3,4,5]::List.delete(5)::List.delete_at(0)
[1,2,3,4]
Which is cool, but I kinda want this option (like Underscore/LoDash allows), to optionally pass the item to operate on as the first argument or use this, and I'm at a loss:

code:
> List.delete([0,1,2,3], 2)
[0,1,3]
> [0,1,2,3]::List.delete(2)
[0,1,3]
Edit: nevermind, fixing the arity of the functions works.
So if done extremely naively:

code:
function add(a,b) {
  if(arguments.length == 1) {
     b = a
     a = this
  }
  return a + b
}

---

> 1::add(2)
3
> add(1,2)
3
Only thing is, how the hell do I pass the context through a decorator function, I just want to write this once for the entire lib, but I can't get it to give me the right this context

code:
const enforceArity = function(fun) {
  return function(...args) {
    if (wrongNumberOfArgs) {
      throw new Error('yadda yadda')
    } else if(fun.length - args.length == 1) {
      return // various attempts to call the function with the local `this` as first arg
    } else {
     return fun(...args)
    }
  }
}

const add = function(a,b) { return a + b }
const Calc = {
  add: enforceArity(add)
}

---

> Calc.add(1,2)
3
> 1::Calc.add(2)
NaN every time

// Explicitly:
> let c = Calc.add.bind(1)
> c(2)
NaN every time

RobertKerans fucked around with this message at 12:33 on Sep 9, 2015

piratepilates
Mar 28, 2004

So I will learn to live with it. Because I can live with it. I can live with it.



RobertKerans posted:

I'm playing around with the bind operator, and just for the experiment's sake I was trying to figure out how to have an optional first parameter that defaults to this.
So I have lib of a virtual functions, looks something like this:
code:
const List = {
  delete(item) {
    let index = this.indexOf(item)
    if(!index in this) return this

    return this.filter((_, i) => index !== i)
  },

  delete_at(index) {
    if(!index in this) return this

    return this.filter((_, i) => index !== i)
  }
}
Where I can do something like this, ie exactly the same as method chaining:

code:
> [0,1,2,3,4,5]::List.delete(5)::List.delete_at(0)
[1,2,3,4]
Which is cool, but I kinda want this option (like Underscore/LoDash allows), to optionally pass the item to operate on as the first argument or use this, and I'm at a loss:

code:
> List.delete([0,1,2,3], 2)
[0,1,3]
> [0,1,2,3]::List.delete(2)
[0,1,3]
Edit: nevermind, fixing the arity of the functions works.
So if done extremely naively:

code:
function add(a,b) {
  if(arguments.length == 1) {
     b = a
     a = this
  }
  return a + b
}

---

> 1::add(2)
3
> add(1,2)
3
Only thing is, how the hell do I pass the context through a decorator function, I just want to write this once for the entire lib, but I can't get it to give me the right this context

code:
const enforceArity = function(fun) {
  return function(...args) {
    if (wrongNumberOfArgs) {
      throw new Error('yadda yadda')
    } else if(fun.length - args.length == 1) {
      return // various attempts to call the function with the local `this` as first arg
    } else {
     return fun(...args)
    }
  }
}

const add = function(a,b) { return a + b }
const Calc = {
  add: enforceArity(add)
}

---

> Calc.add(1,2)
3
> 1::Calc.add(2)
NaN every time

// Explicitly:
> let c = Calc.add.bind(1)
> c(2)
NaN every time

On my phone so this may not make sense, but try using .call or .apply in your decorator with 'this' as the first argument to one of those two functions to preserve the value of 'this'.

RobertKerans
Aug 25, 2006

There is a heppy lend
Fur, fur aw-a-a-ay.
Aha, cheers, I was trying most of that & it wasn't working, but I am an idiot, wasn't passing it again to the function.
Also had to explicitly pass the arity, myFunction.length didn't seem to be picking up the function length for some reason v0v All tests green, so I'm happy

code:
const enforceArity = (fn, arity) =>
  function(...args) {
    if(arity - args.length < 1) throw new Error('Not enough arguments passed.')
    if(args.length - arity > 0) throw new Error('Too many arguments passed.')

    if (arity - args.length == 1) {
      return fn.call(this, this, ...args)
    } else {
      return fn.call(null, ...args)
    }
  }
Well, that was fun-ish, I'll stop trying to implement unix pipe operators & go and do some real work

RobertKerans fucked around with this message at 16:39 on Sep 9, 2015

Knifegrab
Jul 30, 2014

Gadzooks! I'm terrified of this little child who is going to stab me with a knife. I must wrest the knife away from his control and therefore gain the upperhand.

obstipator posted:

It's all about hoisting. When you type the first one, as the javascript compiles, it notices that there's a function definition and it "processes" it's instructions up before everything else in scope. With the variablized version, it doesn't jump ahead and take care of it's existence until it hits the line it's defined on.

console.log(poo poo());
var poo poo = function(){};
// errors because "poo poo" hasn't been defined yet

console.log(poop());
function poop(){}
// works, because poop's definition gets moved to the top of the current scope.

function poop(){} should be used more for a constant definition that cannot change. The variable'd version should be used when you could possibly want to swap out the function that the variable holds, if that makes sense.

And with a file required by node, you have to do the exports.poo poo = function(){} in order to make the function public to outside files.

Thanks, I totally get it now!

edit: Got another standards question. What is the standard in terms of encapsulating object properties? E.g.:

code:
var object = {
   field: "foo"
}
Versus:

code:
var object = {
  "field": "foo"
}
I know they're both valid but is there a "right" way?

Knifegrab fucked around with this message at 00:09 on Sep 10, 2015

pepito sanchez
Apr 3, 2004
I'm not mexican

Knifegrab posted:


I know they're both valid but is there a "right" way?

iirc it makes no difference except without quotes you USED TO be able to iterate over keys easier. now it's all different with ES5

(okay i was setting up a jsfiddle but for some reason it was blowing up on me)
code:
var myObj = 
    {
        "key0" : "0",
        "key1" : "1",
        "key2" : "2"
    };

var keys = Object.keys(myObj);

for(var i = 0; i < keys.length; i++){
    var val = myObj[keys[i]];
    $("#val1").val(val);
}
//different way of doing it
Object.keys(myObj).forEach(function (key) {
    var val = myObj[key];
    $("#val2").val(val);
});
also other stuff in ES5 letting you do the same, and ES6 has even more stuff!

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

pepito sanchez posted:

iirc it makes no difference except without quotes you USED TO be able to iterate over keys easier. now it's all different with ES5

What was easier about iterating over keys without quotes? They should produce identical objects.

Knifegrab
Jul 30, 2014

Gadzooks! I'm terrified of this little child who is going to stab me with a knife. I must wrest the knife away from his control and therefore gain the upperhand.

Subjunctive posted:

What was easier about iterating over keys without quotes? They should produce identical objects.

Yeah I'm also struggling to see the difference. My assumption was that they literally produce the same object, it was more a best practices question but am I to believe they actually produce different objects?

pepito sanchez
Apr 3, 2004
I'm not mexican
agh it's been a while. the quotes made it easier to iterate, not the other way around. i should've clarified how. and only for iteration in a certain way (with a for loop) and only if you, for some odd reason give your keys funky numerical names in the first place. this might be desirable for something like pushing new keys into an existing array of objects. i personally never did this that way. it's the way object keys are accessed.

was about to do more [code] but found this very helpful link that answers stuff
https://mathiasbynens.be/notes/javascript-properties

also worth noting that you have to use double quotes if you work with JSON, because some parsers are dumb.

qntm
Jun 17, 2009

pepito sanchez posted:

also worth noting that you have to use double quotes if you work with JSON, because some parsers are dumb.

If your parser allows anything else, it is your parser who is dumb!

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



pepito sanchez posted:

agh it's been a while. the quotes made it easier to iterate, not the other way around. i should've clarified how. and only for iteration in a certain way (with a for loop) and only if you, for some odd reason give your keys funky numerical names in the first place. this might be desirable for something like pushing new keys into an existing array of objects. i personally never did this that way. it's the way object keys are accessed.

was about to do more [code] but found this very helpful link that answers stuff
https://mathiasbynens.be/notes/javascript-properties

But how does it make iteration easier/better/faster/whatever?

quote:

also worth noting that you have to use double quotes if you work with JSON, because some parsers are dumb.

lol standards amirite :rolleye:

Munkeymon fucked around with this message at 16:10 on Sep 10, 2015

Chenghiz
Feb 14, 2007

WHITE WHALE
HOLY GRAIL
Quotes also let you define keys with spaces in them.

RobertKerans
Aug 25, 2006

There is a heppy lend
Fur, fur aw-a-a-ay.
I have never encountered this before, and it's breaking a load of my tests, just wondering if anyone could explain it:



code:
> function itself() { return this }
undefined
> e = itself.bind('foo')
[Function]
> e()
{ '0': 'f',
  '1': 'o',
  '2': 'o' }
I don't get it, why can I not just have a string returned back to me instead of a literal representation of a boxed version? I don't see why that's too much to ask for

Edit arrgh FFS course I've encountered this thing before, bind call and apply all convert primitives to objects, it just generally hasn't made any difference to the actual end result :barf:

RobertKerans fucked around with this message at 16:21 on Sep 10, 2015

Sedro
Dec 31, 2008

RobertKerans posted:

I have never encountered this before, and it's breaking a load of my tests, just wondering if anyone could explain it:



code:
> function itself() { return this }
undefined
> e = itself.bind('foo')
[Function]
> e()
{ '0': 'f',
  '1': 'o',
  '2': 'o' }
I don't get it, why can I not just have a string returned back to me instead of a literal representation of a boxed version? I don't see why that's too much to ask for

Edit arrgh FFS course I've encountered this thing before, bind call and apply all convert primitives to objects, it just generally hasn't made any difference to the actual end result :barf:

Use strict mode
JavaScript code:
function itself() { return this }
>undefined
e = itself.bind('foo')
>function () { [native code] }
e()
>String {0: "f", 1: "o", 2: "o", length: 3, [[PrimitiveValue]]: "foo"}

function itself() { 'use strict'; return this }
>undefined
e = itself.bind('foo')
>function () { [native code] }
e()
>"foo"

RobertKerans
Aug 25, 2006

There is a heppy lend
Fur, fur aw-a-a-ay.
Ah god, thank you, that is easier than this idiotic switch statement I was building to check for primitives. Sidenote though, I thought using ES6 via babel-node would do that for me automatically, but no, might submit an issue
EDIT: nope, not doing it for me here, back to the switch statement for the minute.
EDIT2: to clarify, works fine if I manually type it into the repl, does not work fine if I run tests (which in theory are just running the same code with the same repl commands)

RobertKerans fucked around with this message at 16:52 on Sep 10, 2015

Sedro
Dec 31, 2008
I use babel too and it puts 'use strict' in every module.

It doesn't hurt to explicitly use strict mode in your case though. Someone could always copy/paste that code and run it in a different context.

Knifegrab
Jul 30, 2014

Gadzooks! I'm terrified of this little child who is going to stab me with a knife. I must wrest the knife away from his control and therefore gain the upperhand.

Chenghiz posted:

Quotes also let you define keys with spaces in them.

What kind of monster does this!?

RobertKerans
Aug 25, 2006

There is a heppy lend
Fur, fur aw-a-a-ay.

Hmm, I am at a loss here. The 'use strict' babel inserts should cover this even if I don't manually add anything, all works great in the REPL, tests fail

code:
    operator: deepEqual
    expected: [ 1, 1, 1 ]
    actual:   [ {}, {}, {} ]
:argh: :argh: :argh: absolutely class, just had to if/else through primitives to manually unbox them just to get tests to pass, worra waste of time

RobertKerans fucked around with this message at 17:12 on Sep 10, 2015

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Knifegrab posted:

What kind of monster does this!?

It's useful if you're using objects as generic key:value containers (like a hash map) and only want to access the values that way.

Knifegrab
Jul 30, 2014

Gadzooks! I'm terrified of this little child who is going to stab me with a knife. I must wrest the knife away from his control and therefore gain the upperhand.

pepito sanchez posted:

also worth noting that you have to use double quotes if you work with JSON, because some parsers are dumb.

I just tested this in the browser and in node and Json seems to be able to stringify objects whose properties were not declared in quotes no problem...

piratepilates
Mar 28, 2004

So I will learn to live with it. Because I can live with it. I can live with it.



Json standard says that Json objects need to have keys enclosed in double quotes, JavaScript objects including ones you're stringifying don't have that restriction, only actual Json.

IronDoge
Nov 6, 2008

Knifegrab posted:

I just tested this in the browser and in node and Json seems to be able to stringify objects whose properties were not declared in quotes no problem...

Use this instead:
http://jsonlint.com/

IronDoge fucked around with this message at 18:35 on Sep 10, 2015

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Knifegrab posted:

I just tested this in the browser and in node and Json seems to be able to stringify objects whose properties were not declared in quotes no problem...

Yes, but the generated JSON has quotes on the property names.

Try JSON.parse('{q:"w"}')

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Knifegrab posted:

am I to believe they actually produce different objects?

No, pepito is making no sense. If it's legal to leave unquoted, then doing so produces exactly the same result as quoting the key. The specification requires it.

piratepilates
Mar 28, 2004

So I will learn to live with it. Because I can live with it. I can live with it.



Alright so why do the ES6 collections like Map have a forEach method but not some, map, or reduce? I know we have for of now, and it is trivial to make a stream library (like Java 8) out of iterators, but it seems like a weird step back to have these nice new collections that can only be traversed natively using a for of loop imperatively instead of a nice functional approach like a Java 8 stream.

Edit: we also now have how many, like 5 ways of traversing collections and they're all slightly different for not a great reason.

Adbot
ADBOT LOVES YOU

Knifegrab
Jul 30, 2014

Gadzooks! I'm terrified of this little child who is going to stab me with a knife. I must wrest the knife away from his control and therefore gain the upperhand.

Subjunctive posted:

No, pepito is making no sense. If it's legal to leave unquoted, then doing so produces exactly the same result as quoting the key. The specification requires it.

Alright thanks, I was going crazy for a second there.

And I understand everyone's point about JSON now, its a good thing to know but doesn't really affect me since I almost never handwrite my JSON.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply