-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Let's figure out how we want &&
and ||
to work
#7479
Comments
Wait, Also, I wonder if this falsiness table should be used with |
Good call, I think Since #7383 we have a way to distinguish between an empty pipeline and a null value, which I think is essential. edit: I'm actually less sure about this after further thought. I could go either way on |
Why not keep it consistent with mainstream languages? For example, in JavaScript, empty string and 0 are false |
I don't think we want to treat |
It's not really a mistake per se (Python also does this, albeit with a simple, robust rule about what values are and aren't falsy) but it's not necessarily desirable for Nushell. By the way… I think |
My thinking is that many commands return It's possible that I'm using the terms "truthy" and "falsy" in a slightly misleading way here, perhaps "success" and "failure" would be more accurate. |
Hmm, good point. "Success" and "failure" are a bit more enlightening. |
It's really tough to fit the original purpose of this traditional feature into Nu's internal commands.
This is the most important & significant advantage of this feature. For example, Same with Due to these reasons, I recommend one of two solutions for the time being.
As far as your current table goes, I think that's acceptable & understandable. Anything with a Nu Error is a "failure". Boolean That said, I would very very very very very strongly recommend against taking examples from languages like JavaScript & Python. For example, JavaScript is basically the incarnation of a design failure. This language does not contain design failures. It is a design failure in itself. It shouldn't even exist, not to mention be popular. |
As someone who's worked on a single JS codebase for over 8 years, I'll say that TypeScript is pretty fire emoji though, which kind of says a lot about how much of JS's problems boil down to "the type system". Also, funny coincidence, but I just came back from reading a tweet about how a friend of a friend of a friend just succumbed to cancer, into reading this post, so…… a bit unsmooth, my fellow. …Anyway, back on topic:
Rather than "it depends", only side-effectual commands ( This also fits in well with the PR for nullable cell paths #7540: for |
As much as I am against Micro$oft, I have to agree, that TypeScript is the emergency chute for JavaScript. It handles so many JavaScript related problems. Yes, mainly the type system.
Sorry about that. I just see the language C as a serious sickness in the general programming world & JavaScript is basically the same, but for browsers. However, once everyone stops using C for everything but embedded & legacy projects, I won't need an analogy as drastic, because the sickness would be cured. I will already be satisifed, once Linux is mostly (re-)written in Rust. Once it crosses the 50% line, C will become insignificant enough.
Okay, I never dove this deep into it, but the first question that is raised in my head, when reading this is, whether this is a rule or more or less a coincidence. I mean, if we expect the behaviour the way you describe, then it must be followed in all future implementations of similar commands or whatever comes next in Nu. Basically, it has to become a rule or guideline a developer has to actively follow.
Now that is truly interesting. Thank you very much for the insight. I didn't think about it, that way. Nice!
Ironically, when reading & processing the preceding sentence, my brain came to the exactly opposite conclusion.
Ah, the sexiness from Kotlin. Yes. That's nice. Now I get your point regarding the explicit null being a "failure". This makes sense, now. Although, I guess I am biased from Kotlin. In Kotlin I'm not for plain copying of behaviour from other languages, but I'm also unsure, whether an explicit null like this is always "bad" in Nu, too. I guess, it's not even about "bad" or not -- it's more about how we want I just notice, that from your examples Anyway, thank you for the information about the behind the scenes. It's interesting to know & think about. |
Is it possible to move forward with this? By that, I mean, do we understand how we want everything to work with |
As discussed in this week's meeting, we should figure out the plan for error handling with
&&
and||
. JT landed an initial PR recently but had to revert it.As a starting point, let's agree on whether various data types should evaluate to success or failure for the purposes of
&&
and||
. To recap:foo && bar
will runbar
only iffoo
succeeded.foo || bar
will runbar
only iffoo
failed.Here's my (probably wrong/incomplete) first stab at the question:
Value::Error
Value::Nothing
PipelineData::Empty
Value::Bool(false)
false(1)
. not 100% sure about this onValue::Bool(true)
List
orListStream
that contains aValue::Error
(in any position of the list)ListStream
gets interesting because you can't know up front whether it contains an errorList
s andListStream
sValue
variantsdo -i
or something similar@jntrnr I think this is what you were asking for, just let me know if I missed something.
The text was updated successfully, but these errors were encountered: