Challenge: How would you start this problem? 24
On Thursday, we’re holding our first Coding Dojo at the recently opened OkC CoCo. This isn’t the first Coding Dojo to happen in Oklahoma City. Some time back, Dave Nicolette held a Randori with a Fishbowl at the OkC Java User’s Group, and that’s the format I’ll be using for this problem. It was a blast then and I’m hoping it’ll be the same this time around.
This first DoJo is with C#, though I hope we manage to use several languages over time. I’d like to sneak in Smalltalk as soon as we have enough of a critical mass so we don’t lose people. I also plan to slowly introduce BDD (maybe not so slowly, who knows – depends on the group).
The recent refactoring exercises (here and here), they come from this problem. We’ll be starting from scratch, so you can probably imagine that those refactoring examples are not going to come up right away (actually probably not at all given the time).
So your challenge this time is not one of refactoring but rather one of an initial value problem. Given the problem statement, how would you go about starting it? I’m assuming TDD, do you make that same assumption? If so, what’s your first test? Your first few tests? What features do you try to tackle first? What questions do you ask yourself about the problem?
I’ve used this problem several times and it’s a great problem to practice many things including:- Test Driven Development
- refactoring (lower case r deliberate – can you guess why?)
- Refactoring to Design Patterns
- Most of the SOLID principles
Anyway, how would you go about starting this problem? Or better yet, give it a try and post your first few tests (in the order you create them).
I’ll be interested in seeing how people start and I’ll compare it to what I’ve done (hint, I use this as a class-driven thing, so I’m pretty flexible on how to start it).
p.s. As a result of studying the manual for my HP 32SII, I have a much better understanding of just how its stack works. I have a EE and CS background, so the stack implementation makes sense, but I left some of its details out of the problem.
When creating a new class / method, i usually write the simplest test that is possible, so that “test fails” means “does not compile” and the test passes after some trivial coding. So my first test was something like this:
Next i tried to get some values into the registers. All the tests first used ints instead of BigDecimal and char, but i refactored later to these types…
After that i started with class OperandStack and tests like these:
These are the first of currently 27 tests beeing now at the point where the second exercise starts.
Sorry for being a little off topic, but isn’t it funny that HP were able to market RPN as a feature, while it’s a way to make the calculator’s design simpler? A typical calculator parses the formula the user enters to create a tree and then executes it on a stack. HP calculators skipped the parsing step and required the user to work directly on the stack. It’s like RPN is the assembly language of calculators. :-)
Martin Vilcans wrote:
Maybe. It IS easier to build (in circuits or software) for the reason you mention. However, RPN has been around since 1920, so I’m not sure if their reason was to make something that was easier to build (maybe) or something that is easier to use (well it is for me, but I love vi as well).
According to the hp museum site, they decided on RPN because of its ability to handle more complex expressions. Given the time-frame (1968), and the weigh (40 pounds), going with a simpler way to represent expressions was a good idea!
And personally, I have a much better time using RPN than infix calculators.
The core of the problem revolves around manipulating the operand stack. Looking at the worked examples in the problem definition, the simplest assertion you can make is that when popping an empty stack, the returned value should be 0, so that is where I started from. The test is at http://randomcode.net.nz/2009/06/22/yet-another-bdd-extension-for-xunit/ as I used it to drive out a BDD style extension for xUnit.
@Test public void ??? shouldContainZeroInEachRegisterAfterCreation() throws Exception { RpnCalculator calc = new RpnCalculator(); assertEquals ??? ?? (BigDecimal.ZERO, calc.getX()); assertEquals(BigDecimal.ZERO, calc.getY()); assertEquals(BigDecimal.ZERO, calc.getZ()); assertEquals(BigDecimal.ZERO, calc.getT());
Given the time-frame (1968), and the weigh (40 pounds), going with a simpler way to represent expressions was a good idea!
what is wrong with me
The Christmas time is comming, and the most desire present i want to get, is the latest white iphone 4, can i get one? Tell you after Xmas.
Hints for choosing the right windsurfing vacation
The importance of Mr16 light bulbs in home
Classic exposition, I have also mentioned it in my blog article. But it is a pity that almost no friend discussed it with me. I am very happy to see your article.
nice.
internette görüntülü olarak okey oyunu oyna, gerçek kisilerle tanis, turnuva heyecanini yasa.
I am not significantly into reading, but somehow I obtained to proceed through numerous content material articles on your very own blog. Its remarkable how intriguing it truly is for me to research out you very often.Just proceed through Stephen’s blog…
Designer replica women LV backpacks free shipping for wholesale
When it comes to feather dress, what appears in your mind? Which kind brand of down jacket do you like prefer? Though there are many down jackets for you to choose from, on the word, which one you really enjoy? I want to say that canada goose coats is really your best choice. I believe you can’t agree with me any more. When you take the quality into consideration, you will find that it is superior to any other kind of coat. Besides, discount canada goose jackets is a world well-known brand, which has gained high reputation in the world, which has accepted by our customers and some organization. Because of its high quality, some of our loyal customers have promoted it to the people around them. In their opinion, it is good to informing others to know it. Recently, Canada Goose Trillium Parka is on hot sale. What I have to inform you is that all the products there are made by hand, so they are elaborative and elegant enough. It is really beautiful once you dress in. So, if you are a lovely girl or woman, go to the store to buy one for you. You will appreciate it that you have such a coat.In addition, they also have any other products like canada goose Gloves and canada goose jacket supplier.Hope your will like its!
Slewing bearing called slewing ring bearings, is a comprehensive load to bear a large bearing, can bear large axial, radial load and overturning moment. http://www.1stbearing.com
http://www.spyderjackets-outlet.net
Create the ultimate Home Theater Projector with a digital projector from InFocus in vvme. Then came the announcement on July 28-the industry’s first LCD-based 3D 1080p lcd projector was on its way. If you want an LCD projector for your beautiful LCD Projector Screen, you should take a look at the choices available at Go vvme. Shop and compare InFocus Meeting Room Projector and find supplies for your InFocus.
It is really a good example that most of the programmer should think about this. If we want to do much better for the code. I should understand it. right? You are very good at this and show us good coding idea.
MANYADEAL.COM is professional for Ballast for HID? The kit comes complete with a Electronic HID Ballast, and it is Plug-n-Play. All necessary hardware for installation is included. Combined HID Slim Ballast and starter unit for better performance and easy installation for 55W Ballast.
Challenge: How would you start this problem? 19 good post13
Challenge: How would you start this problem? 20 hoo,good article!!I like the post!146
One of the most popular types of jewelry swarovski cube beads today that many people enjoy wearing sister bracelet are silver rings. Silver in its natural cheap bangle bracelets form is harder than gold. It is still swarovski necklaces considered too soft for use in fine jewelry.
Our life is modifying promptly with the ralph lauren sale of the society. The modification is mostly come seal the fashionable goods according to the modification in fashion Pas Cher Women’s Ralph Lauren sale Vuitton Sacs. Well, otherwise, it Men’s Ralph Lauren shirts differs in many aspects due to ones gravy style. The gravy style broadly articulating demonstrates the personality and individuality of people.
http://www.outfitscosplay.com/cosplay-catalog/burst-angel-cosplay Deluxe Burst Angel Cosplay Costumes for Sale.Find your favorite characters and cosplay outfits from all the popular anime and games.