2 Replies - 240 Views - Last Post: 06 December 2011 - 11:26 AM

#1 zedth2  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 121
  • Joined: 14-September 09

Reinvent the wheel?

Posted 05 December 2011 - 09:26 PM

Hello everybody,

I'm just about to finish up my first semester as a CS major and I'm enjoying it very much. The intro programming course I'm about to finish was taught in C. I've read online that some colleges use older languages specifically because they don't come with expansive libraries and the such. My question to all of you professionals and students a like is, is it better to reinvent the wheel while learning all this? For example I've had to do several programs dealing with character arrays in C but instead of using strcpy and strncpy and the lot I wrote my own versions of these functions. Mind you they all work they way there supposed to and didn't cause me to be late on any assignments. So if you're just learning all this techno coding junk do you think its better to try and reinvent whats already there or just use the preexisting functions?

Thanks for the input.

Is This A Good Question/Topic? 0
  • +

Replies To: Reinvent the wheel?

#2 elgose  Icon User is offline

  • D.I.C Head

Reputation: 102
  • View blog
  • Posts: 228
  • Joined: 03-December 09

Re: Reinvent the wheel?

Posted 06 December 2011 - 06:21 AM

I believe it's important that you understand how your tools work. For the sake of knowledge, rewriting functions just so you can say you know how is good. Once you're out there doing things, then you'll want to use the tools given to you (and always continue your learning on your own!). With your understanding of how the tools work, though, you'll know when you need something more or potential pitfalls to look for when debugging.
Was This Post Helpful? 1
  • +
  • -

#3 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon

Reputation: 5439
  • View blog
  • Posts: 8,756
  • Joined: 19-March 11

Re: Reinvent the wheel?

Posted 06 December 2011 - 11:26 AM

I agree with elgose on this. Learning to write the basics is important for two reasons: first, as elgose said, it's a way for you to understand the underlying code that you're using in libraries, and this makes it possible for you to use them better. For example, if you know that an implementation of strlen required you to walk down the length of the string, you might want to memoize that value rather than calling it repeatedly, particularly for a long string. On the other hand, if you know that the value is maintained by the String itself, as in Java, then there would be no point in storing that value. Having implemented these functions yourself lets you know what questions you have to ask about your code, so you can make the right choices straight off.
It's also worth reinventing wheels because you're learning how to write code, and writing these routines is a good way to write some real code that actually does something, and then to compare your solutions to the state of the art. Since these are utility functions, they encapsulate a lot of real problem-solving without distracting you in tedious stuff like building a UI, which means you're focusing on the real problem.

Of course it's almost certain that you're never going to write a red-black tree on the job, but doing it once prepares you for the higher-level stuff that you'll actually be doing.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1