ALT Linux Community general discussions
 help / color / mirror / Atom feed
From: Henri Bourbon <useperl@fastmail.fm>
To: community@altlinux.ru
Subject: [Comm] Ruby -- ÂÒÉÌÌÉÁÎÔ × ÍÉÒÅ ÓËÒÉÐÔÏ×ÙÈ ÑÚÙËÏ×!
Date: Tue, 12 Nov 2002 00:57:17 +0300
Message-ID: <15058006468.20021112005717@fastmail.fm> (raw)

On 9 Nov 2002  22:57, Ilya Palagin wrote:

> в целях популяризации ruby - вот-с :-)

Оооооо! Как я вижу, Ruby -- просто бриллиант в мире скриптовых языков! Я
перевел  вашу  программу,  г-н Палагин, на язык Coal, чья отстойность, о
которой  так  много говорили большевики, становится совершенно очевидной
при  взгляде  на  обе  программы (на ruby и coal), помещенные рядом, в 2
колонки:

#!/usr/bin/ruby -w                         | #!/usr/bin/perl -w
content = Hash.new                         |
File.open(ARGV[0], "r") do |f|             | my @lines = <>;
  cnt = 0                                  |
  while (line = f.gets)                    |
    content[cnt] = line; cnt += 1          |
  end                                      |
  content.keys.each do |n|                 | for (0..@lines-1) {
    m = rand(cnt)                          |   my $r = int(rand(@lines));
    content[n], content[m] = \             |   @lines[$_, $r] = @lines[$r, $_];
                    content[m], content[n] | }                                 
  end                                      |                                  
end                                        |
content.keys.each { |n|  print content[n]} | print @lines;                     

Примечание:  о  том, что алгоритм перемешивания строк, придуманный вами,
неправилен  (разные  перестановки входных строк имеют разную вероятность
появления на выходе), мы здесь не говорим. О том, что правильный и более
эффективный  (на  1  итерацию  меньше)  алгоритм, точнее, программу, его
реализующую,  любой, бегло читавший Perl FAQ, отыскал бы за 3 минуты, мы
здесь не говорим. О том, что создать вместо массива хэш с ключами в виде
чисел  1..N  может  прийти в голову, по-видимому, только программисту на
Вижуал Барсик, Си Диез или Ruby, мы здесь не говорим.

Говорим же мы здесь о том, насколько более красивой, простой и наглядной
является, например, конструкция

строки.ключи.каждый { |n|  напечатать строки[n]}

по сравнению с

напечатать @строки;

Как справедливо отмечали большевики, одной из наиболее гадких черт языка
Coal  является  то,  что  все  можно  сделать  более,  чем 1-м способом.
Например, может ли не возмущать, что

print @lines;

можно записать как

foreach my $line (@lines) {
  print $line;
}

или, скажем,

print foreach @lines;

?

Ruby. Implementing Visual Basic Traditions since 1995.

---
Я  нигде  не  рисовал  смайликов,  и  может возникнуть ощущение, что все
сказанное я злобно процедил через зубы. Конечно же, нет! В этом постинге
не было почти ни одной серьезной строки, все это стёб чистейшей воды.

                            O    \
                              __  )
                                  )
                            O    /

-- 
HB



             reply	other threads:[~2002-11-11 21:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-11-11 21:57 Henri Bourbon [this message]
2002-11-11 22:40 ` [Comm] Re: [Comm] Ruby -- бриллиант в мире скриптовых языков! Vitaly Lugovsky
2002-11-12  9:25 ` Ilya Palagin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=15058006468.20021112005717@fastmail.fm \
    --to=useperl@fastmail.fm \
    --cc=community@altlinux.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

ALT Linux Community general discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/community/0 community/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 community community/ http://lore.altlinux.org/community \
		mandrake-russian@linuxteam.iplabs.ru community@lists.altlinux.org community@lists.altlinux.ru community@lists.altlinux.com
	public-inbox-index community

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.community


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git