XOR is for the weak
-
That's the most horrible thing I've seen today.
Regards, Rob Philpott.
TBF it's an IDE's "autofix". I've written a condition:
isValid = (someAreaId != null) ^ (longitude != null && latitude != null);
if (!isValid) { ...Which literally translates to "either someAreaId is not null or both coordinates are not null". This is a required business logic and it doesn't seem to be a way around it. And then I got a "simplify boolean" and "inline variable" quickfixes. If you pass the initial "WTF" feeling, then it starts to make sense.
-
public class SomeLocationData
{
// fields...public SomeLocationData(Long someAreaId, String longitude, String latitude) { if ((someAreaId == null) == (longitude == null || latitude == null)) { throw new IllegalArgumentException("Either someAreaId or coordinates must be specified."); } // ... init fields
THAT CHECK. :cool:
Looks like a buggy check... what if all 3 are specified? That's will throw the error, that's what! :doh:
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
-
Looks like a buggy check... what if all 3 are specified? That's will throw the error, that's what! :doh:
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
I think that's what it's supposed to do. Either one or the other needs to have a value, not both and not neither ;)
Best, Sander sanderrossel.com Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly
-
I think that's what it's supposed to do. Either one or the other needs to have a value, not both and not neither ;)
Best, Sander sanderrossel.com Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly
well perhaps.. but then the error message is misleading! :o
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
-
well perhaps.. but then the error message is misleading! :o
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
How is
Either someAreaId or coordinates must be specified.
misleading, it doesn't say AND?
-
How is
Either someAreaId or coordinates must be specified.
misleading, it doesn't say AND?
Mmm.. maybe the nuance of English are lost on me.. not being a native... This message doesn't seem to imply to me that it is wrong to have both condition true...
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
-
Mmm.. maybe the nuance of English are lost on me.. not being a native... This message doesn't seem to imply to me that it is wrong to have both condition true...
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
It's the very definition of "either... or..." (a.k.a. XOR) ;) Actually, I don't think the code is that bad. I think a lot more programmers can read that than an XOR, which is far from common in C#.
Best, Sander sanderrossel.com Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly
-
It's the very definition of "either... or..." (a.k.a. XOR) ;) Actually, I don't think the code is that bad. I think a lot more programmers can read that than an XOR, which is far from common in C#.
Best, Sander sanderrossel.com Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly
-
It's the very definition of "either... or..." (a.k.a. XOR) ;) Actually, I don't think the code is that bad. I think a lot more programmers can read that than an XOR, which is far from common in C#.
Best, Sander sanderrossel.com Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly
-
public class SomeLocationData
{
// fields...public SomeLocationData(Long someAreaId, String longitude, String latitude) { if ((someAreaId == null) == (longitude == null || latitude == null)) { throw new IllegalArgumentException("Either someAreaId or coordinates must be specified."); } // ... init fields
THAT CHECK. :cool:
Also, you should not be using
String
but
string
I recommend taking a look at this. string vs. String is not a style debate[^]
-
Also, you should not be using
String
but
string
I recommend taking a look at this. string vs. String is not a style debate[^]
-
public class SomeLocationData
{
// fields...public SomeLocationData(Long someAreaId, String longitude, String latitude) { if ((someAreaId == null) == (longitude == null || latitude == null)) { throw new IllegalArgumentException("Either someAreaId or coordinates must be specified."); } // ... init fields
THAT CHECK. :cool:
It's old school rock! :cool: I remembered how to MessageBox (in Client) some texts on ASP.NET...
protected void ShowMessage(string message)
{
string msg = "alert('" + message + "');";
base.ClientScript.RegisterStartupScript(base.GetType(), "jsShowMessage", msg, true);
}Yeah!