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
DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
JavaScript is a really crazy language

Adbot
ADBOT LOVES YOU

Shaggar
Apr 26, 2006

St Evan Echoes posted:

agreed, safari + obj-cscript forever

slowfari is bad and obj-c is even worse

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
I'm sure an internet of ActiveX plugins would be far superior, right?

jesus WEP
Oct 17, 2004


Shaggar posted:

slowfari is bad and obj-c is even worse
actually,

Shaggar
Apr 26, 2006

Jabor posted:

I'm sure an internet of ActiveX plugins would be far superior, right?

to javascript? absolutely.

Shaggar
Apr 26, 2006
even vbscript would be better than javascript

Jerry Bindle
May 16, 2003
i have been implementing r6rs scheme for fun in my spare time, those guys and gals put so much thought into that language. everything works, there are no surprises, its all explained in clear mathematics. its beautiful.

javascript otoh doesn't even get lexical scoping right. :(

Zaxxon
Feb 14, 2004

Wir Tanzen Mekanik

pepito sanchez posted:

app is app :) everything in javascript is named app for some stupid loving reason

Flat Daddy
Dec 3, 2014

by Nyc_Tattoo

pepito sanchez posted:

app is app :) everything eventually falls as part of the main angular module. it's global, or let's say "public" instead right now, but the point is avoiding global namespace pollution. because code gets wrapped inside IIFEs nothing is public or exposed unless i expose it. it's how you declare and use private variables and members in javascript. i have no gripe with IIFEs. the point is in angular, like i mentioned before, is that once you start doing something past declaring the main module, like having dependencies, it starts becoming unreadable.

code:
    var app;
    (function (app) {
        var common;
        (function (common) {
            var ButtService= (function () {
                function ButtService($resource) {
                    this.$resource = $resource;
                }
                ButtService.prototype.getButtResource = function () {
                    return this.$resource("/api/butts/:buttId");
                };
                ButtService.$inject = ["$resource"];
                return ButtService;
            })();
            common.ButtService= ButtService;
            angular.module("common.services")
                .service("buttService", ButtService);
        })(common = app.common || (app.common = {}));
    })(app || (app = {}));
yeah maybe i'm not the best at explaining this.

???

yeah that looks bad but i dont see why you even need app and common.

just do it like in this guide https://github.com/johnpapa/angular-styleguide

no need to expose global variables. 'angular' is the only global; you just call 'angular.module' to get/set modules

Flat Daddy fucked around with this message at 17:03 on Aug 27, 2015

Flat Daddy
Dec 3, 2014

by Nyc_Tattoo
you do have to use IIFEs usually, but its only 1 per file.

pepito sanchez
Apr 3, 2004
I'm not mexican
that is actually how i wrote things in angular, when I just did JS by hand. I'll be very honest in saying apart from having IIFEs easily created for me I don't actually know what if any advantage I get from this code.

it's typescript's direct ES5 transpilation of:

code:
module app.common {
	interface IButtService{
		getButtResource() : ng.resource.IResourceClass<IButtResource>;
	}
	
	interface IButtResource
		extends ng.resource.IResource<app.domain.IButt>{
	}
	
	export class ButtService
		implements IButtService {
			static $inject = ["$resource"];
			constructor(private $resource : ng.resource.IButtService){
				
			}
		getButtResource() : ng.resource.IResourceClass<IButtResource>{
			return this.$resource("/api/butts/:buttId");
		}
	}
	angular.module("common.services")
		   .service("buttService", ButtService);
}
just for shits and giggles i just had it transpile over to ES6, and it looks nearly identical. if i'm doing something wrong then it's me packing everything inside separate typescript modules. it creates the vars on its own.

code:
module app {
	angular.module('buttapp', []);
}

will create a var app, and insert it into the IIFE as shown before. if anyone has some insight on this apart from "JS BAD" it would be cool.

Flat Daddy
Dec 3, 2014

by Nyc_Tattoo
it's probably what you'd come up with yourself if you had to hack a module system on top of es5.

it has to create a var because "module app {}" is creating a global value and theres no other way to do it.
it makes an IIFE for each module so the module innards don't leak into global scope.
it passes "app" to the IIFE in case the compiler needs to change it to (function(app_1) {...})() in the case where it needs to avoid a name conflict with something in the implementation.
the (app || {}) part is so you can add stuff to the same module in multiple files



i was just worried you were writing that by hand.. combining angular's module system with another module system is always gonna look like trash unforunately

Flat Daddy fucked around with this message at 17:53 on Aug 27, 2015

Valeyard
Mar 30, 2012


Grimey Drawer

Flat Daddy posted:

???

yeah that looks bad but i dont see why you even need app and common.

just do it like in this guide https://github.com/johnpapa/angular-styleguide

no need to expose global variables. 'angular' is the only global; you just call 'angular.module' to get/set modules

yeah hold up let me read this style guide -

pepito sanchez
Apr 3, 2004
I'm not mexican

Valeyard posted:

yeah hold up let me read this style guide -



:lol:

Flat Daddy posted:

the (app || {}) part is so you can add stuff to the same module in multiple files

i was just worried you were writing that by hand.. combining angular's module system with another module system is always gonna look like trash unforunately

ah, gotcha

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord

Valeyard posted:

yeah hold up let me read this style guide -


jony neuemonic
Nov 13, 2009

Valeyard posted:

yeah hold up let me read this style guide -


Flat Daddy
Dec 3, 2014

by Nyc_Tattoo

Valeyard posted:

yeah hold up let me read this style guide -


Flat Daddy
Dec 3, 2014

by Nyc_Tattoo
exhibit A on why angular freakin sucks. the learning curve is absurd

JewKiller 3000
Nov 28, 2006

by Lowtax

Valeyard posted:

yeah hold up let me read this style guide -


kitten emergency
Jan 13, 2008

get meow this wack-ass crystal prison
so if angular sucks, what sucks less

Flat Daddy
Dec 3, 2014

by Nyc_Tattoo
"X is the default way of doing things. if you actually do X then your code will be slow as poo poo and unmaintainable forever. btw did mention i created this framework so that designers wouldn't need to learn to code. LOL"

triple sulk
Sep 17, 2014



Valeyard posted:

yeah hold up let me read this style guide -


Shaggar
Apr 26, 2006

Valeyard posted:

yeah hold up let me read this style guide -



lmao

my homie dhall
Dec 9, 2010

honey, oh please, it's just a machine

Valeyard posted:

yeah hold up let me read this style guide -


Shaggar
Apr 26, 2006

uncurable mlady posted:

so if angular sucks, what sucks less

knockout

jony neuemonic
Nov 13, 2009

uncurable mlady posted:

so if angular sucks, what sucks less

basically anything.

except maybe ember. that's probably worse.

jony neuemonic
Nov 13, 2009

Shaggar posted:

knockout

:hfive:

Flat Daddy
Dec 3, 2014

by Nyc_Tattoo
react is simple and good.

you define your page as some function that takes 'state' (mutable object) and 'props' (immutable object) and produces a full HTML DOM. then register event handlers that mutate state and your page fully re-renders accordingly.

it sort of achieves the goal of writing as little in JS as possible by letting you think in the same manner you'd create a server-side HTML page. except it's happening on the client & reactjs sorts out the performance cost of the full re-render by turning it into the minimum amount of DOM manipulations necessary


this is so much better because it removes a mental burden, the huge state space of GUI's & the terribleness of DOM. compare this with angular which is just like "put your dom manipulations in these kind of files, put your model manipulations in these kinds of files", etc.

Flat Daddy fucked around with this message at 19:18 on Aug 27, 2015

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

I'm messing around with Websharper at work whenever I can and it's retardedly nice, I'm going to be real sad when I find out its warts.

"hmm wait actually I want to do this part client-side after all" *cut and paste code from [<Rpc>]Server.GetWidgets() to [<JavaScript>]Client.LoadWidgets(), everything still works*

pepito sanchez
Apr 3, 2004
I'm not mexican

Flat Daddy posted:

react is simple and good.

you define your page as some function that takes 'state' (mutable object) and 'props' (immutable object) and produces a full HTML DOM. then register event handlers that mutate state and your page fully re-renders accordingly.

it sort of achieves the goal of writing as little in JS as possible by letting you think in the same manner you'd create a server-side HTML page. except it's happening on the client & reactjs sorts out the performance cost of the full re-render by turning it into the minimum amount of DOM manipulations necessary


this is so much better because it removes a mental burden, the huge state space of GUI's & the terribleness of DOM. compare this with angular which is just like "put your dom manipulations in these kind of files, put your model manipulations in these kinds of files", etc.

i've looked into react, and with the development of relay it just made me more curious. the idea of representing the UI as small maintainable and extensible pieces is cool. the biggest downside i read about was how heavy it is for larger sites. something about how it uses a virtual DOM before transitioning over to the DOM. i assume that facebook's main page actually implements react, and it's not exactly the quickest load in the world. thoughts?

fart simpson
Jul 2, 2005

DEATH TO AMERICA
:xickos:

Flat Daddy posted:

react is simple and good.

you define your page as some function that takes 'state' (mutable object) and 'props' (immutable object) and produces a full HTML DOM. then register event handlers that mutate state and your page fully re-renders accordingly.

it sort of achieves the goal of writing as little in JS as possible by letting you think in the same manner you'd create a server-side HTML page. except it's happening on the client & reactjs sorts out the performance cost of the full re-render by turning it into the minimum amount of DOM manipulations necessary


this is so much better because it removes a mental burden, the huge state space of GUI's & the terribleness of DOM. compare this with angular which is just like "put your dom manipulations in these kind of files, put your model manipulations in these kinds of files", etc.

this is also why elm is good

Arcsech
Aug 5, 2008

NihilCredo posted:

I'm messing around with Websharper at work whenever I can and it's retardedly nice, I'm going to be real sad when I find out its warts.

"hmm wait actually I want to do this part client-side after all" *cut and paste code from [<Rpc>]Server.GetWidgets() to [<JavaScript>]Client.LoadWidgets(), everything still works*

yeah websharper is badass

triple sulk
Sep 17, 2014



Arcsech posted:

yeah websharper is badass

i think u mean piss

Shaggar
Apr 26, 2006

pepito sanchez posted:

i've looked into react, and with the development of relay it just made me more curious. the idea of representing the UI as small maintainable and extensible pieces is cool. the biggest downside i read about was how heavy it is for larger sites. something about how it uses a virtual DOM before transitioning over to the DOM. i assume that facebook's main page actually implements react, and it's not exactly the quickest load in the world. thoughts?

knockout's component model lets you split everything out into maintainable pieces and you can use require.js for loading them. by listing dependencies inside your component's module definition, the component can be entirely self contained. that way you just plop it where you want it and it wires itself up instead of doing a bunch of javascript in the parent object and then passing it to the component. and since ur using requires.js anything that was previously loaded for the root, or other components is already there and available to components. so you aren't doing anything like loading dependencies over and over nor are you loading dependencies that aren't in use.

note that this is for single page applications. if you aren't doing an spa for the love of christ just use razor.

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.

pepito sanchez posted:

i've looked into react, and with the development of relay it just made me more curious. the idea of representing the UI as small maintainable and extensible pieces is cool. the biggest downside i read about was how heavy it is for larger sites. something about how it uses a virtual DOM before transitioning over to the DOM. i assume that facebook's main page actually implements react, and it's not exactly the quickest load in the world. thoughts?

It is faster than Angular, hands down. You can get around the initiation time of Reacts initial render by prerendering it on the server, but once you're in a view with mutations, it'll do it faster than Angular in most cases. The only reason ANgular would feel faster in an initial render is because the templates are DOM, so it can render that DOM straightaway, but the bootstrapping process of actually taking data and turning it into stuff is still slow in Angular, especially with a lot of data binds. The virtual DOM is a far faster way to perform mutations, which is why everyone is copying that approach now (Ember, Can.js, mercury, riot, etc etc)

pepito sanchez
Apr 3, 2004
I'm not mexican

Maluco Marinero posted:

It is faster than Angular, hands down. You can get around the initiation time of Reacts initial render by prerendering it on the server, but once you're in a view with mutations, it'll do it faster than Angular in most cases. The only reason ANgular would feel faster in an initial render is because the templates are DOM, so it can render that DOM straightaway, but the bootstrapping process of actually taking data and turning it into stuff is still slow in Angular, especially with a lot of data binds. The virtual DOM is a far faster way to perform mutations, which is why everyone is copying that approach now (Ember, Can.js, mercury, riot, etc etc)

assume you have absolutely no control over the backend. is this kind of stuff still possible from the front-end or do i have to depend on the server rendering my views? sadly my *actual* work involves a genexus backend, something i can't touch and they are terrified to touch because it's literally purely generated magic code that can't be touched. angular has been the option because nearly everything worth mentioning is done from my station apart from design, and the only thing i send to the backend are ajax calls. i'm really looking forward to next week's job fair at college. this will sound horrifying, but please let me work with a ruby dev instead.

fast edit: i already know knockout is faster than angular, specially with require.js. i don't think that's the same for react, but that's only from what articles i've seen. it's not so much about speed for me, but a specific need of convenience, maintainability, and limiting headaches.

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

pepito sanchez posted:

but please let me work with a ruby dev instead.

:chanpop:

ruby devs can end up being good because they know how bad code can be without any discipline

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS
i'm in the interview pipeline for a ruby job but it's devops and basically chef with some other ruby tooling

if i get an offer i think i'll only take it for a cool six and a half figgies

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.

pepito sanchez posted:

assume you have absolutely no control over the backend. is this kind of stuff still possible from the front-end or do i have to depend on the server rendering my views? sadly my *actual* work involves a genexus backend, something i can't touch and they are terrified to touch because it's literally purely generated magic code that can't be touched. angular has been the option because nearly everything worth mentioning is done from my station apart from design, and the only thing i send to the backend are ajax calls. i'm really looking forward to next week's job fair at college. this will sound horrifying, but please let me work with a ruby dev instead.

fast edit: i already know knockout is faster than angular, specially with require.js. i don't think that's the same for react, but that's only from what articles i've seen. it's not so much about speed for me, but a specific need of convenience, maintainability, and limiting headaches.

No. React IS faster than Angular, but it depends on what you're using it for. If the backend is basically all JSON, go for it with React, but if Angular is working for you don't uproot all your code. That said, you can just bind React components from say an Angular Controller, but then you've just bloated your code with two big libraries/frameworks. In an app I'm working on we had to do that because Angular was abysmally slow on a critical part of the app, and we're gradually phasing that out so it's all React. You don't need server side rendering to do React, but it's a great way to take the bite out of initial page load, which is something EVERY non-trivial single page app will suffer regardless of framework.

Adbot
ADBOT LOVES YOU

Stringent
Dec 22, 2004


image text goes here

MALE SHOEGAZE posted:

:chanpop:

ruby devs can end up being good because they know how bad code can be without any discipline

that's me!

  • Locked thread