views:

89

answers:

2

I asked my question and got two answers one is piece of code and the other one is to use a library/module.

I am wondering what is better to use. Does it actually matter? Is there any difference in speed, code update or in any other way?

in my case the code is only a loop with 2 lines... My questions is more in general from somebody who is learning ruby and to write nice code

+7  A: 

There might be reasons for either way. From the top of my head, a library might:

  • have had more thought go into it, thereby ensuring it handles corner cases etc. better
  • have been optimized and bugfixed for a long time, making it fast and stable

But it might also:

  • introduce dependencies, complicating deployment
  • contain the solution for a much larger problem, introducing code and bugs you don't need or want

There are surely other considerations as well, but anyway the answer is "it depends". :)

Edit: If the library in question is the standard library, you should of course use it.

calmh
+1 - dependencies may include licensing issues
Stephen C
A: 

If the library does what you need it to do, and is well tested, why would you rewrite the code? I try to always avoid wasting time solving solved problems, unless I'm explicitly trying to learn, or think the solution contains major problems.

floyd