Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Why I don't use Ruby.

Reply
Thread Tools

Why I don't use Ruby.

 
 
Sean Russell
Guest
Posts: n/a
 
      07-10-2004
"Sean O'Dell" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> You can modify values, as long as the value isn't a global (stateful data).
> The key is that the function has to represent the modification, so that when
> you call it with a given set of values, it always does the same thing.


Sean, scope has nothing to do with this. It has to do with state,
within or without of any given scope. If you have a "variable" --
some alias to a value -- and you change it, even within a limited
scope, you've changed state. Re-assignments are not allowed in pure
functional programming languages.

--- SER
 
Reply With Quote
 
 
 
 
Sean Russell
Guest
Posts: n/a
 
      07-10-2004
Martin DeMello <(E-Mail Removed)> wrote in message news:<2DLHc.994640$Pk3.653188@pd7tw1no>...
> I'd say that the difference between a function and a method is that a
> method has a distinguished argument, 'this', *within whose scope it
> runs*. It's not a matter of Obj knowing about foo, or foo knowing about
> Obj, it's a matter of Obj defining its own personal scope within which
> foo is run.


I'd agree with this, although this is usually more of an
implementation than a paradigmatic distinction. OO defines methods as
messages sent to objects.

--- SER
 
Reply With Quote
 
 
 
 
Sean Russell
Guest
Posts: n/a
 
      07-10-2004
Mikael Brockman <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> To resist succumbing to Layne's law, I'll accept your definition.


Wow. That was a reference I had to look up.

> So I'd say Ruby is a mostly-object-but-also-functional language. But if
> one wants to write Scheme code in Ruby, one is unstoppable. One can
> even make it look mostly like regular Ruby code, as long as one *thinks*
> functionally.


I still don't see how you come to this conclusion. Ruby makes heavy
use of side effects, and I'd still suggest that it would be difficult
to program functionally in Ruby, using either NIST's or
comp.lang.functional's definition of a functional programming
language.

Out of curiosity, have you programmed functionally in Ruby, or are we
discussing abstracts here? I've written a lot of what could be
classified as functional programs in Ruby, but they've exclusively
been one-liners from the command line, where I'd normally have used
sed or awk. Any Ruby program I've ever written that grew to more than
a couple of lines (and even many of the one-liners) introduced
side-effects -- accumulators, etc -- which are violate the functional
programming paradigm. I'm just curious if you've done much of this.

> > They're operations on a primitive: a list. A list isn't an object in
> > the OO sense. You can call it an object, but it has no behavior, and
> > it knows nothing about car and cdr.

>
> It does have behavior. When I car it, it gives me its first element;


The list doesn't give you its first element. car discovers the first
element of the list. Saying that a list gives you the first element
when you car it is like saying that a painting gives me meaning when I
look at it. The painting is ignorant about whether or not it is being
observed. And if you take this discussion in a metaphysical
direction, then I'm not playing any more.

--- SER
 
Reply With Quote
 
Sean O'Dell
Guest
Posts: n/a
 
      07-10-2004
On Saturday 10 July 2004 11:57, Sean Russell wrote:
> "Sean O'Dell" <(E-Mail Removed)> wrote in message
> news:<(E-Mail Removed)>...
>
> > You can modify values, as long as the value isn't a global (stateful
> > data). The key is that the function has to represent the modification, so
> > that when you call it with a given set of values, it always does the same
> > thing.

>
> Sean, scope has nothing to do with this. It has to do with state,
> within or without of any given scope. If you have a "variable" --
> some alias to a value -- and you change it, even within a limited
> scope, you've changed state. Re-assignments are not allowed in pure
> functional programming languages.


You're right, not in the strictest sense of the term. But there are two
things you do as a programmer: program in the language and add to the
language. If a functional programming language lets you write your own
functions, so long as you don't make use of global/stateful variables so your
functions always return the same value in response to parameters passed, no
matter how many times it is called or when, to the outside world, to the
programmers calling your function, it makes no difference if you used
variables within the scope of your function or not. Your function behaves
predictably, and it fits well into an existing library of functions in a
"pure" functional language.

Do you see what I mean? You can allow local variables within the scope of a
function, and to the outside world, the function has broken no rules. So
long as it returns the same value always in response to a given set of
parameter values, no one using the function can tell that it has broken a
rule, and it doesn't affect the structure of the code.

Here's a question: are "pure" functional programming languages implemented
according to their own rules? Internally, do they also never use variables?
My guess is: no, or almost never. They break the rules internally to provide
an interface that adheres to the rules. In my opinion, a "pure" functional
language would allow you to develop your own functions and use local
variables so long as your functions interacted predictably with the outside
world.

It wouldn't be a "pure" functional language, but I would still call it a
functional language.

Sean O'Dell


 
Reply With Quote
 
Keith P Hodges
Guest
Posts: n/a
 
      07-11-2004
All,

Could anyone help me I need to host a simple ruby cgi script (for my
daughters blog) and I dont have a machine permanently online. The
script simple takes two rrss feeds and munges the output into
something readable.

many thanks in advance

Keith


 
Reply With Quote
 
Sean Russell
Guest
Posts: n/a
 
      07-11-2004
Mikael Brockman <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> > You may think it is poor, but it is about the *only* hard definition
> > of a functional language that exists. Yes, most "functional"

....
> To resist succumbing to Layne's law, I'll accept your definition.


Hey, I got to thinking about this... is it an example of Layne's law
when you are quoting authoritative sources about the definition of a
word? Is that "arguing" about the definition of a word? For example,
if I claimed that an Apple was a tiny blue fruit that grows on small
bushes, would you be succumbing to Layne's law to quote me the Oxford
English Dictionary's definition of an Apple?

--- SER
 
Reply With Quote
 
Mikael Brockman
Guest
Posts: n/a
 
      07-11-2004
http://www.velocityreviews.com/forums/(E-Mail Removed) (Sean Russell) writes:

> Mikael Brockman <(E-Mail Removed)> wrote in message
> news:<(E-Mail Removed)>...
>> So I'd say Ruby is a mostly-object-but-also-functional language. But
>> if one wants to write Scheme code in Ruby, one is unstoppable. One
>> can even make it look mostly like regular Ruby code, as long as one
>> *thinks* functionally.

>
> I still don't see how you come to this conclusion. Ruby makes heavy
> use of side effects, and I'd still suggest that it would be difficult
> to program functionally in Ruby, using either NIST's or
> comp.lang.functional's definition of a functional programming
> language.


I agree that it's difficult to program functionally in Ruby according to
those definitions. I also think it's difficult to do so with Scheme.
The only people I know that actually program purely functionally are my
Haskell friends, and even they resort to unsafePerformIO occasionally.

Scheme has some features to make it easier, like tail call optimization,
but I don't think using tail recursion instead of looping matters much
in the large scale of things. In fact, I don't think it matters much at
all. When I write tail-recursive loops in functional languages, the
paradigm in my head tends to be imperative.

> Out of curiosity, have you programmed functionally in Ruby, or are we
> discussing abstracts here? I've written a lot of what could be
> classified as functional programs in Ruby, but they've exclusively
> been one-liners from the command line, where I'd normally have used
> sed or awk. Any Ruby program I've ever written that grew to more than
> a couple of lines (and even many of the one-liners) introduced
> side-effects -- accumulators, etc -- which violate the functional
> programming paradigm. I'm just curious if you've done much of this.


Nope, I haven't. I try to follow the grain of the language as much as
possible, so with Ruby, I tend to write imperative object-oriented
programs. Of course, many habits from my functional experience follow
me: defining new control structures, using heavy abstraction, etc.

>> > They're operations on a primitive: a list. A list isn't an object in
>> > the OO sense. You can call it an object, but it has no behavior, and
>> > it knows nothing about car and cdr.

>>
>> It does have behavior. When I car it, it gives me its first element;

>
> The list doesn't give you its first element. car discovers the first
> element of the list. Saying that a list gives you the first element
> when you car it is like saying that a painting gives me meaning when I
> look at it. The painting is ignorant about whether or not it is being
> observed. And if you take this discussion in a metaphysical
> direction, then I'm not playing any more.


That's only true if you think of the data and its operations as
completely separate entities. Doing so isn't easily justifiable in
Ruby, since they're defined in their own little indented scope.

If I were to design in Scheme, say, a library for mutable queues, I
would think of the data and its operations as an object, just like I do
when I'm programming in an object-oriented language. Real functional
hackers probably think differently.

mikael



 
Reply With Quote
 
Sean Russell
Guest
Posts: n/a
 
      07-12-2004
Mikael Brockman <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> I agree that it's difficult to program functionally in Ruby according to
> those definitions. I also think it's difficult to do so with Scheme.


There is quite a debate about how much of a functional language Scheme
is. I've heard it referred to as "relatively functional", and heard
it said that Scheme "encourages" functional programming. This isn't a
trivial point; there are serious reasons for enforcing purity in
functional programming, unlike the common reasons for enforcing purity
in OO languages which often are based on aesthetic reasons. Purely
functional are verifiable and thread safe, which can be important.

However, I know that some Schemers get touchy about this point, so I
don't want to get into an argument about it. Suffice to say that
there's enough of a debate among people smarter than I about the
purity of Scheme to give that opinion some validity.

> Nope, I haven't. I try to follow the grain of the language as much as
> possible, so with Ruby, I tend to write imperative object-oriented
> programs. Of course, many habits from my functional experience follow
> me: defining new control structures, using heavy abstraction, etc.


In my experience, many of my programs in Ruby start out being
functional. Just a line or two return results per line of a file.
Then they grow to be imperative, and I'm defining functions. The
final stage is when they metamorphose into true OO programs; I wrap up
the functions in reusable Objects, and wrap the application up into a
single (or a very few) instantiations and method invocations. This is
one of the reasons why I like Ruby so much. Even though it is more OO
than Java, Java is more of a pain because you have to start out in the
OO paradigm, even when you don't need it.

Real functional programming is also nice, though, and encourages you
to think about the data you're working with. I worked on one
data-driven project where the "specification" ended up looking like a
bunch of Haskell function declarations, so that's what I chose to
write the application in. It was, probably, the most robust
application I've ever written.

> That's only true if you think of the data and its operations as
> completely separate entities. Doing so isn't easily justifiable in
> Ruby, since they're defined in their own little indented scope.


Right, but I think that's the point in a purely functional language.
You have data, and you have functions that operate on that data. The
functions are meaningless without the data -- they are defined in
*terms* of the data, so there's dependancy there -- however, the data
is ignorant of the functions, and are *not* defined in terms of the
functions that operate on it, unlike an OO language where an object is
defined by its state AND the messages that can be sent to the object.

> If I were to design in Scheme, say, a library for mutable queues, I
> would think of the data and its operations as an object, just like I do
> when I'm programming in an object-oriented language. Real functional
> hackers probably think differently.


Yes, I think they do. You yourself said that you're an imperative
programmer. I am too, because I learned programming with Basic, 6502
Assembly, and C. I believe the OO paradigm is a bit overblown. I
have noticed that people who learned programming with a functional
language *do* think differently about the problems they solve, and
they come up with different solutions. Imperative and OO programmers
almost never use tail recursion; FPers use it almost exclusively.
There's a much closer relationship between FP, Math and set theory
than there is between IP and OO and those fields.

--- SER
 
Reply With Quote
 
Tom Copeland
Guest
Posts: n/a
 
      07-12-2004
On Mon, 2004-07-12 at 14:27, Sean Russell wrote:
> In my experience, many of my programs in Ruby start out being
> functional. Just a line or two return results per line of a file.
> Then they grow to be imperative, and I'm defining functions. The
> final stage is when they metamorphose into true OO programs; I wrap up
> the functions in reusable Objects, and wrap the application up into a
> single (or a very few) instantiations and method invocations. This is
> one of the reasons why I like Ruby so much. Even though it is more OO
> than Java, Java is more of a pain because you have to start out in the
> OO paradigm, even when you don't need it.


Very nicely put. I find the same thing happening - first I'll be
backticking psql to run a PostgreSQL query, then I make a function to
wrap it in "psql -c", then I make a little object to do a dry run before
actually running the query. And this transition only takes 5 minutes or
so, and it's not painful to do since I'm not continually recompiling and
such. Just VIM (with VIM/Ruby, of course) and a command line. Good
times!

tom



 
Reply With Quote
 
Mikael Brockman
Guest
Posts: n/a
 
      07-12-2004
(E-Mail Removed) (Sean Russell) writes:

> Mikael Brockman <(E-Mail Removed)> wrote in message
> news:<(E-Mail Removed)>...
>> I agree that it's difficult to program functionally in Ruby according
>> to those definitions. I also think it's difficult to do so with
>> Scheme.

>
> There is quite a debate about how much of a functional language Scheme
> is. I've heard it referred to as "relatively functional", and heard
> it said that Scheme "encourages" functional programming. This isn't a
> trivial point; there are serious reasons for enforcing purity in
> functional programming, unlike the common reasons for enforcing purity
> in OO languages which often are based on aesthetic reasons. Purely
> functional are verifiable and thread safe, which can be important.
>
> However, I know that some Schemers get touchy about this point, so I
> don't want to get into an argument about it. Suffice to say that
> there's enough of a debate among people smarter than I about the
> purity of Scheme to give that opinion some validity.


I agree. Haskell makes it easier to write purely functional programs.
Still, it's definitely possible to write mostly functional programs in
Scheme. I think it's possible to write mostly functional programs in
Ruby, too, though probably to a lesser degree.

>> Nope, I haven't. I try to follow the grain of the language as much as
>> possible, so with Ruby, I tend to write imperative object-oriented
>> programs. Of course, many habits from my functional experience follow
>> me: defining new control structures, using heavy abstraction, etc.

>
> In my experience, many of my programs in Ruby start out being
> functional. Just a line or two return results per line of a file.
> Then they grow to be imperative, and I'm defining functions. The
> final stage is when they metamorphose into true OO programs; I wrap up
> the functions in reusable Objects, and wrap the application up into a
> single (or a very few) instantiations and method invocations. This is
> one of the reasons why I like Ruby so much. Even though it is more OO
> than Java, Java is more of a pain because you have to start out in the
> OO paradigm, even when you don't need it.
>
> Real functional programming is also nice, though, and encourages you
> to think about the data you're working with. I worked on one
> data-driven project where the "specification" ended up looking like a
> bunch of Haskell function declarations, so that's what I chose to
> write the application in. It was, probably, the most robust
> application I've ever written.


I've had some love affairs with Haskell, too. I wrote a client for a
Napster-like file sharing service called Direct Connect, which certainly
isn't Haskell's target market, and it was beautiful. Algebraically
manipulating I/O actions is really pleasant, and monadic parser
combinators (Parsec, in my case) were awesome for parsing the wire
protocol. That parser was probably the most robust parser I've ever
written.

One of the most memorable things was writing this Scheme macro:

| (define-macro (loop action)
| (letrec ((f (lambda ()
| (action)
| (f))))
| (f)))

as this Haskell:

| loop action = action >> loop action

and algebraically simplifying it to simply

| loop = fix (>>)

Another beautiful thing was this:

| downloadFile socket size fd = write fd (read socket size)

Which, thanks to lazy evaluation, intersperses the reads and the
writes. If I wanted it to report its progress to, say, a progress bar,
I could just insert another function in the middle of the pipeline.

Damn you, Sean. You got me in the mood for writing Haskell.

>> That's only true if you think of the data and its operations as
>> completely separate entities. Doing so isn't easily justifiable in
>> Ruby, since they're defined in their own little indented scope.

>
> Right, but I think that's the point in a purely functional language.


Yup. That doesn't mean I have to obey.

Thanks for a nice discussion, Sean.

mikael



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
Cisco 2611 and Cisco 1721 : Why , why , why ????? sam@nospam.org Cisco 10 05-01-2005 08:49 AM
Why, why, why??? =?Utf-8?B?VGltOjouLg==?= ASP .Net 6 01-27-2005 03:35 PM
Why Why Why You HAVE NO IDEA MCSE 31 04-24-2004 06:40 PM



Advertisments