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
piratepilates
Mar 28, 2004

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



MALE SHOEGAZE posted:

but what if I like, want to bind a function defined in my webpack entry to an onclick handler?


add the handler to the element in javascript, instead of the handler to the element in html

or use the output.library configuration to configure how you export your bundle, so you can reference it off of Window

Adbot
ADBOT LOVES YOU

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
got it. this explains so much.


thank you.

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 assuming from you manually binding event handlers to html that this is a page mostly rendered on the backend right?

that's a perfectly valid thing to do (and there should probably be more frameworks that are centered around that kind of thing), but would be weird if it's a front-end heavy page

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

piratepilates posted:

i'm assuming from you manually binding event handlers to html that this is a page mostly rendered on the backend right?

that's a perfectly valid thing to do (and there should probably be more frameworks that are centered around that kind of thing), but would be weird if it's a front-end heavy page

yeah, mostly backend. I'm just using webpack to deal with transforming ES6 and jsx. I don't need any of the splitting or even the async loading (except for dependencies) because our total JS footprint is pretty tiny.

i've just always hooked into my JS with an onload or something, so the idea of not importing anything into the document/window context is weird.

brap
Aug 23, 2004

Grimey Drawer
yeah I tend to couple the script to the document by having some <div id="container"></div> and then calling document.getElementById("container") as a starting point

Volte
Oct 4, 2004

woosh woosh
I'm porting a Typescript React app back to Javascript this weekend. I actually wanted to do a massive refactoring/restructuring operation anyway and introduce Redux, but my main complain about Typescript is that it has not actually saved me from runtime errors on very many occasions. There's enough kludgery involving third party libraries, union types, and other things that I've found the Typescript compiler to be nothing but a hindrance and I still have to deal with enough runtime errors (the kind that a real statically typed language would not have to deal with) that I'd rather switch to ES6 and get the mainstream support.

edit: If I had the resources to maintain perfect type definitions and do everything "right" it would probably be worth it. I don't though.

Asshole Masonanie
Oct 27, 2009

by vyelkin

fleshweasel posted:

yeah I tend to couple the script to the document by having some <div id="container"></div> and then calling document.getElementById("container") as a starting point

this is the correct way (and they way they show in all the tutorials) and they call it MOUNTING

Soricidus
Oct 21, 2010
freedom-hating statist shill
the more i read about webdev, the more glad i am that i don't have to deal with any of that poo poo

at least the clown shows I use were designed by professional clowns with many years experience in the circus

brap
Aug 23, 2004

Grimey Drawer
I have found third party definitions files mostly easy to set up, generally reliable in usage, and very helpful in improving the tooling.

I really fear for you if you're gonna throw out typescript right before doing a big refactor. that's exactly when you would benefit from the type checking.

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
i'm flying with es6 now and dang it's really really nice. honestly it's pretty decent scripting language. i could see using it over ruby or python. having JS's first class functions along with like...usable templating and finally a decent syntax for anonymous functions is pretty usable and fun.

Volte
Oct 4, 2004

woosh woosh

fleshweasel posted:

I have found third party definitions files mostly easy to set up, generally reliable in usage, and very helpful in improving the tooling.
Did you read the part where I found the exact opposite?

brap
Aug 23, 2004

Grimey Drawer
yeah, what I'm trying to say is you might just have hosed up at doing it.

CPColin
Sep 9, 2003

Big ol' smile.
I might try to learn Ceylon.

Send help.

gonadic io
Feb 16, 2011

>>=
i've been doing lots of rust lately. did you know there's a person on stack overflow who spends the majority of their time editing "rust" to "Rust" in everybody's posts?

rust seems good tho

Vanadium
Jan 8, 2005

gonadic io posted:

Rust seems good tho

yeah it's pretty good

Phobeste
Apr 9, 2006

never, like, count out Touchdown Tom, man

gonadic io posted:

i've been doing lots of rust lately. did you know there's a person on stack overflow who spends the majority of their time editing "rust" to "Rust" in everybody's posts?

rust seems good tho

Ice Cream Sandwich

cowboy beepboop
Feb 24, 2001

gonadic io posted:

i've been doing lots of rust lately. did you know there's a person on stack overflow who spends the majority of their time editing "rust" to "Rust" in everybody's posts?

rust seems good tho

yeah now the standard library is stabilising a bit and the 3rd party ones are sorting their poo poo out it's good

Volte
Oct 4, 2004

woosh woosh

fleshweasel posted:

yeah, what I'm trying to say is you might just have hosed up at doing it.
Basically I agree, but not loving up seems to involve a lot of either extra time commitment that I don't have right now (to maintain definition files for third party libraries), or putting up with a lot of 'as any' casts, which completely undermines the entire point of Typescript. I am 75% of the way through porting my React app to ES6 and the little bit of time lost because of the few times I accidentally passed X where I meant Y is nothing compared to the amount of time I was losing before dealing with Typescript's complaints about this interface not being assignable to that one (which 99% of the time was a problem with the type annotations or interface definitions, not a bona fide data flow problem).

Don't get me wrong, I'm a huuuge proponent of static typing, and I look forward to dancing on JS's grave. But as far as I'm concerned, static typing needs to be pervasive (as opposed to optional) and have strong implications about runtime correctness in order to be truly useful to me. Typescript merely checks that its view of things is coherent according to its big list of axioms, but says nothing about whether it is correct. It takes extra effort to make sure that coherent and correct are the same thing (i.e. that Typescript's axioms actually reflect reality), and since I was dealing with most of the problems that JS brings anyway, the added cognitive burden just didn't seem worth it.

Mahatma Goonsay
Jun 6, 2007
Yum
anyone have an opinion on flow vs typescript or is it just the same poop from a different butt?

piratepilates
Mar 28, 2004

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



Mahatma Goonsay posted:

anyone have an opinion on flow vs typescript or is it just the same poop from a different butt?

typescript is made by nerds on the c# team, flow is made by facebook's ocaml pl nerds.

flow has a bit better type inference and nerdy types, typescript has some of it but is more traditional typing (like c#)

people use typescript, for some reason almost no one uses flow

typescript has a big community, flow has a tiny community

flow has support for some es6 features, typescript has support for all of them + some es8 features (async/await)

more or less different consistency poops from different butts

Notorious b.s.d.
Jan 25, 2003

by Reene

uncurable mlady posted:

scala seems like something with a couple of good ideas wrapped in a whole lot of bad ideas

i basically just want (a good) way to write something that runs on windows and linux and i want var :(

java will get a 'var' type thing sooner or later. (probably not in java 9 tho)

the jep:
http://openjdk.java.net/jeps/286

the 'bug' for the spec is actually better than the jep:
https://bugs.openjdk.java.net/browse/JDK-8151454

M31
Jun 12, 2012

Mahatma Goonsay posted:

anyone have an opinion on flow vs typescript or is it just the same poop from a different butt?

typescript expected you to write javascript like it's c# or java. flow allowed much more idiomatic javascript by virtue of a better type system and type inference. flow never got a working windows version though and then typescript stole all of flow's good ideas. TS 2.0 (the next release) will support non-nullable types by default, which was the last major difference between them i guess

also typescript has really good support in all major editors

CPColin
Sep 9, 2003

Big ol' smile.

Notorious b.s.d. posted:

java will get a 'var' type thing sooner or later. (probably not in java 9 tho)

the jep:
http://openjdk.java.net/jeps/286

the 'bug' for the spec is actually better than the jep:
https://bugs.openjdk.java.net/browse/JDK-8151454

Haha why would they introduce both "var" and "val" instead of "var" and "final var"?

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
"final var" makes mutability the shorter default option, so a lot of people will just use "var" even when they have no plans to assign a new value to the variable. making them the same length dramatically increases how many people will use the immutable version whenever possible

CPColin
Sep 9, 2003

Big ol' smile.
So make your IDE automatically add "final" when you have a value that can use it? (Eclipse can already do this.) I'm just saying, why add two keywords when the "final" keyword is already sitting right there?

piratepilates
Mar 28, 2004

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



Javascript got the dumbest version of a 'const' variable identifier keyword

the 'const' identifier, which does not actually make the variable constant, just the binding of it constant:

code:
const boobs = {
    nice: true
};

boobs.nice = false; //No error

boobs = {}; //Error

I feel like there could have been a better name for that than burning off 'const' which could have some day actually been used for constant immutable objects.

Sapozhnik
Jan 2, 2005

Nap Ghost
ya c# const is idiotic too

it's just like java final

except it doesn't force you to actually initialize the poo poo

CPColin
Sep 9, 2003

Big ol' smile.
That "final" keyword is, admittedly, pretty worthless in Java. I see some people insist on putting it on all method parameters. I always want to ask what that's protecting against.

raminasi
Jan 25, 2005

a last drink with no ice

Mr Dog posted:

ya c# const is idiotic too

it's just like java final

except it doesn't force you to actually initialize the poo poo

what

qntm
Jun 17, 2009

piratepilates posted:

Javascript got the dumbest version of a 'const' variable identifier keyword

the 'const' identifier, which does not actually make the variable constant, just the binding of it constant:

code:
const boobs = {
    nice: true
};

boobs.nice = false; //No error

boobs = {}; //Error

I feel like there could have been a better name for that than burning off 'const' which could have some day actually been used for constant immutable objects.

boobs is constant here, but its value is the location of the object in memory. I don't really know C++ but I think it's like a const pointer?

JavaScript code:
var boobs1 = {nice: true};
var boobs2 = boobs1;
console.log(boobs1 === boobs2); // true

boobs1.nice = false; // No error
console.log(boobs1 === boobs2); // still true

boobs1 = {}; // This would be an error if boobs1 was const
console.log(boobs1 === boobs2); // false
If you would like an immutable object, I think you want Object.freeze().

Soricidus
Oct 21, 2010
freedom-hating statist shill

CPColin posted:

So make your IDE automatically add "final" when you have a value that can use it? (Eclipse can already do this.)

because that's worthless. the value of the distinction is that it captures your intention. adding final automatically just captures the status quo at some arbitrary point in the process of typing in the code, which doesn't tell you anything about whether the variable is supposed to be mutable or not.

and what's wrong with having two reserved type names instead of one? the proposal explicitly doesn't make them full keywords, so your variable called val isn't going to become illegal. and if you have an existing class called val then frankly you deserve everything you get.

kitten emergency
Jan 13, 2008

get meow this wack-ass crystal prison

const can be a null reference in c#, the only restriction is that the value of your const field or local has to be evaluated at compile-time

raminasi
Jan 25, 2005

a last drink with no ice

uncurable mlady posted:

const can be a null reference in c#, the only restriction is that the value of your const field or local has to be evaluated at compile-time

how many times has that actually caused any problems in practice

brap
Aug 23, 2004

Grimey Drawer
flow's documentation just seemed really flippant to me. like the fact that they didn't even mention how to run the language on windows and just had mac/linux instructions. gives off the vibe that facebook doesn't give a poo poo about anyone else's use case outside of facebook and so you shouldn't depend on it.

CPColin
Sep 9, 2003

Big ol' smile.

Soricidus posted:

because that's worthless. the value of the distinction is that it captures your intention. adding final automatically just captures the status quo at some arbitrary point in the process of typing in the code, which doesn't tell you anything about whether the variable is supposed to be mutable or not.

So type "final" when you declare the variable? Of course, it's still going to be worthless anyway, because you can still probably mutate the poo poo out of whatever object you just declared.

quote:

and what's wrong with having two reserved type names instead of one? the proposal explicitly doesn't make them full keywords, so your variable called val isn't going to become illegal. and if you have an existing class called val then frankly you deserve everything you get.

I dunno, I just figured the java designers usually have such a boner for reusing keywords, they might reuse one in this case.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

fleshweasel posted:

flow's documentation just seemed really flippant to me. like the fact that they didn't even mention how to run the language on windows and just had mac/linux instructions. gives off the vibe that facebook doesn't give a poo poo about anyone else's use case outside of facebook and so you shouldn't depend on it.
they don't have instructions for running it on windows because they just ported it to windows a month or two ago and haven't officially released a version with windows support yet

brap
Aug 23, 2004

Grimey Drawer

CPColin posted:

So make your IDE automatically add "final" when you have a value that can use it? (Eclipse can already do this.) I'm just saying, why add two keywords when the "final" keyword is already sitting right there?

I'm weary of this argument that you should just use IDE tooling to make up for the bad syntax of your language that causes users to do less safe/robust things by default. it's seriously not an excuse for having a bad language.

Sapozhnik
Jan 2, 2005

Nap Ghost
Yeah if it were up to me then I'd change Java to (A) make byte unsigned and if I get a B then (B) make "final" the default state of affairs that you have to opt out of.

But hey Java is used to develop serious applications that adults depend on to conduct business, so the stewards of the language don't just burn it all to the ground and start from scratch every five years except the bike shed is going to be pink instead of blue this time.

CPColin
Sep 9, 2003

Big ol' smile.
I hope everybody understands I'm not defending Java's stupid "final" keyword. I agree that it's pointless most of the time. By extension, "val" would be, too.

Ceylon seems to get it right (for modern values of "right"); immutable is the default and you have to annotate stuff with "variable" to make them behave otherwise.

Adbot
ADBOT LOVES YOU

abraham linksys
Sep 6, 2010

:darksouls:
is there a comprehensive overview of typescript that I'm missing? like http://www.typescriptlang.org/Handbook doesn't even tell you the syntax for a loving hash map (which is apparently { [key:string]:Type; })

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