This week's book giveaway is in the Server-Side JavaScript and NodeJS forum.
We're giving away four copies of Micro Frontends in Action and have Michael Geers on-line!
See this thread for details.
Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!

tangara goh

Ranch Hand
+ Follow
since Dec 27, 2009
I am a beginner in Java and hope to pick up the trade secrets so that I can move on to Android development
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
2
Received in last 30 days
0
Total given
107
Given in last 30 days
3
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by tangara goh

Stephan van Hulst wrote:

tangara goh wrote:May I know why you mentioned storing responses in my database ?


Because you gave a class ApiResponse in the description of your entities.

But, this is a REST, should it be stored in a database for consuming..?


I don't really know what you mean by this. If your question is whether you should store API responses in the database, my first instinct is no, you should not. But I don't know the design of the application, so maybe your supervisor can shed more light on this.



Thanks Stephan.  Thank God I still have this forum to ask for opinion ....

I'd check with her cos the API responses she indicated it as part of the Models but then it is not part of the REST response....

Stephan van Hulst wrote:@OneToMany

Why are you storing responses in your database?



Thanks Stephan...I am glad that I am not the only one that feel blurred about this structure but then let me clarify with my supervisor about it.

Actually, this is a REST app with the typical POST, PUT etc where one of it is Updating a pet in the store with a form data.

I guess I need to create another question in the right forum...cos I really don't think I can handle this alone....

May I know why you mentioned storing responses in my database ?

But, this is a REST, should it be stored in a database for consuming..?
I need some help to verify if I get the relationships of these entities correct.  It is using Spring JPA.



I feel that the rest are One to One but really I am not sure cos it's been 4 years already since I touched JPA....

Please help me and let me know if there are anything wrong with the relationships...
Tks.

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.



Hi Campbell,

Sorry for the late reply as I was fighting fire at my end..

I didn't use == true in my actual code...It is used here cos I thought it was more clear to you guys.

I am back here yet with another question which I am curious to know :
The thing is that there are new added conditions which makes the return type false 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



I hope you can let me know how things work here cos I am quite confused about this part.

Thank you guys once again for your help.

5 days ago

Campbell Ritchie wrote:Please show us your final solution.



I'd love to but right right I just realised I didn't finish the code at all after I was pointed out that I missed out certain cases

And really I am so careless...really not cut out to do coding

The thing is I have problem in executing a case where I need to find the TargetName at the end of a sentence but I can't use .Contains because if I do I will make other cases failed.

So far, I tried to make use of substring like this


But, it is not working....

Really, I have been working on this for the past few hours and I am not getting it ...I think it is really demoralising...
1 week ago
I have been trying to get this solution right to no avail...

Please let me know what's wrong with my code such that I am not getting the solution



Tks.

(edited code : wrong code earlier)
1 week ago

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.



Yap.  Thank you guys for your help.

I think I finally resolve all the errors...but it just made me feel if I am suitable to do coding at all
I mean I really spent lots of effort on the problem which I think any experienced person can do it within 10minutes ?
And really my foundation is just so shaky.... cos this is really quite fundamental in any cs ...
I feel that my future is very very bleak....
1 week ago

Campbell Ritchie wrote:

fred rosenberger wrote:. . . nested if statements?

Maybe yes, but there is no need after if (xyz) return true; . . .
But you can simplify the multiple equals calls into one and go back to my first suggestion.



what if there is a null inside which I need to handle ? I can't possibly use exceptions handling right ? or should I use try catch if say the text is NULL ?
1 week ago
Yes, Tim,
In fact, now I am being driven to insanity because of this if x and not !x thing.  Actually, if it is !x, then there is no need to check further...but how do I make it happen in a boolean method ?

1 week ago

Campbell Ritchie wrote:

tangara goh wrote:. . . Can I know this if else structure mus it ends with a else . . . .

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.
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:-



What if I put all the true first before I put all the false and returning the false ? Will it be ok ?

I did a refactoring last night and it looks like this :



But, I told my boss I would upload my code to the git so I guess if he is only to mock at it ...let it be...I need to look for another job for sure ...can't wait till the day I pack and go while other temp guys still staying around for more months...

I'lll come back here and learn.

Thank you guys.
1 week ago

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.
1 week ago

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.



I will try that Thanks Campell.

Can I know this if else structure mus it ends with a else as the last statement, given the above code that I have provided because there is a lot of true and false that is mixed with this !boolean method and boolean method == true and again follows by alot of true and false in this boolean method is true.

I feel that I am totally lost!

Please help me on this.

Thanks again.
1 week ago
Hi guys,

I am back to another refactoring which I really need some serious help because my boss thinks I am very bad in my programming and also the job duration is very short and I need to look for another job again

The code structure goes like this :

Sorry this is C# code again so the syntax may be off.... and I know NUTS about C# ....but what to do I really need the money....which is better than being a cashier....


How do I make the code more effective since there is so many conditions combined with this Boolean method that is true and ! Boolean method?

Thanks.



1 week ago

Carey Brown wrote:I'm not a C# person but I see some potential issues:

  • Sometimes "Trim" is used and other times "Trim()" is used.
  • There's an if(expression); {...} // the semi-colon shouldn't be there.

  • Is this code you've already refactored a bit?
    Why do you think it's not clean?



    Sorry there was probably an error there in the pre-refactored code.

    Actually, I don't know much about C# but what to do, my boss insisted Java == C#
    And really I need the money ...cos it is not much but better than working as a cashier where I can't even say I know I will be deemed ARROGANT!

    How would you go about further refactoring the code since there are quite alot of similar elements in the if else portion?
    2 weeks ago
    I am in a temporary job where I am asked to do unit test but the code is not written in a 'clean' way so I am having difficult in performing unit test and something that I am still struggling.
    The language used is not Java but C# but I am used to this forum so I hope someone can advise me how to go about refactoring because I really am lost and my skill is still very shaky.



    The refactored method is





    I would like to know what are the refactoring methods I can use in order to make the code more clean for unit test.
    Especially the part in the



    Thanks.
    2 weeks ago