« first day (963 days earlier)      last day (461 days later) » 

3:48 AM
@VLAZ Well, my question was more of, await is calling the .then method, which is how this is actually working? So, yes, if that's true, there are obviously plenty of ways that you can break it. Although I don't know how the .then method could tell it's being called implicitly by await or explicitly, unless JavaScript code has a way of checking its own call stack at runtime (sometimes called "reflection").
I'm surprised you have no comments about my little journey to use Stack Overflow to solve my JavaScript problems. :-)
 
 
3 hours later…
6:38 AM
@CodyGray There is no surefire way to tell whether it is await calling or not. But there are good guesses - await obj will call obj.then(successFn, failFn) passing both arguments. So, you can examine if both are being passed in. Whereas most other usages of a programmer calling .then() will be passing a single argument, as obj.then(successFn).catch(failFn) are more common with being more explicit. It also looks nicer in a multi-line chain:
obj
  .then(successFn)
  .catch(failFn)
 
Yeah, I've seen the pattern. Makes sense.
 
Thus if you're implementing the then you can try to make it do something different with two arguments vs just one. And that would very often correspond to using await vs not using await. Not a guarantee, though. Nor does it make much sense to have two different behaviours for these situations.
@CodyGray I thought it would get tiring to bash the low quality answers on SO getting votes. Feels like I do that every time you mention it.
 
Yeah, I just feel like something must be fundamentally broken in JS-related stuff
Because I do not experience this anywhere else on SO
 
I really don't know what. Blatantly wrong answers get upvotes. Answers that literally repeat the code from OP also do. Overall, it seems users vote on how well they think the answer looks. Short answers are very often upvoted and I've seen comments saying that they like having "one liners". Even if it doesn't save that much code. Or even obfuscates intent. Or doesn't even work the same as what the question asks.
 
Hmm
 
6:48 AM
But also longer answers (as in, maybe two paragraphs) seem to also get noticed if they show of some "cool code" which isn't a one-liner but just some roundabout way to achieve some more straight forward result.
 
I guess the process of community vetting breaks down when the members of your community do not, in general, know what they are doing?
 
@CodyGray That's probable a good explanation.
 
@VLAZ This is even more surprising than the like for "one-liners".
 
Yesterday there was a question on how to recognise numbers. The question explicitly mentioned the isNaN function and that it doesn't work for them. There was an answer which started with "you can use isNaN" which totally did not work at all for the question and disregarded the explanation that isNaN didn't work there. It got an upvote somehow.
It was also ChatGPT generated, so the disregard and the wrong advice were understandable. The upvote wasn't, though.
 
Uh...is it just poorly named?
Because I'd think a function named isNaN would only return true if the argument is not-a-number (i.e., NaN).
So it would never work as a general-purpose number-recognition function.
 
6:55 AM
It is. isNaN actually checks if the argument provided will convert to NaN or not. For example converting the string "123" to a number gives you 123. So isNaN("123") will return false. But isNaN("hello") returns true. Which is why there was another one introduced: Number.isNaN() where only Number.isNaN(NaN) is true everything else is false. Which fits your intuition much better. And yet: Is Number.IsNaN() more broken than isNaN()
 
See
When your language behaves like that, how can you expect the people who use it to know what is reasonable?
 
Fair.
 
I really don't understand the answer
Oh wait, I see the problem. It's actually a problem with the question. The asker doesn't understand what "NaN" means. So, the answer is actually responsive to the question, I just read the question incorrectly, assuming it was asking what I would have asked.
 
Yes, I was more pointing at the question which confuses the concept of some value being a number or not and the actual numeric value NaN
 
That would make sense if they'd called is isNotANumber.
But this is a case where using the abbreviation actually makes it more clear.
 
7:00 AM
It's one of those things where it's completely sensible but a large portion of the users seem to misinterpret it.
 
I guess it's because they don't know their programming fundamentals?
 
Same with error messages: code like foo.bar can produce "Cannot access "bar" from undefined" which means that foo is undefined and you cannot access bar from it. Yet very many people post questions on SO daily complaining that bar is somehow undefined even though that 1. wouldn't raise an error 2. the text of the error doesn't fit that narrative.
 
Odd.
Although, hmm, I thought Oleg told me that is safe, and will just produce "undefined"?
No, I guess he was saying your #1, that if bar is undefined and/or doesn't exist, that's fine, and would just return "undefined".
 
Yes, if foo exists but doesn't have a bar property, it just returns the value undefined.
While if foo doesn't exist, well, just think of it as a null pointer exception. Trying to access a property from null. Which incidentally throws the same error just says "Cannot access "bar" from null"
 
Making that distinction seems arbitrary. If you're going to "allow" it (i.e., treat it as not an error, just return undefined) in one context, why not do it in all contexts?
 
7:24 AM
It's only a non-error if it's a "leaf". As in last piece of the chain: a.b.c.d will work if d doesn't exist. But if b doesn't exist, then it's an error because then you're getting quite literally undefined behaviour. If you had department.staff.fred.salary then if staff doesn't exist, doesn't make too much sense to automatically treat it as if good old Fred did exist but didn't have a salary.
It's the same as NPEs, in essence. If something isn't there, it's an error if you try and use elements from it. However, given the fluid nature of objects, it's not an error to try and access a property that doesn't exist. Other (more sensible) languages just don't allow this because the compiler will ensure that if you're calling foo.bar then foo will definitely have a property bar. Yet, the shape of the object is known in advance then.
 
@VLAZ It seems to me to make exactly the same amount of sense.
After learning about it, I've been trying to get into the habit of writing everything with the null-coalescing operator as a matter of habit, because I think this behavior is more predictable and sensible, not to mention easier to write code around.
i.e., department?.staff?.fred?.salary
 
You could do that, I suppose. I'm not against it but I'd prefer to use it a bit more sparingly. Mostly because I prefer to be more sure in the shape of the objects I have, so I'd use ?. when I know something might be null/undefined. I'd rather not assume everything might be, as that means I can't really rely on the objects I have.
 
7:40 AM
Hm, but... it's not a compiled language, so you can't rely on an error.
You're going to have to write run-time code to handle the error, so why not handle it as if an "undefined" object was returned, rather than writing some try/catch to handle an error getting thrown?
 
I'd rather have an error if something is wrong, rather than try to treat each value as nullable. Because if I take the salary, I'd hope it's a number. Not potentially null or undefined. And it might be one of those values even if I know for sure that salaries are set to at least a zero. If fred doesn't exist, then I'd get undefined, while if department is null, I'd get null from the expression.
What's even worse is that both of these will behave differently when used as if they were a number. salary < minimum will return true for null (because it's converted to zero) and false for undefined (because it converts to NaN).
So, depending on which link in the chain is missing and how, a follow-up usage of the value will yield different results.
 
Hmm. I guess I don't fully understand that.
You handle it in a different way?
 
Well, the correct thing would be to check if the result is nullish. However, if you don't do that, then the results will vary based on the exact nullish value.
 
Oh, I think I read about this. I have the habit of writing if (obj) (or, the opposite, if (!obj), assuming that'll check whether the object is null/undefined, but apparently it doesn't. You have to do if (obj == null)
 
More generally if foo?.bar (so, nullish-safe access) is used everywhere, then the result will always be nullable, and would require extra runtime code to weed out the invalid values. Which might be hard if null happens to be a correct value for bar. For example, maybe fred.spouse is null because Fred is divorced. But staff.fred.spouse could also return null if Fred doesn't exist. This conflating "person doesn't exist" with "person is not married".
 
7:55 AM
"Which might be hard if null happens to be a correct value for bar." Haha, well, there's the problem!
That shouldn't ever be the case.
 
@CodyGray if (!obj) will work in a lot of cases. Specifically, it wouldn't for primitive values that are falsy: false, 0, "". However, if it's indeed an object and you know it won't be a primitive value, then if (obj) is fair to use. I tend to prefer == null but I don't really mind.
@CodyGray Honestly, I agree. Just the rest of the programming world just loves the million dollar mistake, so a lot of external code uses null as a valid value.
 
Hmm, I see. I don't have enough experience to know.
I think of it like a null pointer, and, in my world, that doesn't ever mean "Fred is divorced".
 
Well, it really shouldn't. Because marital status and the details of the spouse shouldn't really be conflated. Yet, such things exist often - the details of something about the object are set to represent both "it exist" and the details themselves or null if it doesn't exist. Which are actually two pieces of information.
 
Right, exactly
 
A more "enterprise-y" way to represent that is to have a field for marital status which is probably an enum and then another field for spouse.
Then you'd be doing something like if (fred.maritalStatus === "MARRIED") spouse = fred.spouse.name
 
8:03 AM
Yes
I wouldn't say that's "enterprise-y", because I'd interpret that term as somewhat derogatory :-)
But my fundamental question is, in front-end code, are you actually going to handle the situation differently if the object you expect to exist doesn't exist, versus an object doesn't exist and isn't expected to exist? In the JS I write, I'm not. I'm just going to not display it, or not do whatever it is that I need it to do.
 
Well, that's sort of what I was projecting. But mostly in the sense that I've seen people show disdain for this approach. Because it's deemed "too complex". You need to check two things instead of just one. Moreover, what guarantee do you have that if Fred is married the spouse field will be populated? You could get into the exact same situation as before if spouse is still null!
(that's not my words, just trying to represent sentiments I've heard)
I do disagree with this reasoning, for the record. Make sure your objects are constructed correctly then you'd know that the status can only be set to MARRIED if there are spouse details.
 
Well, also, if you expect spouse to be non-null because of other metadata, but you find that it is null, that's a programming error.
 
Or there can be another approach - there could even be two values - one for being married and the spouse details being present, and one for being married but the details not being there (or further split these two is also valid). Which gives more flexibility in how you represent the data. Also, specifically for marital status, it is even more representative of the real world. The details might be unknown for any reason. Might be privacy, for example.
@CodyGray Yes, that's true. And then I think it's quite sensible to have an error thrown. The state of the application is not expected. Same if you try to, for example, read some data from the disk but the disk isn't there.
 
Yes, except that I can't imagine using JS to write an application. :-)
To me, it's exclusively for dynamically manipulating the front-end presentation layer.
And then only because it's the only thing reasonably well-supported.
 
I mean, that's also true. For larger-scale things TS works. But I really wouldn't suggest building an enterprise-grade application out of TS/JS.
And I think an enterprise-grade application is possible. I just have a huge dislike for the JS ecosystem. Well, there are other problems, as well, but a more robust ecosystem would probably alleviate some of them.
 
8:23 AM
The ecosystem doesn't seem like the primary problem to me.
In fact, compared to what I'm used to, JS has a huge and thriving ecosystem.
 
8:44 AM
I'm not disputing that it's huge and thriving. Just saying that it's garbage. A lot of packages are quite useless and add additional bloat for no real gain. Yet this is not only accepted but many encourage it. Something as simple as checking if a value is an integer is a package. Checking if it's a safe number is also a package. Then there are packages that depend on both of these to tell you if something is, for example, a positive integer. That's three packages. For trivial functionality.
Might seem like I'm exaggarating for effect but is-safe-positive-integer is an actual package and it has four dependencies.
I was actually looking for a different one which I feel demonstrates the issue quire well. But I found this one now and it's just as good for demonstration. Which brings me to another point about the ecosystem - huge redundancy.
I do understand having overlap between several libraries. But you're usually spoiled for choice for which package to use that gives you one function to use only.
 
That sounds more like the curse of popularity
Everyone wants to make their own package because it'll be cool, so they make something stupid and submit it
 
Yeah. It's a problem, though.
 
Is it really?
 
And now that I'm looking at the dependencies of that package - why in hell does it depend on a package for publishing books? Or is-ogrn where (after googling it) OGRN is some sort of registration number for Russian companies?
 
I mean, there's a lot of noise from low-quality submissions, but can't you pretty easily just ignore that?
@VLAZ I'm trying to read about the package Bookiza, but the entire screen is filled with a cool drawing of a peacock feather, so I can't see any text.
 
8:54 AM
@CodyGray The issue is all the people who aren't ignoring it. If you use a dependency it can easily incorporate a dozen of these useless ones. It is, in fact, how a huge amount of JS projects stopped working back in 2016: qz.com/646467/…
Summary: one (or a few) packages used by other packages used by actual projects depended on a package called "left-pad". The author removed that package from NPM breaking all projects that transitively depended on it.
left-pad just pads a string with characters up to length. It was used to pretty print some messages in the log by padding all to, say, 10 characters.
 
Because some juvenile was squatting on a name he hadn't even developed into a package yet, a reasonable request was made to rename it because it conflicted with the name of a widely-recognized service, and he acted like even more of a juvenile by insisting on taking his toys and going home.
I mean, really, the main problem here is that the package management system doesn't take snapshots of the packages that are dependencies.
 
It's a huge mess all around, yes.
Or include sensible things like namespaces/organisation names for packages.
Well, it does now but did it really have to break in order for this need to be recognised? Other package systems exist. It's not like they have to feel around in the dark for how to create a package distribution system and what problems can exist.
 
Wow, yeah, that's a surprising omission.
It's really quite bizarre to me how JS programmers can't list all the dependencies of their code.
I mean, I fundamentally cannot understand that. I can pretty much list everything that my code depends upon off the top of my head.
 
9:10 AM
Yeah, this is the issue - transitive dependencies are a pain. I have a couple of very simple repositories on GitHub that keep getting automatic PRs by dependabot to fix potential security issues. Yet none of the vulnerabilities are in things I directly depend on.
This repository has 11 commits by me and 7 by dependabot. It has a single dependency listed - just ESLint because I wanted to enforce a code style. Well, it's gotten updates for libraries like minimist, minimatch, and ajv. I actually have no clue what any of those do.
 
To me, this is a sign that there is too much ecosystem.
Rather than the opposite, which is what you claimed. :-)
 
I said it's garbage.
I don't think I've said there is not enough of it.
 
Oh, you did say "huge dislike for". I somehow read that as not thinking there was enough ecosystem.
I guess it was "a more robust" that threw me off.
 
Yeah, I guess. Should have been more explicit and said "less garbage" there.
It's too big which makes it too brittle and unreliable.
 
Yes, that likely would have helped me manage the correct interpretation. I know what garbage is. :-)
 
9:15 AM
I'm aware you've seen the flag queue.
:P
 
 
2 hours later…
10:51 AM
I have to apologise to is-positive-integer. I misread it it does not have any dependencies. It has dependents. So, the book thing and the Russian company number thing depend on that package.
I also found the package I was actually thinking about is-positive-int. It's quite obvious, I don't know how I couldn't remember it /sarcasm
It has two dependencies. Each of which has one more. And last I checked several of the total dependency chain were obsolete.
 
It does nothing!
I mean, it literally just calls functions from its dependencies.
 
                is-positive-int
	         /            \
is-safe-integer           number-is-integer
      |                          |
max-safe-integer             is-finite
Ugh, well, not as misaligned now.
But that's the dependency chain
I think that package is a poster child for the endemic over-engineering in the JS ecosystem.
Also, incidentally, it's created by a SO gold JS tag badge holder.
 
I still think it's due to programmers who have no clue what they're doing
And the JS ecosystem has enabled copy-pasta/cargo-cult programming on a massive scale
 
Yes, that is the reason. I was complaining about the result. Same thing, to be honest. It's all bad.
The low bar of entry for JS leads to less rigorous software development. And also a lot of the programming techniques are closer to "oral tradition" than software engineering. It's something you can find in probably most languages but, say, in C/C++ the whole community is well better educated. And strives for higher quality overall.
Whereas there is a large portion of the JS community which just hacks things until it sort of works and then the trial-and-error result is popularised through articles/videos which other just take wholesale.
 
11:06 AM
Oral tradition?
 
@CodyGray Somebody says "guys, I figured out how to do X - here it is" and that's how others learn it. Rather than reading the docs or trying to apply known software engineering techniques and approaches.
 
Oh. Normally when you say, "guys, I figured how to do X - here it is", you put that in the docs, no? :-)
 
And SO is also part of the whole cycle. Just to tie it back in to the beginning of my whole rant. People would post an answer that sort of worked for them. Others would upvote because it looks interesting. Rather than whether it is useful.
@CodyGray Yes. And, honestly, the MDN docs for JS are stellar. I actually prefer them over the C# documentation.
Yet, a lot of questions go "Why do I get Y instead of X when I pass <some value> to <some built-in function>" which is very often answered by the documentation.
With examples and everything.
 
I can only assume that's because most documentation for libraries/tools/frameworks that programmers use is terrible.
So they don't even realize that the rare few of these things actually have good documentation that is worth consulting first.
 
I'd posit they don't check the documentation in general. Rather than having bad experience with it, they have no experience with it. Again due to lack of low bar of entry - you can just hack at things in the console until it works. And check a tutorial for how to build something more complex.
 
11:14 AM
You can hack at things until they work in any programming language. Unfortunately...
 
11:26 AM
Time to create a new language which only compiles if the developer has an official certificate from a course. That would solve every single problem ever.
/s
 
haha, no
 

« first day (963 days earlier)      last day (461 days later) »