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
German Joey
Dec 18, 2004
Quick question for y'all. its been about a year since I looked into this. is Sails.js / Waterline still the best way to interact with an SQL database in the node.js world? Or is there anything new I should know about?

Adbot
ADBOT LOVES YOU

German Joey
Dec 18, 2004

piratepilates posted:

Well I just read this article about Sails.js, helpfully titled "Don’t Use Sails (or Waterline)"

Maybe try Sequelize.

There's something very funny about datastore libraries in Javascript not having stuff like transactions or batch insertions that seem kind of important to have.

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!

German Joey fucked around with this message at 11:24 on Sep 8, 2015

German Joey
Dec 18, 2004

Wheany posted:



You are absolutely right.

And after working a few years with Javascript god drat did it feel good to code Java again. Like, everything doesn't have to be poo poo? What is this?

Last night I started reading some Flask documentation/tutorials, and I was like, "Wow, goddamn, this is really great." But then I went to look at Django again, (I'd used it heavily 3-4 years ago), specifically a websockets library called Swampdragon, and it was really well documented too! Full API documentation, multiple full walkthroughs/examples for setting up a new app (and they actually worked). Amazing! And then I read some article comparing Flask/Django/Pyramid and one minor negative it brought up against both Flask and Django was that their documentation was "ok, but not the best."

...

I had forgotten that this is what the rest of the dev world actually expects as a bare minimum. :gonk:

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

German Joey
Dec 18, 2004
Speaking of lovely network performance, is there any easy way to test websocket poo poo on the client side when my websocket server is still running on the localhost? I want to make sure that all my socket handlers still gracefully reconnect and resync when the websocket connection is temporarily lost without actually killing the websocket server. Is there something like a pass-through proxy I can set up to do this?

German Joey
Dec 18, 2004

Biowarfare posted:

https://jagt.github.io/clumsy/ maybe?

also you have no idea how confusing it is to randomly encounter maplestory avatars in cobol

...scared?

German Joey
Dec 18, 2004

Noam Chomsky posted:

Just use the right tool for the right job and don't be a moron.

Right, hence, don't use javascript if you can help it.

German Joey
Dec 18, 2004

MALE SHOEGAZE posted:

Javascript has first class functions and is therefore better than more fun than many alternatives.

more like its one saving grace. but better than what? C++? PHP? we're dredging pretty bottom of the barrel here! if only it had a real scope implementation and an object model that didn't both require extreme abuse of these aforementioned first class functions, then it might actually be enjoyable to code in this horrible loving language! but probably not! THE WEB! GOTTA LOVE IT!!!!!!!!!!

German Joey
Dec 18, 2004

Subjunctive posted:

You want something other than lexical scope? Dynamic scope would be much worse, I think, so I'm curious as to what you have in mind.

Which object model facilities do you find yourself wanting? Classes provide more traditional syntax, and proxies+reflect give a pretty rich meta-object protocol (though you have to implement defadvice or similar yourself if you want it).

You know that only functions can create a new scope in javascript, right? That's why we have to wrap everything in this "(function() { ... code ... })();" bullshit.

German Joey
Dec 18, 2004

Maluco Marinero posted:

You know he's written a considerable amount of JavaScript implementations? Is it too much to ask that people argue from an assumption of good faith and domain experience, given were all in the JS thread. This isn't yospos.

I did not know that and in fact I find it surprising. How can he write javascript implementations and not know what's hosed up about javascript scope or its object model? If someone says something like that I have to assume it's either out of ignorance or not an argument in good faith. Javascript is just way way way too hosed up not to recognize it at all.

Here's an interesting example. I took a look at the most popular javascript projects of today page on github, and then looked at how they built their classes. Like, this is a pretty basic thing for a language, right? If I were to go look at a random python, or java, or whatever library, I might not know how the gently caress its structured or how it works exactly, but when I go take a look at the class definitions I will see a "class Name" on one line, then maybe some members, and then a bunch of methods. There's gonna some imports at the top of the file, maybe some singletons or whatever, but they're all gonna look pretty much like that. With something like Perl, which is much looser, we'd see a bunch using Moo and a bunch using old-school perloo style. But, one or the other. C++? Probably something like this. Ugly, but standardish. What about javascript? gently caress NO. Let's take a look at our random sample; the point isn't which of these projects are good or bad, or which of their object models are good or bad, but that they're all completely loving different and custom-rolled object models.

And, for the record, I ignored stuff that looked like it was a core engine component (as that type of thing would be mucking with internals more) or stuff that looked like it wasn't a mainly javascript project, or stuff that had a function-based interface. Just tried to find what looked like a regular component of a project implementing some its functionality.

https://github.com/trending?l=javascript

  • https://github.com/guisouza/dss
    code:
    (function(dss){
    'use strict';
    
    	dss.core.flatRules = function(){
    		var flattedRules = {};
    		...
    		return flattedRules;
    	};
    
    })(this.dss);
    
  • https://github.com/meteor/meteor
    code:
    Meteor.absoluteUrl = function (path, options) {
      if (!options && typeof path === 'object') {
        options = path;
        path = undefined;
      }
      options = _.extend({}, Meteor.absoluteUrl.defaultOptions, options || {});
    
      var url = options.rootUrl;
      if (!url)
        throw new Error("Must pass options.rootUrl or set ROOT_URL in the server environment");
    
      ...
    
      return url;
    };
    
    // allow later packages to override default options
    Meteor.absoluteUrl.defaultOptions = { };
    if (typeof __meteor_runtime_config__ === "object" &&
        __meteor_runtime_config__.ROOT_URL)
      Meteor.absoluteUrl.defaultOptions.rootUrl = __meteor_runtime_config__.ROOT_URL;
    
  • https://github.com/mateogianolio/sshync/blob/master/ssh.js
    code:
    (function() {
      'use strict';
    
      var util = require('util'),
          ee = require('events').EventEmitter,
          fs = require('fs'),
          cp = require('child_process'),
          spawn = cp.spawn,
          exec = cp.exec;
    
      module.exports = function(username, host, connectcb) {
        return new SSHClient(username, host, connectcb);
      };
    
      function SSHClient(username, host, connectcb){
        var self = this,
            outBuff = "",
            out;
    
        this.username = username;
        this.host = host;
    
        ...
    
        this.ssh.stderr.on('data', function (data) {
          self.lastError = data.toString();
          ...
        });
      }
    
      util.inherits(SSHClient, ee);
    
      SSHClient.prototype.exec = function(cmd, cb) {
        ...
      };
    
  • https://github.com/typicode/json-server
    code:
    module.exports = {
      getRemovable: getRemovable,
      createId: createId,
      deepQuery: deepQuery
    }
    
    
    function getRemovable (db) {
      var _ = this
      var removable = []
      _.each(db, function (coll, collName) {
          ...
    
  • https://github.com/facebook/react
    code:
    var EventPluginHub = {
    
      injection: {
        injectMount: EventPluginUtils.injection.injectMount,
        ...
        },
    
        getInstanceHandle: function() {
          if (__DEV__) {
            validateInstanceHandle();
          }
          return InstanceHandle;
        },
      },
    
      ...
      putListener: function(id, registrationName, listener) {
    };
    
    module.exports = EventPluginHub;
    
  • https://github.com/angular/angular.js
    code:
    angular.module('ngMessages', [])
       .directive('ngMessages', ['$animate', function($animate) {
         var ACTIVE_CLASS = 'ng-active';
    
         ...
    
         return {
           require: 'ngMessages'
    
    
           controller: ['$element', '$scope', '$attrs', function($element, $scope, $attrs) {
             this.getAttachId = function getAttachId() { return nextAttachId++; };
    
             var messages = this.messages = {};
             var renderLater, cachedCollection;
    
             this.render = function(collection) {
    
    ...
    

Again: they're all different.. And what's really hilarious is that none of these use the "standard' javascript object models, of either a.) basic prototype inheritance, b.) the yahoo module pattern, c.) the jquery boilerplate pattern. (e.g. something like this) or d.) boilerplate OO from javascript boilerplate. And this isn't even counting poo poo like Typescript or Coffeescript, which have their own internal javascript module/class/object patterns. By the way, why are javascript-preprocessors even a thing if the language is ok? Other than C++, what other language even has language preprocessors in widespread use whose purpose it is to fix the language?

German Joey
Dec 18, 2004

Subjunctive posted:

You know about let, and catch blocks?

E: C++'s object model is so great that people had to invent COM. Different C++ object models abound.

I asked what your specific complaints were, to discuss them. Modern JS provides lexical scope, class sugar, and a robust meta-object protocol. What else do you want, specifically? "Many people make different choices about how to structure their programs" isn't a language critique, and if it were you could level it against anything from Lisp to C++ to good old C.

This is the language though. Saying "Modern JS provides lexical scope, class sugar, and a robust meta-object protocol" doesn't mean poo poo if a.) lexical scope only happens with functions, b.) nobody actually uses the class sugar or the "robust" meta-object protocol. What people actually do in the language matters more than what they theoretically could do. If seasoned professionals are using all of this other bullshit instead of javascript's built in "robust" object model than that means javascript's built in """"robust""" object model is even more bullshit.

What I want (LOL) is to write AND READ code that's not indented by 4 sets of tabs to start with and/or wrapped in weird custom object engines.... like I can do in pretty much every other language.

And yeah I ain't shouldn't even try to defend C++, that's the one language I consider worse than Javascript. Forget that part.

German Joey
Dec 18, 2004

Subjunctive posted:

Perhaps let me try this again:

In the 20 years since I started working with JS, and especially in the rough decade in which I was involved in implementations and standards activities, I've had many discussions about the shortcomings of JS. I've raised concerns about the language that have led to changes in it, in fact.

The productive versions of those conversations are based on concrete exploration of things that people want to do with the language, why they can't do them now (or why the pain of doing them now is too great), what alternatives there are, and how they would affect the language as a whole. Simply saying "scoping and the object model are hosed, yo" isn't concrete enough to have a useful conversation or understand alternatives, so I described the core attributes of those things as I saw them, and asked for specifics about what you objected to.

Lisp and JS both have function-or-let scope introduction, but I don't often hear complaints that Lisp's scoping is absurd. What are you trying to use scope for, and how is it failing you?

Similarly, what do you want from the JS object model that it isn't providing?

The more specific you are, the more productive our discussion is likely to be.

Dude, I have also been working javascript for 20 years and I just showed you explicitly what is wrong with it. I'm not talking about "let" or any other ES6 poo poo, because I can't write code in ES6 yet. We're talking about current Javascript, not future Javascript that I won't be able to use until 2020. Maybe then, I will be happy, I don't know.

But, I loving posted code samples from some of the most popular of today and showed you that general examples of professional-quality javascript code is both a labyrinthine mess and highly dissimilar, and thus errors I get during the usual course of development while using this code are also a.) labyrinthine messes and b.) highly dissimilar. And, you know, I'm just talking about errors in my own code, trying to figure out why some when I call some method, an anonymous function 10-nested calls deep in the library is thinking something is undefined, and not problems in the library itself, although anecdoteally I feel like I find errors in javascript libraries far more often than I do in comparable python ones. Diving into the guts of these libraries over and over to figure out the solution is an insanely frustrating experience because a.) they're all labyrinthine messes and b.) highly dissimilar. It wastes so much loving time!

Regarding scope. Tell me. What happens here:

code:
var createCallBack = function() { //First function
    return new function() { //Second function
        this.message = "Hello World";

        return function() { //Third function
            alert(this.message);
        }
    }
}

window.onload = createCallBack(); //Invoke the function assigned to createCallBack
"this" is bound to global scope, so when you have callbacks inside of callbacks inside of callbacks.... now imagine you're doing jquery plugin poo poo, which involves writing this kind of structure out the wazoo.

If I seem particularly pissed about this, its because its been my every-day experience lately. I've been dealing with it for the last couple of weeks now, shifting back to the frontend after spending a blissful week rewriting a node.js application in django.

German Joey
Dec 18, 2004

Subjunctive posted:

The goalposts have moved here.

YOU are the one moving the goalposts by talking about ES6, not Javascript as its, I don't know, "currently lived" or whatever. Current practices.

German Joey
Dec 18, 2004
Great, another preprocessor! Of course, if I need to use a compiler on the backend, what's the point of writing the backend in javascript again? Isn't the idea of "javascript on backend and frontend" to have your entire application be in the same language?

German Joey
Dec 18, 2004

Noam Chomsky posted:

Is MongoDB pretty much a bad choice for ~99% of applications?

yes.

German Joey
Dec 18, 2004
Speaking of, and I'm kinda laughing at myself for even thinking about this, but is there any way to sandbox Javascript in the browser? Like, lets say I have some widget that has a bunch of methods attached to it, and I want to allow user-written scripts that can interact with this widget. As in, User A writes a script on the site, and User B loads the script and runs it.... WITHOUT needing to worry about his computer blowing up or known terrorists now knowing his credit card number and his mother's maiden name. Just from the top of my head, I'd want to ban DOM manipulations except via the widget's method calls, or modifying the widget itself, or the use the eval function, or access to cookies, or to load any external objects, or who knows what else. Is this possible natively?

German Joey
Dec 18, 2004

Subjunctive posted:

Sandboxing is what caja does, it works well.

oh, this looks perfect! Looks like it works how I envision something like this should work...

edit: except for all of their demos being broken...

German Joey
Dec 18, 2004

Skandranon posted:

You could maybe try something like a WebWorker. It will run a separate .js file in a separate thread, and has no access to the DOM or a lot of other things, but can communicate with the main thread (and thus, the DOM) via postMessage.

that's not a bad idea. I googled a bit along these lines and found this:

https://github.com/asvd/jailed

Which seems like I could do something with. I think what I'd want to do is instantiate the user code inside a wrapper, which would provide with an API that shadowed that of my widget. However, rather than operating on the widget directly, the user would actually be invoking the wrapper, which would use postMessage to communicate a command to the wrapper around the widget. Likewise, any events generated by the widget would themselves invoke postMessage to communicate a command to the worker, which would then invoke a cooresponding worker event.

This seems a lot simpler than using caja, and I bet it would be a lot faster too... I'm already worried about my app being very resource-intensive on the server side, even without needing to worry about processing crap for every little UI interaction.

edit: Oh I see now, this is exactly what jailed does already! I just need to provide a wrapper to jailed's application.remote object to hide that interface from the user.

German Joey fucked around with this message at 23:25 on Nov 5, 2015

German Joey
Dec 18, 2004
What the hell are you doing that needs multiple GB of RAM, and why are you doing it in javascript?

German Joey
Dec 18, 2004

peepsalot posted:

CSG CAD stuff, for fun

http://openjscad.org

e: it doesn't normally need GBs of ram but i wanted to render a specific very high detail script

fairly cool!

edit: sites like this always make me feel warm and glowing about how amazing the potential of the web is, but then when I start developing in Javascript again it doesn't take long for me to degenerate back into a frothing, furious mess. :xd:

German Joey fucked around with this message at 21:33 on Nov 15, 2015

Adbot
ADBOT LOVES YOU

German Joey
Dec 18, 2004
Can anyone help me with Javascript build tools? I've developed a plugin for another library (leaflet.js) that I'd like to release on github, but the source code ended up being a lot longer than I originally predicted (~1200 lines now) so I'd like to split it up into multiple files. I don't need 'require' or anything of the sort, and my code is all plain, vanilla Javascript. I basically just want some standard build tool that will take my files and concat them together, and then minify the resulting file. What's the easiest way to do this with bower, or jake, or webpack, or rollup, or whatever the heck is the latest fashion these days?

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