Then I noticed you said C#. Sorry; that won't work full stop. But the concept will.A few minuts ago, I wrote:. . . it only works in Java11+. . . .
Campbell Ritchie wrote:Can you reduce the multiple Boolean expressions to one expession? Can you look for methods in the String class?The String#strip() method is probably better than trim() but it only works in Java11+. I challenge you to find a reliable way to avoid the null test.
Carey Brown wrote:This isn't anywhere near real code. You have unbalanced parens. And, I would think Equals() would return a boolean, so what does Equals().Trim() do?
tangara goh wrote:
Carey Brown wrote:This isn't anywhere near real code. You have unbalanced parens. And, I would think Equals() would return a boolean, so what does Equals().Trim() do?
This is the c# portion in which I replaced it with .trim Java syntax. Cos C# one is troublesome - still need to do some replaceOf method ..
I am more concerned how do I go about refactoring the code by putting the ! Boolean with the conditions that return true and false and another Boolean method with different conditions that return true and false.
I hope to get some some guidance about this part.
Tks.
I have already given you some guidance. You simply have to translate it into C#.tangara goh wrote:. . . I hope to get some some guidance about this part. . . .
Education won't help those who are proudly and willfully ignorant. They'll literally rather die before changing.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
I don't think you need an if‑else in the first place. I haven't seen anything to suggest that my technique can't be adapted to your requirements.tangara goh wrote:. . . Can I know this if else structure mus it ends with a else . . . .
Education won't help those who are proudly and willfully ignorant. They'll literally rather die before changing.
Tim Holloway wrote:Or, just to combine everyone's suggestion (assuming that all those minor tests were to see if a space-trimmed name matched in a case-independent way)
Campbell Ritchie wrote:
I don't think you need an if‑else in the first place. I haven't seen anything to suggest that my technique can't be adapted to your requirements.tangara goh wrote:. . . Can I know this if else structure mus it ends with a else . . . .
If each if contains return xyz; then you don't need an else at the end. You can get away with a plain simple return. But, as you will see in the old Sun Style Guide, it isn't good style to writeNot even if you can abbreviate it toThis is what you want to write:-
Yes, if the semantics of the “after” formula is the same as the “before” formula. You haven't actually told us what the formulae are, so I can't tell you. Do you know any Boolean algebra?tangara goh wrote: . . . What if I put all the true first before I put all the false and returning the false ? Will it be ok ?
I am afraid I still don't like that sort of code.I did a refactoring last night and it looks like this . . .
That's a pleasureThank you guys.
Maybe yes, but there is no need after if (xyz) return true; Because such code transfers control back to its calling method, the else is unnecessary. If we overlook the missing code path which might fail to reach a return..., this sort of codebecomesYou can sort out the missing return problem by getting rid of the second if:-You can get rid of the first if by cancelling out its double negative:-I think a few excess bang signs have crept in there But you can simplify the multiple equals calls into one and go back to my first suggestion.fred rosenberger wrote:. . . nested if statements?
Education won't help those who are proudly and willfully ignorant. They'll literally rather die before changing.
Start by reading all the replies you have got, especially my first reply.tangara goh wrote:. . . how do I make it happen in a boolean method ?
Campbell Ritchie wrote:
Maybe yes, but there is no need after if (xyz) return true; . . .fred rosenberger wrote:. . . nested if statements?
But you can simplify the multiple equals calls into one and go back to my first suggestion.
Campbell Ritchie wrote:NULL is a predefined constant in C/C++; you mean null, surely.
Did you understand my first post in this discussion? You quoted it, but I don't get the impression you really understood it.
Education won't help those who are proudly and willfully ignorant. They'll literally rather die before changing.
Tim Holloway wrote:
Campbell Ritchie wrote:NULL is a predefined constant in C/C++; you mean null, surely.
Did you understand my first post in this discussion? You quoted it, but I don't get the impression you really understood it.
Actually, NULL is a macro defined (if memory serves) in stdlib.h and more than once for various reasons I've had to define it manually. "null" is improper usage as C tradition is that manifest constants should have names that are all uppercase. Or at least the original kind done via pre-processor before "const" became part of the language.
Campbell Ritchie wrote:Please show us your final solution.
Campbell Ritchie wrote:Don't use == true or similar, which is poor style and rror‑prone because you might write = true or similar by mistake.
What is the logic behind the use of substrings? It doesn't look right to me. And where does return false; in line 4 come from?
Stop messing around with code. You are simply tying yourself in knots. Write down what you require on paper, with your computer turned off.
But we believe people when they show us their code. We see people who really do write == true all the time.tangara goh wrote:. . . I didn't use == true . . . I thought it was more clear to you guys.
But false isn't a return type; it is result and the return type is bool/boolean/Boolean.. . . the return type false
I really feel as if I were going round in circles here You seem to be repeating yourself again. Or are you repeatedly testing the same thing? The multiple returns where you don't seem to know what you want are dreadfully error‑prone. Have you analysed that code or done a truth table for it? You still haven't shown me anything better thanI am trying to remember where I first saw that sort of code.and there isn't a better way to do it than like this below: . . . My question is the end return true will refer to which condition ? Will it refer to
. . .
That's a pleasureThank you . . .
Look ma! I'm selling my stuff!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|