[#2367] Standard libraries — Dave Thomas <dave@...>

From ruby-dev summary:

60 messages 2004/02/11

[#2397] PATCH: deprecate cgi-lib, getopts, importenv, parsearg from standard library — Gavin Sinclair <gsinclair@...>

Index: cgi-lib.rb

15 messages 2004/02/12

[#2465] PATCH: OpenStruct#initialize to yield self — Gavin Sinclair <gsinclair@...>

This is a common approach I use to object initialization; I don't know

24 messages 2004/02/19

Re: rb_io_puts is strange

From: Elliott Hughes <ehughes@...>
Date: 2004-02-04 16:17:39 UTC
List: ruby-core #2342
> "bad" is a strong word.  How bad do you think?

Some of the things I don't like are, in no particular order:

 * It has the same name as C's puts, but doesn't have the same
   behavior as C's puts.

 * It isn't to print what Java's println is to Java's print. I
   understand this kind of printing duality, because it's in so
   many languages. As far as I know, Ruby's print/puts
   relationship is unique. It's certainly unusual.

 * It implements something I've never wanted, and can't -- to
   be honest -- understand the need for. At the same time, it
   looks like something I do need and use a lot. And *mostly*,
   it works like C's puts.

 * It's always going to examine the last character of my string;
   if I needed that, I could implement it for those cases where
   it's what I want.

 * It's complicated. Not as bad as Perl's split function[1], sure,
   but far more complicated than it ought to be. I find Ruby's
   great in terms of putting things where I'd expect to find
   them, but I'm often caught out by the behavior of the methods
   I find. (The biggest example for me is the way ! methods tend
   to return nil if they haven't changed anything. Presumably
   they're intended to be used in if statements or something,
   but it's weird that they either behave like their non-!
   counterpart, or return nil.)

> It's little bit complex than the simplest, I know, but I don't
> consider it bad.  I just wanted "puts" to ensure string ends with a
> newline.

Maybe it's a mindset thing, but to me, a program that doesn't know whether a
string already ends in a newline is broken. I see a difference with things
like join, where you don't want a separator on the end, but newlines aren't
like that (in anything I've ever done, at least).

> If you want to put a newline at the end, you just need to
> call print str, "\n".

Yeah, this is roughly what I've search-and-replaced my Ruby scripts with.
(I've actually used print("...\n") because the Perl-like use of a , without
parentheses makes me nervous.)

It's unfortunate, I think, that Ruby is different enough from familiar
things to need treating differently, yet superficially similar enough to
fool me time and time again. (The other problem with yesterday's script was
that I kept thinking that '/' in Ruby means the same as '/' in the C family,
and not the same as "/", and that I need to use ?/ instead.)

 --elliott

_____
1. Learning the full truth about Perl's split was enough to make me vow
never to write a new script in that language. I'd always had this feeling of
walking across thin ice, but now I'd looked down and seen just how deep the
lake is, and just how cracked the ice.


*********************************************************************
This e-mail and any attachment is confidential. It may only be read, copied and used by the intended recipient(s). If you are not the intended recipient(s), you may not copy, use, distribute, forward, store or disclose this e-mail or any attachment. If you are not the intended recipient(s) or have otherwise received this e-mail in error, you should destroy it and any attachment and notify the sender by reply e-mail or send a message to sysadmin@bluearc.com
*********************************************************************


In This Thread

Prev Next