Michael Bruce Allen

Ranch Hand
+ Follow
since Sep 21, 2015
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Michael Bruce Allen

probably not that interesting, I know. I am just trying to learn to be a efficient coder.
Hey folks. I thought I would come of to the Agile area and meet a few people who have similar outlooks. I feel Agile coding is important to me, even in my early stages. I also want to share what I am working on and ask if anyone would care to share a few pointers.

I have been practicing TDD quite a bit and here is a thread that I started where I have gotten most of my TDD and SOLID practice TDD-Simple-Calculator

As for this thread (the Boggle board), is I want to try building a simple boggle board generator and one that can rotate the board. There will be no in game mechanics. It is a simple Boggle board generator and rotator (kinda like the game Wordament in app stores).

-console output,
-take user input of n and create a board n^2
-generates all random letters.
-board can rotate 90 degrees at a time and refactor the board with the correct letters.

This is to be simple.

I have imagined what the program is supposed to do and I asked myself what does this program look like. What type of methods? What should it do with user input?

So to keep it simple, I figured write a test that will take a user input and create a string of that length squared. Is this an ok first test?

so like this...

Junilu Lacar wrote:

Michael Bruce Allen wrote:There is something really bothering me: Double
I do not like using this for the calculator, it seems too defined. I have heard of BigDecimal and BigInteger and thought about making a Number class. There needs to be an easy way to convert these to a string if needed as well. It should be able to take a number as large as I want. I do not know how to test for this though, since adding more too many numbers results in compiling error. This is where I am unsure.

As for the Double type, I need to see code that says Double is not appropriate, code that's in the form of a failing test.

This is where I have a problem testing. If the number is too large it will just have a compiling error. So I am not sure how to test it.
8 years ago
perfectly understood. Thanks.

Why the need of the <T> after Comparable? Comparable is just a interface, so I am curious why we would need a Generic here.
8 years ago
I am taking a course on Generics and it is really good. I am a bit confused on bounded type perameters.

What I am confused about is why you would need to use extends Comparable, because most Classes implement it anyway. I can take any String and do something lik e"abc".compareTo("bcd) and it returns -1. But in a Generic allows to instantiate any class. So here are my questions.

When I extend Comparable on generic in a method like this, does this only allow you to declare or instantiate ONLY objects that already implement Comparable?
If that is true, that would mean that if I extend Comparable on a Generic, it actually LIMITS the classes I can use as the Generic type. Is this correct?

What part is the return type in this "<T extends Comparable<T>> T"?
I believe the T on the right side is the return, but what is it called on the left then?

If my questions do not make sense, just know I am new and rigorously studying and want to learn so that my questions do make sense
8 years ago
No, you are not overwhelming me. I appreciate ALL the insight. The courses are great so far. I have a question on Generics already
I posted it in the Java In General
8 years ago
I am now going through a course on Generics and next on Tree Data Structures and recursion. So I imagine I am going to be way better at understanding how to handle a lot of this calculator code-wise.
8 years ago
I decided to go at the calculator from the beginning today and see what I come up with. I really like the idea that I came up with today.

perform(Operation) can except new Addition(), new Subtraction(), and new Number(double)

I am unsure of the interface name Operation since a number is an operand. So any ideas on a name here?
Also, it seemed after I made the subtraction() method, i refactored constantly. I was unsure if I was supposed to be writing tests. But really it was for the same thing, the tests still worked after the refactor look at recent test below, and this is where I stopped trying to write tests and I just kept refactoring. What do you think of this?

My commits

Number class looks like this...
8 years ago

When looking at that code, is it better to say stack.hasEnoughOperands()?? If this is the case, then the NumberStack class was not such a bad thing. I know you mentioned it recently, but what was your motivation?
8 years ago
I seem to have this disconnect with what the end goal is. What is the end goal? At first it was to read a string and convert to postfix. Then it was a simple rpn calculator. Now I just do not know what.

What I would like to do is, have a solid goal. Perhaps just build a simple RPN calc to get finished. Then ill start another project that has a more advanced goal. Right now if this is just an rpn calculator, then what realy do we have left other than just preempt a few possible bugs?
8 years ago

Stephan van Hulst wrote:
public void setUp() {
this .calculation = new ReversePolishCalculation();
super.calculation = this.calculation;

// Tests specific to ReversePolishCalculation.


What is this super.calculation = this.calculation?
What why the need to call super? What is going on here?
8 years ago

Junilu Lacar wrote:
Edit: Retrospecting on this a little bit, think about how the refactoring to extract a formula to the hasEnoughParameters() method allows you to realize that there is mis-assigned responsibility in your code. Would you have been able to see that otherwise? Does this show how good code leads to even better code? And how bad code can hide problems and that you need to refactor ruthlessly to eliminate bad code and bring out the goodness in the program?

In Aikido, this is part of shugyo

This is awesome and I will take this very seriously from now on.
8 years ago

Junilu Lacar wrote:Next up, separation of concerns/responsibility. Obtaining the operands is a separate concern from using the operands. I'll separate these two a little bit:


The other operation classes would undergo the same transformation. After that, there is still a lot of duplication. This is where I see that a Binary operation is a generalization of all four operation classes. So I extract to a superclass:


There are even more opportunities to make this code cleaner by using some of the language constructs introduced in Java 8 but you can look into that later.

I like this, but what makes this a refactoring focus? What principal? I mean, they were all fine before, they were able to access the abstract method just the same. Now this cleans up all the class files, but why would you have a class within a class (I hope you don't think I am arguing here, I like this a lot, I just want to know the driving force)?
8 years ago

Junilu Lacar wrote:

Michael Bruce Allen wrote:Well, I did some searching around and learned of another way to do this. I like this way much better because it is more clear.

The thing is, you didn't really need to look anywhere outside for that. It was right there in the code. But I guess that recognition comes with experience.[/Quot]

Believe me man, I would have had to ask lots of questions before figuring this out. I didn't even really understand what an abstract method was until now.

Junilu Lacar wrote:
You took a distracting detour in making that method take a stack and two doubles. I guess that can happen though. I would have reverted when I saw how ugly it was instead of forging ahead from there. I'm trying to follow your commits and it seems you jumped the gun there somewhere and missed out on a few critical small steps in refactoring. The end result is almost the same but in this case, the means is just as important as the end.
I immediately see a pattern repeated in this code. A pattern indicates that there is an opportunity to generalize by extracting similarities and parameterizing differences. The first thing I see is that formula, stack.size() > 1.
I ask "What does that formula mean? What is the essence of it?" -- Answer: "I need two operands to perform this operation, so I'm checking that there are at least two operands available to pop from the stack."

Within my temp branch the other day, I did this very thing. I called it stackHasEnough() lol

I remembered doing this before, but I felt I didnt like the code. One thing I did not realize is the importance of code clarity. I thought I understood, but because I wanted to change this, I never refactored it (this time), If I would have just renamed it, I might have gotten a better idea.

8 years ago
Just testing a bit here. https://github.com/CodeAmend/calculator/commits/test

I do not know exactly how to do this. I am getting confused quickly
am I at all on the right track?

I am trying to use a UnaryOperator I made but the if(stack.size() > 1) in the perform method in Calculator class is killing it.
8 years ago