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
Pollyanna
Mar 5, 2005

Milk's on them.


I feel very very stupid right now. I'm trying to get a number field to display its values as "n,nnn" instead of "nnnn", but failing. Right now, we're using React+Redux to format incoming string value inputs via toLocaleString, but even with a pattern that allows for commas in numbers I'm still getting this error message:

code:

The specified value "1,200" is not a valid number. The value must match to the following regular expression: -?(\d+|\d+\.\d+|\.\d+)([eE][-+]?\d+)?

What am I doing wrong? What do I need to do to get number inputs to accept/show numbers with commas, formatted as in toLocaleString?

Adbot
ADBOT LOVES YOU

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

Pollyanna posted:

I feel very very stupid right now. I'm trying to get a number field to display its values as "n,nnn" instead of "nnnn", but failing. Right now, we're using React+Redux to format incoming string value inputs via toLocaleString, but even with a pattern that allows for commas in numbers I'm still getting this error message:

code:
The specified value "1,200" is not a valid number. The value must match to the following regular expression: -?(\d+|\d+\.\d+|\.\d+)([eE][-+]?\d+)?
What am I doing wrong? What do I need to do to get number inputs to accept/show numbers with commas, formatted as in toLocaleString?

Does this help?

https://stackoverflow.com/questions/5917082/regular-expression-to-match-numbers-with-or-without-commas-and-decimals-in-text

Pollyanna
Mar 5, 2005

Milk's on them.



Not exactly. Upon digging, that error message is a React error message. This to be a limitation with React/Redux where it imposes that big ol' regex on the value of a number field, and it seems like React just plainly doesn't allow for commas or something. At least, I can't find where that big ol' regex is set - and trying to manually set it on the fields doesn't work.

Unfortunately our React/Redux lead is out on vacation this week, the week we deploy the new version (read: scramble to try and get it in before Wed). :sigh: It may simply not be possible with our current setup.

HaB
Jan 5, 2001

What are the odds?

Pollyanna posted:

Not exactly. Upon digging, that error message is a React error message. This to be a limitation with React/Redux where it imposes that big ol' regex on the value of a number field, and it seems like React just plainly doesn't allow for commas or something. At least, I can't find where that big ol' regex is set - and trying to manually set it on the fields doesn't work.

Unfortunately our React/Redux lead is out on vacation this week, the week we deploy the new version (read: scramble to try and get it in before Wed). :sigh: It may simply not be possible with our current setup.

I'm not a React guy but I was able to google up a couple of react plugins for formatting numbers.

https://github.com/s-yadav/react-number-format

maybe that?

Pollyanna
Mar 5, 2005

Milk's on them.


HaB posted:

I'm not a React guy but I was able to google up a couple of react plugins for formatting numbers.

https://github.com/s-yadav/react-number-format

maybe that?

Would have to run it by our team lead and get buy-in to bring it in. I just told our PM that we can't solve this right now and will have to push it to another sprint. :shrug:

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

Pollyanna posted:

Would have to run it by our team lead and get buy-in to bring it in. I just told our PM that we can't solve this right now and will have to push it to another sprint. :shrug:

Time to rewrite everything in Vue.js while your team lead is gone. Go out in a blaze of glory!

Pollyanna
Mar 5, 2005

Milk's on them.


Skandranon posted:

Time to rewrite everything in Vue.js while your team lead is gone. Go out in a blaze of glory!

No thanks, I've had enough JavaScript adventures for a lifetime. :shepface:

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

Pollyanna posted:

No thanks, I've had enough JavaScript adventures for a lifetime. :shepface:

The only way to transcend your suffering is to accept it willingly. Learn to love the Sisyphean nightmare.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Pollyanna posted:

Not exactly. Upon digging, that error message is a React error message. This to be a limitation with React/Redux where it imposes that big ol' regex on the value of a number field, and it seems like React just plainly doesn't allow for commas or something. At least, I can't find where that big ol' regex is set - and trying to manually set it on the fields doesn't work.

Unfortunately our React/Redux lead is out on vacation this week, the week we deploy the new version (read: scramble to try and get it in before Wed). :sigh: It may simply not be possible with our current setup.

What version of React are you guys using?

edit: I grep -F'ed the entire react git history for that regex and its nowhere to be found. It's possible that it's concatenated from smaller strings or whatever.
edit2: "The value must match to the following regular expression" is not in the react repo working tree. Waiting for git to search the whole history now. It takes a long time!
edit3: That phrase isn't in the React git history either...

Thermopyle fucked around with this message at 20:15 on Jun 12, 2017

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Thermopyle posted:

What version of React are you guys using?

edit: I grep -F'ed the entire react git history for that regex and its nowhere to be found. It's possible that it's concatenated from smaller strings or whatever.
edit2: "The value must match to the following regular expression" is not in the react repo working tree. Waiting for git to search the whole history now. It takes a long time!
edit3: That phrase isn't in the React git history either...

My guess is they are using <input type=number" /> then they are manipulating the value via React into a formatted string in there and the *browser* is complaining. But I'm just an idiot, so I'm probably wrong.

Newf
Feb 14, 2006
I appreciate hacky sack on a much deeper level than you.

Skandranon posted:

The only way to transcend your suffering is to accept it willingly. Learn to love the Sisyphean nightmare.


Lumpy posted:

But I'm just an idiot, so I'm probably wrong.

Lumpy knows the ropes.


Has anyone here used lerna to manage a js (actually TS / TSX / ReactXP in this case) project before? I decided to give it a go as part of a reorganization of an existing code base and I suspect that I've just wandered down one of those paths where I can expect to put 30 hours into tinkering with tooling before I get back to working on the project itself.

If you DO happen to know how lerna works, or know npm well enough to groc it at a glance, feel free to take a stab at this unanswered stackoverflow question of mine.

Also, stackoverflow is so lovely compared to how it used to be. I've put up a few effort-questions in the past couple of weeks that, years ago, would have had a handful of votes and at least a reply or two.

Pollyanna
Mar 5, 2005

Milk's on them.


Thermopyle posted:

What version of React are you guys using?

edit: I grep -F'ed the entire react git history for that regex and its nowhere to be found. It's possible that it's concatenated from smaller strings or whatever.
edit2: "The value must match to the following regular expression" is not in the react repo working tree. Waiting for git to search the whole history now. It takes a long time!
edit3: That phrase isn't in the React git history either...

Yup, I'm actually a jackhole, who knew? It's not React. It's likely to be what Lumpy said:

Lumpy posted:

My guess is they are using <input type=number" /> then they are manipulating the value via React into a formatted string in there and the *browser* is complaining. But I'm just an idiot, so I'm probably wrong.

So it really probably is my own stupidity. I really wish design would just let us use number fields with no commas :(

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Newf posted:



Also, stackoverflow is so lovely compared to how it used to be. I've put up a few effort-questions in the past couple of weeks that, years ago, would have had a handful of votes and at least a reply or two.

People want to gain rep fast, so they just refresh looking for easy to answer simple questions. If typing a response takes three minutes, somebody might type one up in two minutes fifty seconds and beat you so why bother. :smith:

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.

Lumpy posted:

People want to gain rep fast, so they just refresh looking for easy to answer simple questions. If typing a response takes three minutes, somebody might type one up in two minutes fifty seconds and beat you so why bother. :smith:

Yep, effort questions are rarely answered in my experience, usually by maintainers when they are too.

Munkeymon
Aug 14, 2003

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



Is there a good way to identify effort questions? I kind of like answering them when I get bored enough to want to - often they're too specialized into something I don't know at all. Sometimes I look over the bounty questions, but they seem to overwhelmingly have that specialization problem.

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

Lumpy posted:

People want to gain rep fast, so they just refresh looking for easy to answer simple questions. If typing a response takes three minutes, somebody might type one up in two minutes fifty seconds and beat you so why bother. :smith:

I've never seen the point of posting a question to StackOverflow... I've always been able to find answers for what I want from other people's questions, or my situation is non-trivial enough that there isn't already an answer, and I'll usually figure it out myself sooner than I would get an answer from someone else.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Skandranon posted:

I've never seen the point of posting a question to StackOverflow... I've always been able to find answers for what I want from other people's questions, or my situation is non-trivial enough that there isn't already an answer, and I'll usually figure it out myself sooner than I would get an answer from someone else.

I think you are forgetting that most people are lazy and in some cases, not very smart as well.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

I've had a few effort questions answered on SO, but that's overwhelmingly not the case.

I try to answer effort questions though. I subscribe to the RSS feeds for the tags I'm able to help on and maybe a couple times a month I write an effort response.

My highest rated question by far is one I asked not long after SO came out. It's an embarrassingly newbish question.

prom candy
Dec 16, 2005

Only I may dance
What kinds of tests would you want to see for a simple open source React Component? I wrote a small wrapper for an existing JS carousel plugin, should I just be testing whether the props get forwarded as options to the plugin?

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
No need to test the component you are wrapping, test that the wrapped component is rendered and receives the props you expect it to. Then test whatever else your wrapper is supposed to do.

Tei
Feb 19, 2011
Probation
Can't post for 3 hours!
Historians will point at javascript has the cause of the downfall of our civilization. Js is a inflatable castle for kids, that people is using as permanent housing. Js is a army swish knife redesigned medical use. Js is a library full of necronomicons, and a book with a list of books that dont have their own title inside. Js is a mexican standoff between hardcore members of the sgml commite that refuse to go home after the 1986 florida convention. Js is simple, but required the creation of the galactic empire and 54 civil wars. Js is 2 + 2 = 2.0000000003

Edit:

Forgot to add the question.

When people talk about "Virtual DOM in the server" what they mean exactly?

Do they have a object in memory in the server, with the same structure the whole DOM or what?

Tei fucked around with this message at 10:55 on Jun 14, 2017

Plavski
Feb 1, 2006

I could be a revolutionary
yeah, but TypeScript is a good language

it lets me write really, really terse code that makes it impossible for anyone else to quickly understand. but man, look at all these cool exciting new features i'm using! implicit returns for days!

Tei
Feb 19, 2011
Probation
Can't post for 3 hours!

Plavski posted:

yeah, but TypeScript is a good language

it lets me write really, really terse code that makes it impossible for anyone else to quickly understand. but man, look at all these cool exciting new features i'm using! implicit returns for days!

As soon the mayor browsers support web bytecode, I think many people will jump to something like that.

I see some downsides. Is nice to have everyone on the same language. And some people is going to decompile webbytecode into js, then continue there. So some websites in 2024 will be a big unholy main.js file.

Tei fucked around with this message at 11:40 on Jun 14, 2017

HaB
Jan 5, 2001

What are the odds?

Plavski posted:

yeah, but TypeScript is a good language

it lets me write really, really terse code that makes it impossible for anyone else to quickly understand. but man, look at all these cool exciting new features i'm using! implicit returns for days!

Just because you can doesn't mean you should.

Readability > *everything else*

Pollyanna
Mar 5, 2005

Milk's on them.


Plavski posted:

but man, look at all these cool exciting new features i'm using! implicit returns for days!

Babel. :confused:

Plavski
Feb 1, 2006

I could be a revolutionary

if i want to await a Promise.all that async maps over ajax requests, it's really nice to be able to do it in a single, incredibly confusing line

whenever i read guides to advanced typescript/es2017 features it takes me an hour just to unpick the terseness. christ it's almost embarassing how long it took me to get generators - not only is that syntax funky as all hell, but when examples are trying to wedge it all on one line cos implicit returns are the sexiness du jour, it's doubly annoying

nothing makes me feel stupider than reading an example when words like return, if, else, and curly braces have just been dropped in favour of implicits and ternaries

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Of all the things to complain about Implicit return arrow functions is a weird one.

I mean, maybe the first time you see it you might not know what it is, but then after that, what's to worry about.

luchadornado
Oct 7, 2004

A boombox is not a toy!

Generators in JS are meh and are a stepping stone to the amazingness that is async/await. I'd wait until async/await catches more traction before ditching promises. Look at a library like Koa to see an example of how libraries are following these cutting edge features and not stabilizing appropriately to the detriment of gaining acceptance.

Implicit returns and ternary operators are cool and good. If you see them in a code review being abused to the point its hard to understand the code, spit on them and tell them to stop being an expert beginner.

() => isValid ? ({a: 1}) : ({a: 2});

Is way easier to read/write than:

function() {
if (isValid) {
return {a: 1};
}. else {
return {a: 2};
}
}

Just because you can do something like this https://aphyr.com/posts/341-hexing-the-technical-interview doesn't mean you should. Pragmatism is a skill many developers lack.

prom candy
Dec 16, 2005

Only I may dance
10+ years ago when I was a young and stupid Ruby developer my goal was always to write the sickest one-liners I could, with no regard for character limits. God I was a dumbass.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Terseness is not a valid criticism of a language or language feature.

A language should be as terse as is readable and no more. It's just as bad for it to be too verbose.

Any feature that enables terseness or verboseness can be abused to harm readability.

Readability does not mean "able to understand what this does the first time I ever encounter the language construct".

Tei
Feb 19, 2011
Probation
Can't post for 3 hours!

Thermopyle posted:

Terseness is not a valid criticism of a language or language feature.

A language should be as terse as is readable and no more. It's just as bad for it to be too verbose.

Any feature that enables terseness or verboseness can be abused to harm readability.

Readability does not mean "able to understand what this does the first time I ever encounter the language construct".

I completely agree with this dude.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
Yeah but the Javascript community has gone nuts. I think JS is the best language there is, there I said it. I haven't tried all of them, but the feature set, how fast it is, and how widely utilisable a .js file is across platforms and devices cannot be ignored. There are a million ways to compile things into JS if you don't like using ES2015+, but even if you do, it's really really good.

Where things go wrong is within the community. When it started it made sense because JS was terrible, so there were a million libraries that made JS unrecognisable. Now, when I look at a pile of new fangled library, framework, and obfuscation infused JS code my eyes roll into the back of my head. You don't need all that crap. The language does everything you need out of the box.

Stop re-inventing the language and use the language, internet. Stop introducing libraries that enable you to write incredibly confusing, slow, "functional only" crap. Stop trying to warp it, it's great the way it has become. I'm so thankful the dark lords who introduce new language features ignore 99% of it.

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

Nolgthorn posted:

Yeah but the Javascript community has gone nuts. I think JS is the best language there is, there I said it. I haven't tried all of them, but the feature set, how fast it is, and how widely utilisable a .js file is across platforms and devices cannot be ignored. There are a million ways to compile things into JS if you don't like using ES2015+, but even if you do, it's really really good.

Where things go wrong is within the community. When it started it made sense because JS was terrible, so there were a million libraries that made JS unrecognisable. Now, when I look at a pile of new fangled library, framework, and obfuscation infused JS code my eyes roll into the back of my head. You don't need all that crap. The language does everything you need out of the box.

Stop re-inventing the language and use the language, internet. Stop introducing libraries that enable you to write incredibly confusing, slow, "functional only" crap. Stop trying to warp it, it's great the way it has become. I'm so thankful the dark lords who introduce new language features ignore 99% of it.

While I have come to appreciate JS more than I once did, it does not do everything you need out of the box. For example, it has a terrible default string manipulation library, which is how we ended up with the padLeft() catastrophe. This is one of the places I think C# really shines, it's included libraries are much better that most.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Nolgthorn posted:

Yeah but the Javascript community has gone nuts. I think JS is the best language there is, there I said it. I haven't tried all of them, but the feature set, how fast it is, and how widely utilisable a .js file is across platforms and devices cannot be ignored. There are a million ways to compile things into JS if you don't like using ES2015+, but even if you do, it's really really good.

Where things go wrong is within the community. When it started it made sense because JS was terrible, so there were a million libraries that made JS unrecognisable. Now, when I look at a pile of new fangled library, framework, and obfuscation infused JS code my eyes roll into the back of my head. You don't need all that crap. The language does everything you need out of the box.

Stop re-inventing the language and use the language, internet. Stop introducing libraries that enable you to write incredibly confusing, slow, "functional only" crap. Stop trying to warp it, it's great the way it has become. I'm so thankful the dark lords who introduce new language features ignore 99% of it.

This post ties me in knots because I strongly agree with it and strongly disagree with it.

Like, yeah there's too many developers chasing too many new things. On the other hand there's a ton of very useful libraries that you're just being a masochist or someone stuck in their ways for not using. And picking functional programming as an example of what you're on about is weird as functional programming is cool and good and has nothing to do with chasing new and shiny.

porksmash
Sep 30, 2008

Nolgthorn posted:

Stop re-inventing the language and use the language, internet. Stop introducing libraries that enable you to write incredibly confusing, slow, "functional only" crap.

Turns out programming runs on the same cycle as fashion.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

Thermopyle posted:

This post ties me in knots because I strongly agree with it and strongly disagree with it.

Like, yeah there's too many developers chasing too many new things. On the other hand there's a ton of very useful libraries that you're just being a masochist or someone stuck in their ways for not using. And picking functional programming as an example of what you're on about is weird as functional programming is cool and good and has nothing to do with chasing new and shiny.

The problem isn't functional programming, functional programming changed my life in some small ways. But it is to be used in moderation, not for everything.

Stuck in your ways, imo, is using a hundred libraries for everything regardless that they are new libraries. That is how JS has been done for a very long time and it simply is not needed anymore. It takes effort to learn how to write raw JS that doesn't require constant never ending fiddling to keep working.

Tei
Feb 19, 2011
Probation
Can't post for 3 hours!
Maybe the reason theres 16000 files in the node_directory is because javascript lacks a good standard library.

But I will not talk about this further, because JS has better minds than me, and I don't want to say something too stupid in public.

The Fool
Oct 16, 2003


Tei posted:

Maybe the reason theres 16000 files in the node_directory is because javascript lacks a good standard library.

But I will not talk about this further, because JS has better minds than me, and I don't want to say something too stupid in public.

node_modules inflation is more of an issue with npm than js.

yarn does a lot to reduce that, from my understanding

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

The Fool posted:

node_modules inflation is more of an issue with npm than js.

yarn does a lot to reduce that, from my understanding

Even if you reduce it to 1000, it still says something about JavaScripts lack.

Adbot
ADBOT LOVES YOU

luchadornado
Oct 7, 2004

A boombox is not a toy!

Thermopyle posted:

This post ties me in knots because I strongly agree with it and strongly disagree with it.

Like, yeah there's too many developers chasing too many new things. On the other hand there's a ton of very useful libraries that you're just being a masochist or someone stuck in their ways for not using. And picking functional programming as an example of what you're on about is weird as functional programming is cool and good and has nothing to do with chasing new and shiny.

This is some wisdom right here, but I've also been more careful about about chastising people for not using libraries. The line between pragmatism and idealism is heavily blurred in JS.

I got mocked for implementing one of Bluebird's functions from scratch in a module I made. When that module and some others were split out into proper npm modules used across all the web apps, mine worked fine, and everyone else came across bugs and build problems because of the modules that required Bluebird as a peer dependency and didn't manage/communicate that well. I unfortunately come across that type of situation far too frequently even with "ubiquitous" libraries like jQuery and lodash. There are a lot more libraries in use because the core language lacks a lot of useful things and Javascript developers are hyper-focused on nano-modularization. Yarn vs npm doesn't fix those issues.

React Router is a pile of garbage that can't figure out how it wants to work if you look at the 2/3/4 versions. Express is an open source project that the creator sold for a few thousand dollars and went through some ridiculous ownership drama. Redux was based on one guy liking some functional aspects and claiming they were necessary without explaining why or how and leaving things like how to handle asynchronous dispatches up to the community, but it was still better than Flux and its creator who claimed that MVC doesn't scale. It's an entire community that flits from idea to idea, communicates lovely opinions in 140 characters or less, re-invents the wheel whenever possible, and never stops to think "how do we make this better". Somehow, it convinces people that these are admirable traits.

Because of that, I'm burnt out on it. I'll probably still use Node for POCs and React for some webapp stuff, but I just can't do it anymore. I've started doing a lot more backend stuff and interviewing for fullstack or backend positions and it :feelsgood:

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