Skip to content
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

Refactor Blocks #35

Merged
merged 6 commits into from
Sep 30, 2016
Merged

Refactor Blocks #35

merged 6 commits into from
Sep 30, 2016

Conversation

mandaiy
Copy link
Member

@mandaiy mandaiy commented Sep 18, 2016

Following changes are made in this commit:

  • Rename classe
    As we discussed offline
  • Extract common functions among block classes
    Changed NumberTextHolder interface for better encapsulation
  • Change return value type of BlockBase#getKind
    The previous code uses Class class, which does not represent actual
    use case (e.g., ForwardSecBlock#getKind returns SequenceBlock.class).
    Replaced Class<? extends Block> type with Enum.
  • Remove locale-dependent code on parsing numbers
    The previous code relies on the Locale.US no matter what locale
    this app runs on.
    This commit fixes the locale dependent code by extracting the parsing
    logic.
  • Fix the unspoken rule that using scaled values
    for communicating between blocks and number pickers.
    The previous code scaled values so that the value has no radix
    point, which was confusing code.
    Fixed by replacing the type with BigDecimal and explicitly use the raw
    value.
    In accordance with it, changed the type of "number"
    in ProgramDataSpec for saving without data loss
  • Remove code in Unit class for handling quantities, which was ugly and cannot be used widely.
    Changed second string ("second/s" -> just "s")

@tiwanari
Copy link
Member

Thanks for this PR 👍 Because I merged other PRs, there are conflicts :( Please fix them.

Following changes are made in this commit:
* Rename classes
    As we discussed offline

* Extract common functions among block classes
    Changed NumberTextHolder interface for better encapsulation

* Change return value type of BlockBase#getKind
    The previous code uses Class class, which does not represent actual
    use case (e.g., ForwardSecBlock#getKind returns SequenceBlock.class).
    Replaced Class<? extends Block> type with Enum.

* Remove locale-dependent code on parsing numbers
    The previous code relies on the Locale.US no matter what locale
    this app runs on.
    This commit fixes the locale dependent code by extracting the parsing
    logic.

* Fix the unspoken rule that using scaled values
  for communicating between blocks and number pickers.
    The previous code scaled values so that the value has no radix
    point, which was confusing code.
    Fixed by replacing the type with BigDecimal and explicitly use the raw
    value.
    In accordance with it, changed the type of "number"
    in ProgramDataSpec for saving without data loss

* Remove code in Unit class for handling quantities, which was ugly and cannot be used widely.
    Changed second string ("second/s" -> just "s")
@mandaiy
Copy link
Member Author

mandaiy commented Sep 28, 2016

Hey @tiwanari, resolved conflicts.
Please take a look at my commit. Thanks.

@tiwanari
Copy link
Member

Thanks for notifying me :) Please give me a little time to check them.

Copy link
Member

@tiwanari tiwanari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made comments but before seeing them, please make the PR enable to be built. There are errors with merged code (ExecutionCondition).

try {
return (Class<T>) Class.forName(className);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this blank line makes this program more readable. Is there any specific reason to keep blank lines like this? If no, please remove such lines.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seriously? I DO THINK SO.

but this is kinda religious war and here's your realm.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, I didn't want to mean it :( I agree that adequate blank lines help code reading.

I couldn't see the consistency between these blank lines here and previous codes at review but now I'm guessing you added blank lines between long lines. It can give a kind of tender impression to codes I think. I wanted to know some of rules, i.e. why you added it here and didn't there.

We haven't talked enough about blank lines beforehand and formatters never specify it. I really appreciate if you share your thoughts :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't take my comment seriously and offensive, please.
For consistency you are right.
And topics of the format are bit off from here.
Anyway I'll merge this. Thanks.

incidentally you can witch-hunt with

$ grep -ElR "catch \(.*\) {" app | xargs perl -0777 -pe 's/\n(\s*} catch \(.*\) {)\n/$1/g'

for making your realm calm and getting rid of "pagans"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. The one-liner seems to illustrate a rule "add blank lines before & after a catch clause" :)

btw, `realm' has a bit overwhelmed impression for me... 😓

public static final int UNDO = 3;
public static final int LOAD = 4;

/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a question. Did you remove Javadocs from here because the method is private, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The answer is Yes

@@ -29,14 +30,14 @@
*/
public abstract class RepetitionBlock extends BlockBase {

public static final int FOREVER_WHILE_OFFSET = -1000;
static final int FOREVER_WHILE_OFFSET = -1000;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found this cannot be package private here because it is used in ExecuteCodition. This may be controversial.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to ExecutionCondition, since this field is irrelevant for the operation of blocks.
(btw ExecutionCondition is no longer "condition")

@@ -38,131 +38,93 @@
public static final int SEQUENCE = 0;
public static final int REPETITION = 1;
public static final int SELECTION = 2;
@Deprecated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, this is my fault. I forgot to remove this constant. Please remove it and I will add it in #12 .

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

import java.math.BigDecimal;
import java.util.Locale;

public class NumberTextViewDelegate {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you give a short description of this class as a Javadoc here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

import java.text.ParseException;
import java.util.Locale;

public class ParseUtil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class also has many blank lines. It's okay if it has reasons.

}
}

public static BigDecimal bigDecimalValueOf(String value) throws NumberFormatException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please give a Javadocs as you made above.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

* @param context an application context
* @param integralPart the length of integral part
* @param decimalPart the length of decimal part
* * Constructor.
Copy link
Member

@tiwanari tiwanari Sep 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: double *.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

return Integer.parseInt(numText.getText().toString());
}
// TODO: set from preference
private static final int PRECISION = 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 is okay but it was 0.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

public double getMin() {
return 0.0;
public Range<BigDecimal> getRange() {
return range;
}

@Override
public int action(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is my fault but if you have time, please remove break lines... (this is not mandatory)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@tiwanari
Copy link
Member

Overall, they are really good and cleaned 👍

* remove UNDO in BlockFactory.java
* move FOREVER_WHILE_OFFSET in RepetitionBlock.java to ExecutionCondition.java
* add Javadocs on NumberTextDelegate
* change the signature of BlockSpaceManagerBase#placeBlock (ArrayList to List)
* rename OnTouchNumTextListener to OnTouchNumberTextListener
* remove OnNumberTextListener#context and rename holder to mHolder
* rename Unit#getUnitString to decorateValue and introduce new class NumberUtil
for the following classes:
* NumberTextViewDelegate
* Unit
* NumberUtil
* ParseUtil

And cradle.build in the root directory is modified to add the dexmaker libraries
which are necessary for mockito
Copy link
Member

@tiwanari tiwanari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@mandaiy mandaiy merged commit 17ea9c6 into PileProject:develop Sep 30, 2016
@mandaiy mandaiy deleted the refactor/block branch October 3, 2016 07:00
tiwanari pushed a commit that referenced this pull request Mar 22, 2017
* Refactor Blocks

Following changes are made in this commit:
* Rename classes
    As we discussed offline

* Extract common functions among block classes
    Changed NumberTextHolder interface for better encapsulation

* Change return value type of BlockBase#getKind
    The previous code uses Class class, which does not represent actual
    use case (e.g., ForwardSecBlock#getKind returns SequenceBlock.class).
    Replaced Class<? extends Block> type with Enum.

* Remove locale-dependent code on parsing numbers
    The previous code relies on the Locale.US no matter what locale
    this app runs on.
    This commit fixes the locale dependent code by extracting the parsing
    logic.

* Fix the unspoken rule that using scaled values
  for communicating between blocks and number pickers.
    The previous code scaled values so that the value has no radix
    point, which was confusing code.
    Fixed by replacing the type with BigDecimal and explicitly use the raw
    value.
    In accordance with it, changed the type of "number"
    in ProgramDataSpec for saving without data loss

* Remove code in Unit class for handling quantities, which was ugly and cannot be used widely.
    Changed second string ("second/s" -> just "s")

* Fix PR according to the comments on #35

* remove UNDO in BlockFactory.java
* move FOREVER_WHILE_OFFSET in RepetitionBlock.java to ExecutionCondition.java
* add Javadocs on NumberTextDelegate
* change the signature of BlockSpaceManagerBase#placeBlock (ArrayList to List)
* rename OnTouchNumTextListener to OnTouchNumberTextListener
* remove OnNumberTextListener#context and rename holder to mHolder
* rename Unit#getUnitString to decorateValue and introduce new class NumberUtil

* Add and fix tests

for the following classes:
* NumberTextViewDelegate
* Unit
* NumberUtil
* ParseUtil

And cradle.build in the root directory is modified to add the dexmaker libraries
which are necessary for mockito

* Remove superfluous line-breaks

* Add constructor guards for util classes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants