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
Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
no, I have source maps enabled. but source maps are extremely fragile, and they don't seem to work for breakpoint debugging (local variable names are still mangled, sometimes chrome just shows me the unmapped .js file anyway). error stacks as well seem to be completely untranslated through source maps. and how do i import modules through the JS console REPL?

it's weird because we solved debuginfo years ago with DWARF but somehow the web guys decided to throw all of it out the reinvent it with some quirky JSON garbage, and they can't even do that right

Adbot
ADBOT LOVES YOU

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Dumb Lowtax posted:

A good estimation of how long typescript takes to setup

:confused:

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.

Suspicious Dish posted:

no, I have source maps enabled. but source maps are extremely fragile, and they don't seem to work for breakpoint debugging (local variable names are still mangled, sometimes chrome just shows me the unmapped .js file anyway). error stacks as well seem to be completely untranslated through source maps. and how do i import modules through the JS console REPL?

it's weird because we solved debuginfo years ago with DWARF but somehow the web guys decided to throw all of it out the reinvent it with some quirky JSON garbage, and they can't even do that right

i've definitely gotten breakpoint debugging to work with source maps before, it's not an intrinsically impossible thing.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Lumpy posted:

What is "estimating"? Is that when you first hear the arbitrary deadline imposed on you?
I was saying you are correct in estimating "don't think learning typescript and getting the tooling all set up will fit in [three days]".
Because even just getting the tooling all set up correctly, if you can do typescript just fine already, will likely take you more than three days, unless you already happen to use an overcomplicated set of tooling that can trivially flip over from javascript to typescript.

Roadie
Jun 30, 2013
Parcel is definitely the least bad of the bundlers, and it still has a bunch of obviously lovely design decisions, like how raw file text inclusion requires this bizarre thing with fake API calls that get text replaced at parse time.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

roomforthetuna posted:

I was saying you are correct in estimating "don't think learning typescript and getting the tooling all set up will fit in [three days]".
Because even just getting the tooling all set up correctly, if you can do typescript just fine already, will likely take you more than three days, unless you already happen to use an overcomplicated set of tooling that can trivially flip over from javascript to typescript.

Ahh. Gotcha. I *want* to use typescript (actually I want to use Elm, but...) but in a fairly sized codebase with crazy deadlines I don’t see the daylight to work it in there.

To be fair, I started a small personal project a few months ago and was hell bent on using typescript: I made it about two hours in and was reading about typing my redux action when I deleted it and started over with plain old JS. :smith:

Maybe my New Years resolution will be to actually do something with it. Is there a React / Redux focused resource you guys would recommend? Having written some stuff in Elm, I see the benefit, but I can’t stop listening to the voice that says “you’d be done by now if you just used vanilla....”

Suspicious Dish
Sep 24, 2011

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

Bruegels Fuckbooks posted:

i've definitely gotten breakpoint debugging to work with source maps before, it's not an intrinsically impossible thing.

i've seen it working before, once. it's not impossible but it's really brittle and nobody seems to care to invest any time into fixing it.

LOOK I AM A TURTLE
May 22, 2003

"I'm actually a tortoise."
Grimey Drawer
I mostly do my debugging with console.log these days, to be honest.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
I think my issue with Typescript is just that ES2015+ is really really good. It does whatever I need without types when I write my code cleanly. More than that, I spend a lot of my time in Node, which immediately means Typescript is not nearly so useful to me. I do not want to compile my code if I don't have to and in Node my code is always going to run the same way. When I transition to the client side, I have very little reason to context switch my programming language.

That's probably the biggest reason Node took off in popularity, because people didn't want to write in two languages.

The least important reason I don't want to use Typescript is because combining it with god knows what you really need, like Vue or a any number of front end technologies is more difficult than not doing it. The pain points aren't worth it unless I'm writing something exceedingly complicated. I'd rather just write explicit code across a large number of different files anyway.

danishcake
Aug 15, 2004
Anyone have any experience calling native code from Electron? I've been fiddling with it recently and I can't help but feel like I'm fighting the system somehow.

I have a dll/.so/dylib that has been convenient built by someone else, and I wanted to call a couple of functions in it. I started out with ffi, and quickly wrapped the dll up on Windows. Moved over to a Mac and found that ffi hasn't been maintained since 2016, and no longer works with anything newer than Node 8. I tried replacing ffi with ffi-napi, which seemed to work with Node 10, but I couldn't get it to compile with electron-rebuild.

Eventually I gave up and used an ancient version of Electron. I presume I've just missed the memo that ffi isn't used anymore or something. How do people call into DLLs in 2018?

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Nolgthorn posted:

I think my issue with Typescript is just that ES2015+ is really really good. It does whatever I need without types when I write my code cleanly. More than that, I spend a lot of my time in Node, which immediately means Typescript is not nearly so useful to me. I do not want to compile my code if I don't have to and in Node my code is always going to run the same way. When I transition to the client side, I have very little reason to context switch my programming language.

That's probably the biggest reason Node took off in popularity, because people didn't want to write in two languages.

The least important reason I don't want to use Typescript is because combining it with god knows what you really need, like Vue or a any number of front end technologies is more difficult than not doing it. The pain points aren't worth it unless I'm writing something exceedingly complicated. I'd rather just write explicit code across a large number of different files anyway.

I sort of feel this way, but I also know that no matter how good ES2015+ is, typescript is there to protect me from myself.....

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


Yeah, even if you don't need the extra features, then just enable JS scanning in tsc so you can see where you're being a bit sloppy.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!
Is there a lazy way in Javascript to avoid making this mistake I always make when doing adventofcode sort of things?
code:
let input = `butt=4, rear end=3
butt=7, rear end=7`;
for (const line of input.split(/\n/)) {
  let [discard, butt, rear end] = line.match(/butt=(\d+), rear end=(\d+)/);
  console.log(butt+rear end);
}
Where I want the output to be 7, 14 but of course the output is 43, 77. I know how to fix it once I realize I've done it, but is there some sort of thing I could use more like sscanf where I extract numbers from a string in the form of numbers in the first place rather than having to remember to call parseInt on them all after the match?

Happy Thread
Jul 10, 2005

by Fluffdaddy
Plaster Town Cop
You can put a unary + operator in front of the variable to force it to cast to a number even if string, which is just one character to type as opposed to parseInt, so maybe then you'll remember to?

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Dumb Lowtax posted:

You can put a unary + operator in front of the variable to force it to cast to a number even if string, which is just one character to type as opposed to parseInt, so maybe then you'll remember to?
That is a handy thing I didn't know, thanks. I don't think it will work for this purpose though, because you can't do [+a, +b, +c] = numbersExtractedFromAString;

But it will at least make it less annoying and verbose when I notice and do the retroactive correction.

vvvv Yeah, I got it, but that's where it's too late for me to cultivate a habit of doing it - converting at use-time rather than at capture-time.

roomforthetuna fucked around with this message at 08:00 on Dec 16, 2018

Happy Thread
Jul 10, 2005

by Fluffdaddy
Plaster Town Cop
You'd have to do

quote:

console.log(+butt+(+rear end))

Wheee

necrotic
Aug 2, 2005
I owe my brother big time for this!
edit: I do not read well in the morning

Happy Thread
Jul 10, 2005

by Fluffdaddy
Plaster Town Cop
Yeah it's hard coming out of line.match. I doubt there's a way to use the + operator on the call itself that respects the destructuring of the returned object.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Dumb Lowtax posted:

Yeah it's hard coming out of line.match. I doubt there's a way to use the + operator on the call itself that respects the destructuring of the returned object.
I suppose I could just not destructure it at first hit, like
code:
let m = line.match(/stuff/);
let [x, y, z] = [+m[1], +m[2], +m[3]];
Which I wouldn't have wanted to do with parseInt, but with the unary + might be short enough to work.

Happy Thread
Jul 10, 2005

by Fluffdaddy
Plaster Town Cop
That seems MUCH better and more explicit to the reader. First line is about strings, second line is about numbers.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Dumb Lowtax posted:

That seems MUCH better and more explicit to the reader. First line is about strings, second line is about numbers.
Well, it's adventofcode sort of things I'm doing (in a real programming context I wouldn't mind just using parseInt) so there is no reader.

Learning about the unary plus already paid off today though, I'm pretty sure it saved me enough time to gain a position, and having talked about it also kept me from making the "forgetting to turn strings into numbers" mistake again, so thanks!

Strong Sauce
Jul 2, 2003

You know I am not really your father.





if you need to parse an array from string into a number.. why not just
code:
arrayOfIntStrings.map(Number)

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Strong Sauce posted:

if you need to parse an array from string into a number.. why not just
code:
arrayOfIntStrings.map(Number)

Yeah, do that.

Happy Thread
Jul 10, 2005

by Fluffdaddy
Plaster Town Cop
Whoa that is cool, class name as a constructor as a function pointer as a casting utility

Happy Thread
Jul 10, 2005

by Fluffdaddy
Plaster Town Cop

roomforthetuna posted:

so there is no reader.

You are the reader!

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

Strong Sauce posted:

if you need to parse an array from string into a number.. why not just
code:
arrayOfIntStrings.map(Number)

That seems ambiguous. I prefer the explicit form.

code:
arrayOfIntStrings.map(num => parseInt(num, 10))

necrotic
Aug 2, 2005
I owe my brother big time for this!
Nah, map(Number) is great. Its equally explicit and easier to read.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
It's not entirely clear what it's doing.

code:
typeof Number('35')
"number"
typeof new Number('35')
"object"
What if you want to ensure it's an integer, or moreover, perform additional tests to ensure the value isn't undefined?

code:
Number()
0
Number('')
0
Number(undefined)
NaN
Would you prefer the first or second form of the following for example?

code:
arrayOfIntStrings.map(num => parseInt(num, 10));
arrayOfIntStrings.map(num => Math.floor(Number(num)));
So it's more extendable and therefore easier to read, because I know what was expected to come out of it when I read it again in 10 years.

Happy Thread
Jul 10, 2005

by Fluffdaddy
Plaster Town Cop
Getting some weirdness when I type "JavaScript" out in another thread and it gets filtered to "java script". Doesn't happen here though??

Kobayashi
Aug 13, 2004

by Nyc_Tattoo
I’m messing around with Typescript and dependency injection. Separately, I like them both. Together, I hate them. So many decorators and incantations to wire everything together. I think it’s mostly the decorators. They feel like an extra layer of indirection to me.

Roadie
Jun 30, 2013

Dumb Lowtax posted:

Whoa that is cool, class name as a constructor as a function pointer as a casting utility

JavaScript code:
[
  "value 1",
  whateverCondition && "value 2",
  "value 3"
].filter(Boolean)
Gotta be careful with your implicit falsy cases, of course.

Kobayashi posted:

I’m messing around with Typescript and dependency injection. Separately, I like them both. Together, I hate them. So many decorators and incantations to wire everything together. I think it’s mostly the decorators. They feel like an extra layer of indirection to me.

Dependency injection in JS is usually at best a horrible leftover of the pre-import days.

smackfu
Jun 7, 2004

necrotic posted:

Nah, map(Number) is great. Its equally explicit and easier to read.

I’m not a huge fan of the readability because it doesn’t look like a function with the uppercase.

lunar detritus
May 6, 2009


smackfu posted:

Im not a huge fan of the readability because it doesnt look like a function with the uppercase.

I mean, it's Number, I think someone can count on devs knowing how that works. Hopefully.

:negative:

Strong Sauce
Jul 2, 2003

You know I am not really your father.





its for an advent project not dealing with credit card numbers or money...

if you're just writing some quick function to convert an array of strings into numbers so you can add them up you're not exactly sanitizing data there... is parseInt returning NaN any better than Number returning 0 for empty string? well that depends on what you want to do.

One allows for
code:
array.map(Number).reduce((acc, val) => acc + val, 0)


But if it absolutely positively has to be an integer and you only want the integers

code:
["1","sdf", undefined,"0","10000"].map(i => parseInt(i)).filter(Number.isInteger)

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS

Strong Sauce posted:

its for an advent project not dealing with credit card numbers or money...

if you're just writing some quick function to convert an array of strings into numbers so you can add them up you're not exactly sanitizing data there... is parseInt returning NaN any better than Number returning 0 for empty string? well that depends on what you want to do.

One allows for
code:
array.map(Number).reduce((acc, val) => acc + val, 0)


But if it absolutely positively has to be an integer and you only want the integers

code:
["1","sdf", undefined,"0","10000"].map(i => parseInt(i)).filter(Number.isInteger)

Always specify a radix for parseInt.

Happy Thread
Jul 10, 2005

by Fluffdaddy
Plaster Town Cop

Roadie posted:

JavaScript code:
[
  "value 1",
  whateverCondition && "value 2",
  "value 3"
].filter(Boolean)
Gotta be careful with your implicit falsy cases, of course.

It looks cool and I feel like I almost see it, what it's it used for?

Raskolnikov2089
Nov 3, 2006

Schizzy to the matic

Blinkz0rz posted:

Always specify a radix for parseInt.

this guy lints with airbnb

Strong Sauce
Jul 2, 2003

You know I am not really your father.





Blinkz0rz posted:

Always specify a radix for parseInt.
Why? On the chance you're parsing some number that begins with "0" then some other digits, and you need to support IE8? then sure... but then you're also not going to be able to use Number.isInteger.

Doom Mathematic
Sep 2, 2008

Strong Sauce posted:

Why? On the chance you're parsing some number that begins with "0" then some other digits, and you need to support IE8? then sure... but then you're also not going to be able to use Number.isInteger.

There's that, there's also the famously surprising way that array.map(Number.parseInt) behaves.

Adbot
ADBOT LOVES YOU

Strong Sauce
Jul 2, 2003

You know I am not really your father.





Doom Mathematic posted:

There's that, there's also the famously surprising way that array.map(Number.parseInt) behaves.
It's a good thing I didn't just write: array.map(parseInt) then isn't it?

edit: passing a radix was to address the issue of how parseInt handled "0"+<num> in IE8 or <ES5 browsers.

additionally if you're using _map_ then parseInt(x, 10) is redundant since ES5 is when you got _map_ and then a formal definition of what the default radix is if it's not defined (10).

so again giving advice to always specify a radix is outdated and useless. if we're talking about using map/filter then you're fine using parseInt without a radix.

Strong Sauce fucked around with this message at 11:13 on Dec 22, 2018

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