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
Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.
Yeah, well thats the kicker, a lot of the push back I see, including my own, is against it eating the back end, and its because while JavaScript is not the worst thing in the world, there are far better, far safer alternatives out there for back end systems.

This is most keenly felt in the way Nodejs can just swallow errors or crash despite the logging in place, or the lack of good standardisation for performing asynchronous work (of which there is a lot). This is just two factors that make working with libraries a bit of a crapshoot, and then the volatile quality of npm libraries doesn't help.

The question is does npm/nodejs need to eat the backend? There are plenty of good alternatives out there that are easier to debug, have better constructs for asynchronous work, and a higher standard of libraries in use.

Adbot
ADBOT LOVES YOU

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.

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.

German Joey posted:

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.

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.

piratepilates
Mar 28, 2004

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



Am I remembering this wrong or is Subjunctive the person who first implemented Array.prototype.map in a browser?

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?

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.
From my experience coffee script can extend classes from es6 libraries can extend classes from Typescript libraries. I agree that classical patterns are a clusterfuck but ES6 has been paving the way for standardisation there.

I think the big issue is that JavaScript is an incredibly useful compilation target, but writing it as raw ES5 compatible JavaScript is very limiting for all the constructs you'd like to use. It's malleability is its greatest strength as a compile to target, but its not good for establishing an ecosystem with well defined APIs and solid error handling.

Most of the JavaScript pain comes from working with external code not following your toolkit & conventions. This is where npm becomes a crapshoot, because there's so much more to libraries than what it does, because working with them can be a very variable experience based on the choices you've made with your own codebase.

A big culprit here is browserify et al, sure you can pack libraries but what about efficient minification and packing rules, its not reliable enough to just stuff everything into a single container yet due to the tooling inconsistencies out there.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

German Joey posted:

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.

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.

Subjunctive fucked around with this message at 00:42 on Sep 24, 2015

Skandranon
Sep 6, 2008
fucking stupid, dont listen to me

Maluco Marinero posted:

A big culprit here is browserify et al, sure you can pack libraries but what about efficient minification and packing rules, its not reliable enough to just stuff everything into a single container yet due to the tooling inconsistencies out there.

To be fair, Browserify was never meant for packaging assets for web, but for packaging Node libraries for use in the browser.

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.

Skandranon posted:

To be fair, Browserify was never meant for packaging assets for web, but for packaging Node libraries for use in the browser.

Yeah, and webpack still inherits the same problem, if you don't pack it right all you get is a bloated node library that wasn't minified correctly. I guess the problem is we can't actually trust our tools yet, they have major deficiencies if used on face value (chokidar actually watches properly yet gulp.watch is how most people do watching in gulp) so everyone who uses a tool in production has to view its documented best practices with a lot of scepticism.

Too many people in a rush to make a pretty homepage for their little library before hardening up the API.

Skandranon
Sep 6, 2008
fucking stupid, dont listen to me

German Joey posted:

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?

The reason for this is because the Browser Wars are still going, and they are somewhat against working with each other. There have been MANY proposals for new languages that would be better than JavaScript, but since all the browsers won't agree on anything other than the ES standard, we are stuck. ES6 fixes a lot of things, but since it's still the ES standard, it can't take things OUT of JavaScript, which is what is really needed. Things like TypeScript allow for much more rapid improvement of the language, and produce cross browser compatible code.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

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.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Skandranon posted:

ES6 fixes a lot of things, but since it's still the ES standard, it can't take things OUT of JavaScript, which is what is really needed. Things like TypeScript allow for much more rapid improvement of the language, and produce cross browser compatible code.

What do you think needs to be taken out of the language (versus just not used very often, like eval)? We've taken things out of JS and ES before, though it's difficult.

(What does Tyoescript remove from the language? Isn't it a superset?)

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.

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.
Last time I used Typescript it was purely superset with extra features following ES6's lead. I'm considering going back because the type system has more options now (so you don't have to drill through with any types as often), I certainly think just a little bit of type checking would go a long way to help alleviate my main issues with writing large scale JavaScript, but there's only so far that will go unless we have universal use of Typescript.

Skandranon
Sep 6, 2008
fucking stupid, dont listen to me

Subjunctive posted:

What do you think needs to be taken out of the language (versus just not used very often, like eval)? We've taken things out of JS and ES before, though it's difficult.

(What does Tyoescript remove from the language? Isn't it a superset?)

TypeScript IS a superset, so doesn't ACTUALLY remove things, but you can turn things on like "no implicit any" during compilation which forces you to be more explicit in your types.

I don't have anything that comes to mind that NEEDS to be removed, as opposed to just not using it. I do think a lot of JS problems come from that it has things which easily confuse newcomers and gets you in trouble. When you understand it better, you know what to stay away from, but if you never spend enough time with it, you come away with a bad taste (or a grudge, like German Joey).

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

German Joey posted:

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.

The goalposts have moved here. You started out complaining about the language, and now you're complaining that people don't use the language. Not everyone uses the language fully because not every has learned to, and old ways still work. But I work with professionals who employ classes all over the place, and use the MOP when they need it (it's not an everyday tool).

Many people still write C++ using explicit functors instead of lambdas, but that doesn't mean the language lacks the facility.

(As I've said several times already, there is more than just function scope.)

Skandranon posted:

I don't have anything that comes to mind that NEEDS to be removed, as opposed to just not using it.

Then what did you mean when you said "what it really needs"?

I sort of feel like I'm being gaslighted here.

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.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
"JavaScript is hosed, here's what needs to be fixed..."

"Uh, all this stuff is fixed in ES6..."

"I'm not talking about future JavaScript"

Skandranon
Sep 6, 2008
fucking stupid, dont listen to me

German Joey posted:

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.

You could solve all this with TypeScript, now, today. It will automate the _this=this pattern inside arrow syntax functions. And tomorrow when you compile to ES6, it will use the native ES6 implementation of arrow syntax.

Subjunctive posted:

Then what did you mean when you said "what it really needs"?

I sort of feel like I'm being gaslighted here.

Not trying to gaslight you at all. I just think that, if JavaScript could be done over again today, knowing what we know now, it would be better. But it's certainly usable now, and ES6 will be even better.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

With Babel and such you can write ES6 today and target any browser. Some of the biggest sites in the world do so.

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?

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.
It's to write the shared stuff in the same code. You can compile es6 to backend and front end just fine.

Define the shared stuff and the conversation is more useful. Personally I find it is template rendering that generates the largest intersection between front and back end. Business logic can result intersection but in my experience there's actually a fair bit of asymmetry in how a client and server needs to treat the same pieces of data.

Impotence
Nov 8, 2010
Lipstick Apathy

German Joey posted:

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?

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

You can use a compiler on the front and back ends, as you use a compiler for many languages. As more targets improve their support for ES-latest, more of the transforms become identity.

I'm not particularly advocating for backend use, though I think JS has some merits there.

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

It's important to remembert that the problems with javascript are primarily human problems. Like, you can do anything you want in client side javascript. The problem is that since literally any rear end in a top hat can write javascript, all third party libraries and all tools are poo poo. The node.js people are eventually going to win - like, Typescript and other compile-to-js stuff is a win, and eventually, someone is going to make non-retarded versions of Node.JS and angular - hell, even Microsoft has gotten tired of loving dealing with IIS and is starting to embrace Node. But until actual non-retards start getting interested in front end development, we're going to have to deal with stuff like gulp and bower and grunt and require.js.

my effigy burns
Aug 23, 2015

IF I'M NOT SHITPOSTING ABOUT HOW I, A JUNIOR DEVELOPER IN JAVASCRIPT KNOW EVERYTHING THERE IS TO KNOW, PLEASE CHECK TO BE SURE MY ACCOUNT WAS NOT COMPROMISED BY A CLIENT-SIDE BOTNET, TIA

Bruegels Fuckbooks posted:

It's important to remembert that the problems with javascript are primarily human problems. Like, you can do anything you want in client side javascript. The problem is that since literally any rear end in a top hat can write javascript, all third party libraries and all tools are poo poo. The node.js people are eventually going to win - like, Typescript and other compile-to-js stuff is a win, and eventually, someone is going to make non-retarded versions of Node.JS and angular - hell, even Microsoft has gotten tired of loving dealing with IIS and is starting to embrace Node. But until actual non-retards start getting interested in front end development, we're going to have to deal with stuff like gulp and bower and grunt and require.js.

Node is simultaneously the best and the worst: you get async and speed and power, but sometimes it's like being blind and owning a race car whose parts are scattered throughout the world's largest dump. Still, NPM + travis + download stats + documentation + pull requests/issues can give you a pretty good idea of what you're getting into, so I've never really seen the 'widely varying quality' argument as a serious problem. It's definitely annoying, (sometimes very annoying) but it's not like we're purchasing closed-source software with no forewarning and no way out.

Of course, in the long run I kinda I think we'd be better off if javascript had a king who could make decrees at will. There would be a lot of stupid decisions to rage against, but at least there would be a clear universal standard and a clear rebel faction.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

my effigy burns posted:

Of course, in the long run I kinda I think we'd be better off if javascript had a king who could make decrees at will. There would be a lot of stupid decisions to rage against, but at least there would be a clear universal standard and a clear rebel faction.

The Internet Explorer 6 monoculture was actually pretty poo poo, objectively speaking.

Vulture Culture
Jul 14, 2003

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

my effigy burns posted:

Of course, in the long run I kinda I think we'd be better off if javascript had a king who could make decrees at will.
Also if that guy was Reg Braithwaite

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

German Joey posted:

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

Ah, yes, much like C++, Java, and C#, which have no defined block for namespace wrapping.

Skandranon
Sep 6, 2008
fucking stupid, dont listen to me

Suspicious Dish posted:

Ah, yes, much like C++, Java, and C#, which have no defined block for namespace wrapping.

It's only 3 tabs for C#(namespace, class, function), which means the world to some people it seems.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Just use modules. (C++ will get them soon too.)

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Subjunctive posted:

Just use modules. (C++ will get them soon too.)

Wait, the C++ committee accepted modules? I thought they were thrown out.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Suspicious Dish posted:

Wait, the C++ committee accepted modules? I thought they were thrown out.

Last I heard (spring) they were in good shape, though not clear if 17 or a TS. It would be big news of they got dropped.

("Voted out" in the committee's language means approved, oddly.)

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

Subjunctive posted:

("Voted out" in the committee's language means approved, oddly.)

This is not a particularly good sign coming from a body responsible for the design of a programming language.

Skandranon
Sep 6, 2008
fucking stupid, dont listen to me
That's what you get when you allow operator overloading.

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.
So I come from php where cron jobs exist. If I wanted to do something similar to a cron job in node, what would be the best way to go about that? I basically have a function I want run every five minutes that checks that a time limit isn't being approached.

Skandranon
Sep 6, 2008
fucking stupid, dont listen to me

Knifegrab posted:

So I come from php where cron jobs exist. If I wanted to do something similar to a cron job in node, what would be the best way to go about that? I basically have a function I want run every five minutes that checks that a time limit isn't being approached.

Well, you have two main ways. One would to similarly run a cron job every x minutes to start, run, stop the node script.

You could also have a long running process that uses timeouts to run every x minutes to do your check, then take some action.

Doesn't really matter much, unless your application startup time is significant and you don't want to repeat it every time you perform your check.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

The long-running case also requires tighter error handling too, so that a fatal error doesn't kill it forever. You also have to worry more about resource consumption. Processes are pretty nice. :3:

Adbot
ADBOT LOVES YOU

kedo
Nov 27, 2007

Random number generation question for you folks. Earlier I was playing around with a cellular automata-like function that generates pixel shapes and I noticed that it tends to generate shapes that slope up and to the right more often than not. For example:



This only shows 9 generations, but they always tend to look a bit like this. The red pixel is the origin point, light blue pixels are ones that generated at random afterwards. There are the occasional shapes that go off to the bottom/top left, but they're rare and they don't tend to go extend further than a couple of pixels.

Below is the (slightly abstracted) code I'm using, with grid.trigger() being the important bit. In English, when triggered, the origin pixel has a 100% chance of animating. All of its surrounding pixels are then triggered, but they only have a 30% chance of animating.

I'm guessing the random number generation is my problem? Or maybe the fact that I grab surrounding pixels clockwise from the origin? Any thoughts?

JavaScript code:
      // User input calls
      $('.pixel-grid').on('mouseenter', '.pixel', function() {
        grid.trigger($(this),100); // Trigger grid with a 100% chance to execute.
      });


var grid = (function() {

    var settings = {
      rows: 40,
      columns: 40,
      spreadChance: 30 // Percent chance that a mouse event will spread
    };
    
    var animatePixel = function($pixel,origin) {
      if (origin === true) {
        $pixel.addClass('origin');  
      }
      $pixel.addClass('animating');
      setTimeout(function() {
        $pixel.removeClass('animating origin')
      }, 1000);
    };

    var trigger = function($pixel,chance) {
      // Determine if the function will progress w/ random number.
      var spreadRand = Math.random() * 100;
      
      // if (chance == 100) {
      //   console.log('______________');
      // }
      // console.log('r' + $pixel.attr('data-row') + ', c' + $pixel.attr('data-column'));
      // console.log(spreadRand);
      // console.log(spreadRand <= chance);

      if (spreadRand <= chance) {
        // Run the animation
        if (chance === 100) {
          animatePixel($pixel,true);  
        }
        else {
          animatePixel($pixel,false);
        }
        
        // Run the animation on neighbor pixels
        var currentPixel = {
          row: $pixel.attr('data-row'),
          column: $pixel.attr('data-column'),
        }
        // Get surrounding pixels
        var surroundingPixels = [
          { // Above
            row: parseInt(currentPixel.row) - 1,
            column: parseInt(currentPixel.column)
          },
          { // Top right
            row: parseInt(currentPixel.row) - 1,
            column: parseInt(currentPixel.column) + 1
          },
          { // Right
            row: parseInt(currentPixel.row),
            column: parseInt(currentPixel.column) + 1
          },
          { // Bottom right
            row: parseInt(currentPixel.row) + 1,
            column: parseInt(currentPixel.column) + 1
          },
          { // Bottom
            row: parseInt(currentPixel.row) + 1,
            column: parseInt(currentPixel.column)
          },
          { // Bottom left
            row: parseInt(currentPixel.row) + 1,
            column: parseInt(currentPixel.column) - 1
          },
          { // Left
            row: parseInt(currentPixel.row),
            column: parseInt(currentPixel.column) - 1
          },
          { // Top left
            row: parseInt(currentPixel.row) - 1,
            column: parseInt(currentPixel.column) - 1
          }
        ];
        for (i=0;i<surroundingPixels.length;i++) {
          var $target = $('.pixel[data-row="' + surroundingPixels[i].row + '"][data-column="' + surroundingPixels[i].column + '"]');
          trigger($target,settings.spreadChance);
        }
      }
    };

    return {
      trigger: trigger
    }
  })();
Also, I've tried to implement a couple of better random number generators such as Alea with similar results... now I'm wondering if I just have some stupid typo.

kedo fucked around with this message at 22:47 on Sep 30, 2015

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