From: Alex Date: 2009-12-30T02:02:20+09:00 Subject: Re: Creating my own method for sorting an array --0015175cfad6f89ba1047be0fb03 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Tue, Dec 29, 2009 at 11:47 AM, Marnen Laibow-Koser wr= ote: > Robert Klemme wrote: > > 2009/12/29 Marnen Laibow-Koser : > >> Joe User wrote: > > > > Somehow I believe I heard that name somewhere already... :-) > > > >> In Ruby, this is frankly stupid. =EF=BF=BDNo Ruby programmer would do = this in > >> any other way than by using the .sort method, providing a comparator > >> block, and letting Ruby take care of the bookkeeping. > > > > I don't see how that is a stupid exercise. I reckon this is not > > mainly an exercise to introduce sorting but rather to get accustomed > > with class Array and probably algorithms in general. > > Then they probably should have picked a better example, or at least > explained common sort algorithms before turning you loose v > > > > >>> and compare it to the rest of the elements and if it's the smallest, > >>> push it onto the sorted list and push the remaining elements onto the > >>> unsorted. =EF=BF=BDThen call the method again with the sorted and uns= orted > >>> lists. That's the recursion part. > >> > >> That would certainly be a way of doing it. =EF=BF=BDHave you written a= utomated > >> tests to encapsulate these requirements? =EF=BF=BDIf not, do so before= writing > >> another line of code. > > > > Maybe it's a bit early to start writing tests when someone is starting > > to learn to program... > > No. Testing is a fundamental part of programming, though it is often > neglected. > Way to kill the enjoyment of programming, dude. This guy is a new programmer, and you're talking to him about tests? When I started out, I certainly didn't care a single bit (GASP!) about how well-written my programs were, or if they followed good design patterns and whatnot. Exposing him to this stuff is just going to make it even more confusing tha= n it needs to be. > > > When I started learning software development I > > certainly got more kick out of a working program than a working unit > > test before hand. :-) > > It's the working test beforehand that lets you know when you have a > working program. It really is best to write the tests first. Read up > on test-first development and apply it religiously -- it really is worth > it. > Yeah, the way I tell if I have a working program is (generally) to run it. True, a new programmer could write a test to ensure that his "hello world" program works right, but isn't that a little silly? > > > > >>> I guess the problem I'm having is knowing how to check each element o= f > >>> the unsorted array against the other elements. =EF=BF=BDI can check i= f the > >>> current element is smaller than the other elements using < (less than= ) > >>> but that doesn't mean it's the smallest in the whole array. > >> > >> Sure it does. =EF=BF=BD(Of course, this is quite computationally ineff= icient.) > > > > As I said, I don't believe this is the point of the exercise. > > > > Perhaps not. And it may be a good exercise for learning algorithmic > concepts. But really, it teaches you nothing good about writing > idiomatic, efficient Ruby. > > Best, > -- > Marnen Laibow-Koser > http://www.marnen.org > marnen@marnen.org > -- > Posted via http://www.ruby-forum.com/. > > Seriously, guys... He's trying to write a sort algorithm. I wrote many of them when I was starting out, trying to figure out what was going on. What'= s the problem here? Let's give him some guidance, not talk about how dumb it is to write that, because no one would use it in "the real world." You know what else no one ever used in the real world? That slot machine program I first wrote. All those "hello world" programs I wrote. All the algorithms I re-implemented, trying to learn how they worked. Does the fact that no one will ever use them make them worthless? Or maybe the experience I gained from writing all that worthless code made me a better programmer. Alex --0015175cfad6f89ba1047be0fb03--