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.
 
  • Locked thread
piratepilates
Mar 28, 2004

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



neurotech posted:

I'm seeing a lot of making GBS threads on node, but not much in terms of advice, suggestions or recommendations about alternatives.

If not node, then what should web applications be built on?

Django or Flask are pretty good for Python based web applications, for large large scale web applications then the various big Java frameworks (JEE, Spring, whatever weird enterprise poo poo is here), for smaller scale web applications then Dropwizard for Java, maybe Play on Scala, maybe Clojure has a nice one. One of those is probably good enough.

edit: Oh right and C# with ASP.NET MVC or WebApi or whatever that's all called

piratepilates fucked around with this message at 16:01 on Aug 8, 2015

Adbot
ADBOT LOVES YOU

piratepilates
Mar 28, 2004

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



Is it just me or does Mongoose just kind of suck? Like the last time I used it the TypeScript definitions didn't even fully work, if you attach methods to the schema using schema.method('balls', function(){console.log('fart');}) then you wouldn't be able to access it from an instantiated model, the definition doesn't include the schema types to be on the model.

piratepilates
Mar 28, 2004

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



Stoph posted:

The biggest issue with Node APIs for me was the miserable stack traces but I'm hoping generators or async/await could fix that? It's been a while since I worked on a production Node app...

There was always that package 'longjohn' for pretty printing async stack traces, Chrome does the same thing for the client facing stuff now.

edit: Too lazy to check but I really doubt that async/await or generators are native in io.js right now, so the only way of doing it would be through Babel or maybe TypeScript, and that would then as far as I know involve lots of state machines that probably just lead to even more confusing stack traces, but I could be wrong about all of this.

piratepilates fucked around with this message at 03:42 on Aug 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.



gbaby posted:

all web dev languages suck

the world is just a terrible place

edit: C# is pretty alright aside from that whole Windows thing though

piratepilates
Mar 28, 2004

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



let i hug posted:


This obviously doesn't work if you're making desktop applications/embedded software, but with the web you really get to leverage your control over the whole server ecosystem. I mean, Facebook started out in PHP, and they figured their way out of that mess somehow.

They figured their way out of that mess by contiuing to use PHP, and then when massive performance problems popped up they started teams to come up with different ways of making their existing PHP codebase faster, such as HHVM (new runtime for PHP), and HipHop (a transpiler that just translates PHP to C++), and Hack (a new dialect of PHP that they've just started using instead of rewriting their codebase).

piratepilates
Mar 28, 2004

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



I'm not really sure how much of a help it is to start off with something like Node.js and planning to rewrite it -- unless your long term goal is to be using some messy IBM framework that no one knows how to use then is it really that much more convenient to use Express.js for the first year instead of starting off with Dropwizard or that slim version of Spring?

piratepilates
Mar 28, 2004

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



I'll tell you what though -- TypeScript is quite nice, if you're gonna use JavaScript extensively then you should probably be using it.

piratepilates
Mar 28, 2004

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



I'm Crap posted:

I think people are being unnecessarily negative about node in here. It's great for toy-size apps and prototypes where the problems (potentially unmanageable code, crap debugging, slightly "ehh" performance) aren't going to bite you.


I'm not sure there's a much (reasonably) lower bar than that for a piece of technology. At that point what is it even doing in these toy-size apps and prototypes that any other language isn't doing for you?

piratepilates
Mar 28, 2004

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



Tao Jones posted:

With Node, I often feel like I have no earthly idea in advance what a function is going to be returning. Is it going to be a promise? Is it going to be an object that isn't a promise? A string? Undefined because something got hosed up?

Similarly, I find I'm often in situations where if I try to deviate slightly from a provided example -- ie, in the tutorial everything is just mashed into one large function but in my code I want to break each piece into smaller functions -- I particularly hit this snag where async fucks things up or there's some weird promise interaction or something.

Is there any kind of cheat sheet or quick and dirty guide to where some common minefields are, or is this just the kind of stuff I just have to bang my head against?

For the function returning types in advance thing, check the API docs. If the API docs don't give you a good sense of it then post an angry message on their Github and choose a better library, if there isn't a better library then you're screwed.

Not sure exactly what you mean by the second thing though.

edit: It may help to dig in to the internals of what the API is doing if you don't understand it. Set a breakpoint and step through it a bit and see what's in each object, maybe that'll help you figure out what they return.

edit: Oh how could I forget, just start using TypeScript. TS has definitions for types in the major NPM libraries so you'll have a much easier time figuring out what things are expecting.

piratepilates fucked around with this message at 03:34 on Aug 27, 2015

Adbot
ADBOT LOVES YOU

piratepilates
Mar 28, 2004

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



Tao Jones posted:

Oh, Typescript looks cool, I'll check that out more. Is it possible to have typescript and vanilla JS in the same Node app?
Yes, there's no actual runtime for TypeScript, it just transpiles to JavaScript and the final JS is run. You can just have any JavaScript files renamed .ts since TypeScript is (almost) a superset of JS -- may get a ton of compiler warnings (will still compile most likely) for a while though.

quote:


The second thing is that, and maybe this was more when I was first learning node, I didn't always understand async and promises (and neither did anyone else on my team) so we tended to make these monstrous endpoints where the validations and all of the data massaging before calling an external API and then all of the data munging and doing what the function's real work was were all in one function in one file. Later on, when we got to the point where we had 400-line callback hell functions, we started trying to abstract out the parts that could be separated into other functions and then just call them. In Rails this was relatively[*] safe[**] to do,
I have no idea what you people were doing but it sounds like a bad idea throughout.

quote:


but in node we found that it was a good way to introduce more async-related bugs or accidentally start mixing up "callback style" and "promise style".
Stick with one or the other -- use promises for anything that runs once, a listener callback for anything that runs more than once.

quote:

So I guess what I'm asking for is whether or not there are a collection of Good Opinions about how to write node.js out there that can help keep teams from accidentally doing something in a weird way because they found some 2 year old article from Stack Overflow saying to do it in this one esoteric way.

Keep functions small, use promises, use Flow or TypeScript, alternatively use Babel and all the language goodies in there to help your code look better, embrace functional programming -- try to make as much as possible about inputs -> outputs with as little state as possible -- embrace closures and functions that return functions for anything that will help you do this, look at how Facebook does it (Relay, React, Immutable.js, Flux, Flow) and try to mimic them.

And of course JavaScript is a very loose dynamically typed language, but that doesn't mean you can or should treat everything in a loose dynamic style. Embrace constructors to make objects as much as possible, use ES6 symbols and fake enums as much as possible for identifiers that are shared instead of using strings or magic numbers. If you're making a class then put every field that will be used in the constructor, even if you're just setting it to null (helps with performance too, since changing the underlying structure of an object tends to be expensive). Look at what a good statically typed language like C# or Rust does to ensure that you don't do something stupid, and then embrace that. Don't try to do things magically -- don't have a function that can take a string, or it can take an object, or it can take an array of objects, or whatever, if it's not a reasonable thing for the function to take care of (like maybe a single string being passed in gets turned in to an array of strings, while otherwise it will expect an array of strings) then throw an Error -- don't try to adapt the arguments to what you want it to be.

  • Locked thread