Are you sure about that? Does that reminds you something? a^2+b^2=c^2Lucian Whiteman wrote:if at least 3 of the contained numbers in the array can form a triangle (the sum of any 2 is bigger than the third one)
Tim Driven Development | Test until the fear goes away
Is that readability? I would think it is a more severe error than that. You might return an int in C or in most of the languages that preceded Java® but using an int when a boolean is available counts as incorrect code (or not writing Java® code) in my eyes.Tim Cooke wrote:My first readability gripe would be the return type.
A method called 'isTrianglePossible' is a question, therefore I expect the return type to be a boolean.
Not that one, but the one which is above "for" loop.Lucian Whiteman wrote:if inside for is not needed
Liutauras Vilda wrote:
Not that one, but the one which is above "for" loop.Lucian Whiteman wrote:if inside for is not needed
Because you're starting check with "for" loop from the beginning of the array, so, during the first iteration you'd check exactly the same elements as you would check in "if" statement.
If you had a competition to make the readability worse, that would be up amongst the leaders for the prize.Lucian Whiteman wrote: . . .
Liutauras Vilda wrote:Lucian,
Can you explain what is this? What are you trying to accomplish with it? Stop guessing how the code should look like - you should be writing down the steps on piece of paper and trying to solve the problem on it first.
Campbell Ritchie might a bit sarcastic, but very right
There are three kinds of actuaries: those who can count, and those who can't.
You said thata readability formatting freak.
I read that as meaningHe does not allow me methods greater than 10 - 15 lines.
He is obviously trying to find out whether you can program.My boss knows how to program.
Campbell Ritchie wrote:I can see another problem in that code, I am afraid, which makes it not correct in my opinion. I can see a side‑effect which might cause incorrect behaviour of other code.
At least you can see the problem . Seeing the problem is half the battle.Lucian Whiteman wrote: . . .
The array gets sorted inside the function, and this is a side effect that may cause bugs in other parts. Got that, thank you.
. . .
Now the method name is containing an "and", thus no more single responsibility principle and no more job for me. What to do ? How can I rewrite it better ?
Campbell Ritchie wrote:
At least you can see the problem . Seeing the problem is half the battle.Lucian Whiteman wrote: . . .
The array gets sorted inside the function, and this is a side effect that may cause bugs in other parts. Got that, thank you.
. . .
Now the method name is containing an "and", thus no more single responsibility principle and no more job for me. What to do ? How can I rewrite it better ?
At least two things you can do1: Don't sort the array. Use it unsorted. 2: Don't sort the array. Sort something else. By the way. I would look on that method as incomplete if you don't have a documentation comment.
Liutauras Vilda wrote:Lucian,
As Campbell Ritchie rightly pointed out, you keep changing the instructions/requirements.
It is quite difficult to do the things without knowing what has to be in a final version, and these changes are not minimal or something extra - it changes all things in general.
Very 1st program you posted were intended to do completely different thing. Please clarify.
Lucian Whiteman wrote:I do not have written specification, or any of such guidance. So I write the code, and pray it works with minimal bugs.
Lucian Whiteman wrote:
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |