Homework 5.6

Homework 5.6 was asking me to re factor the code in functions hashtableupdate and hashtablelookup. When I go to look at this functions they are already 6 lines of code or less and contain no while loops and the only thing that I could re factor is a for loop but that would not really save any lines of code.

I guess I'm a little confused on what the question wants me to do.

asked 27 Mar '12, 00:54

Alex%20Merritt's gravatar image

Alex Merritt
3316
accept rate: 0%

edited 27 Mar '12, 00:55

pmoriarty's gravatar image

pmoriarty
5.5k52377


2 Answers:
link

answered 27 Mar '12, 00:56

pmoriarty's gravatar image

pmoriarty
5.5k52377

If you look at the two functions they mention you hopefully see duplicate code in both of them. The exercise is wanting you to eliminate the duplicate code from those two functions by creating a new function that encapsulates that task that's being duplicated and have the functions that have duplicate code call your new function to obtain the information it needs to perform.

Hit this and search for 'Extract Method' for a bit more. To be honest it's not much more but you may enjoy reading about other refactoring techniques.

link

answered 27 Mar '12, 00:57

David%20Smith's gravatar image

David Smith
1.2k61236

edited 27 Mar '12, 01:00

Your answer
Question text:

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×15,296
×1,718
×43
×8

Asked: 27 Mar '12, 00:54

Seen: 311 times

Last updated: 27 Mar '12, 01:00