Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Bug in code, need an outside perspective - cannot figure it out.

 
Jeff Yan
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey, basically i have programmed a nextFit algorithm that is a cable ordering system. the user orders a length and type of cable and the program processes the order cutting the cable that is required at the required length. the orders are generated using a seperate class and are passed as a parameter to the algorithm to be processed.
i have this code working; however - it works only for the first run of each type of cable.

e.g.

-programme starts
-one order gets processed for 28m of aluminium,
-there is no aluminium in the store so more is ordered (a random integer between 100 and 200 used to represent the length ordered)
-the 28m gets taken of the ordered aluminium, say 190m was ordered from the store, the remaining aluminium after this has been processed is 168m

then after this one run, when another order of aluminium is processed, it does not take the value off the remaining aluminium variable.

i dont know if this is something to do with using the same object to process all the data?? but it should work. i cannot see the bug anywhere and have been looking for hours to no avail. the code for the class with the bug is below. any help much appreciated.

 
Jeff Yan
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
anybody?
 
D. Ogranos
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You only check if the orderlength is greater than the remaining aluminium length. But what is if it is NOT greater?
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff Yan wrote:anybody?

PatienceIsAVirtue.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff Yan wrote:anybody?

You waited like 30 minutes--not long enough--so you get code comments.

- The use of non-standard Java naming conventions will slow down some Java developers (like me) as they read over your code: in general, member variables should be named starting with a lower-case letter.
- Access should always be specified instead of using the default.
- The initialization you *think* you doing in your constructor isn't; those are local to the constructor.
- The class is a jumble of concerns and functionality--not necessarily an issue, but even something this short becomes more difficult than necessary to understand and debug.
- Along with that, make sure that duplicated code is identified and removed as early in the process as possible.
- Notably, the block of code for ordering copper and ordering aluminium are essentially identical: in this case, that indicates something funky in the design process.
- Note that OrderProcess is recursive: I can think of no good reason to make it so.
- Be wary of making things instance variables that don't need to be: relying on side effects can make debugging... troublesome.
- You spelled aluminum wrong. (Okay, I'm kidding with that one
 
Jeff Yan
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry for the impatience, i was getting stressed about it! and the code is just a basic outline it needs refinement, but the first answer hit the nail on the head, so thank you for that. problem resolved.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic