From owner-freebsd-questions@freebsd.org Fri Jul 1 07:57:15 2016 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2383BB8ECD6 for ; Fri, 1 Jul 2016 07:57:15 +0000 (UTC) (envelope-from minaev@gmail.com) Received: from mail-lf0-x233.google.com (mail-lf0-x233.google.com [IPv6:2a00:1450:4010:c07::233]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 8DFDC2148 for ; Fri, 1 Jul 2016 07:57:14 +0000 (UTC) (envelope-from minaev@gmail.com) Received: by mail-lf0-x233.google.com with SMTP id l188so71743693lfe.2 for ; Fri, 01 Jul 2016 00:57:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding; bh=3VYTnccSY3Z/5UKKrbpUGuGFj5IzhM3hVYiQcCtSZSU=; b=xUZzXu2sWCu08O3FpB22Qy8FFStQj1yxx8HsXuTByZ1AMJ7vc1MD4g7ecukrGhiK61 ntNRMRhcnOZAuijXGlNSpOEwhMCWKUf6/jipLfHSnT+YNEdmdIS/NIZBj+4ZyawjRnQR 16byr1aDntpMov1NwaXBQDSnE7AxuMMbgxKMm1g0edkoroe3vG2VBCmRiVVtguEvuF0Q 6W/Dl+vvgBsMlh9UWHkD2d68VbEmPAuXsl+znNsfpZ307ZHu3j21Aib/o5It4y/G5FCR KvVBcvB+6evaAE6rX+T1oypeg+gqUZeeRJxf0wLCYwRaDoaYZxqKvuiwHK3D9o/ZvAJ0 4kaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=3VYTnccSY3Z/5UKKrbpUGuGFj5IzhM3hVYiQcCtSZSU=; b=flBWs8N1/gtD/GuL4ZRbGyaknayXAMvF1iN2eC/OPUXMA6sEJ2VO3wE0kz39KhDHks mSKkQmwfkIn4vpzfJL6q55vpoYBKdyxBdta81nvFR1g33lPue2gJVgb9jCFsbxZmOd1F VeEG0uJp6mhFZEUYd9hoIxFNiJ/712CCLphrAHM6eC1QEeWrq8J4O/NIDgeyixoohNlx IglDDo3e0UpqIdXms5CP1RzE+44Au453mrhSJBcs7hfJcKLO/saRvK3ezZ010XEhsbtM 3cO4EG8dizFejT9oyhyEBObhm6KIc20hUvLsfsuWT6FRDIy9fUDgYaTfkXLG3A8iLHtV 6ouA== X-Gm-Message-State: ALyK8tJAxB1q02nrMszTlL/YZ0wBWtSv4DP6XeeK25yKXaqvrY1AJbZrS/qBaS8/ymUzDw== X-Received: by 10.25.39.78 with SMTP id n75mr6621768lfn.91.1467359832690; Fri, 01 Jul 2016 00:57:12 -0700 (PDT) Received: from [10.18.11.113] ([188.128.94.254]) by smtp.gmail.com with ESMTPSA id e64sm2159397lfe.3.2016.07.01.00.57.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Jul 2016 00:57:11 -0700 (PDT) Subject: Re: "Simple" Languages in FreeBSD To: Allen , freebsd-questions@freebsd.org References: <20160630175243.063e07a7@KoggyBSD.org> From: Dimitri Minaev Message-ID: <57762256.7070106@gmail.com> Date: Fri, 1 Jul 2016 11:57:10 +0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0 MIME-Version: 1.0 In-Reply-To: <20160630175243.063e07a7@KoggyBSD.org> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 01 Jul 2016 07:57:15 -0000 On 07/01/2016 01:52 AM, Allen wrote: > Literally anyone who responds with an opinion, I'm interested. Being > easy to learn for someone who isn't great with Math but does understand > Unix is a plus but not a requirement. I was starting to teach myself > Ruby on a Linux box I was using for a while and Ruby did seem to be > going OK, but a lot of the FreeBSD Books I've bought recommend Perl, > and I've also had just as many reasons from people saying to try > Python, so basically any Language and what reasons would be great. A huge part of my job is automation in UNIX and 99% of it is done in Bash. IMHO, shell is a must for anyone working with UNIX, even though it's not really a programming language in the common sense. About 15 years ago I used Perl often and I remember it as a very natural language very similar to shell, but better. The syntax may sometimes look strange, but most of the time Perl by default does exactly what you want it to do. The Python is in fashion these days. They say it's easy to learn and has a clean syntax. Perhaps, I'm getting too old to learn new languages, but I found Python verbose and awkward. The trend introduced by the object-oriented languages of the last decades makes the programmer use various helpers, wrappers, proxy objects, singletons and other doubtlessly useful but clumsy contraptions. For example, let's write a simple script that runs a program, reads its output and feeds it to the stdin of another program. In Perl, it's as straightforward as this: open(P1, "ls -la |"); open(P2, "|grep ^d"); while (my $l = ) { print P2 $l; } Quite natural, eh? Now, Python: import subprocess a = subprocess.Popen(["ls", "-la"], stdout=subprocess.PIPE) b = subprocess.Popen(["grep", "^d"], stdin=subprocess.PIPE, stdout=subprocess.PIPE) ls = a.communicate()[0] r = b.communicate(input=ls)[0] print(r.decode()) I'm sure there are other ways to do the same in a more concise way using external Python modules like 'sh', but the idiomatic way, AFAIK, is the one used above. Besides, Python, however logical it is, may be unpredictable. For example: In [1]: a=99 In [2]: b=999 In [3]: a is 99 Out[3]: True In [4]: b is 999 Out[4]: False I found Ruby to be more like Perl. Even though it is an object-oriented language, it has many shortcuts that make things simpler, like using $_ variable to store the last read string. But I never liked OOP and put Ruby away. So, from the practical point of view I would vote for Perl. Some would say it's too old, but hey, it's still more popular than Ruby, according to TIOBE index: http://www.tiobe.com/tiobe_index But the popularity shouldn't be crucial in the language choice. If you're going to learn programming languages for fun, have a look at some less popular alternatives. One of them is my favorite Tcl. It's a language with very simple syntax, underestimated but powerful. Many utilities used in other languages, were born in Tcl: Sqlite, Expect and Tk GUI, to name a few. It's still very popular as a built-in language in network hardware. It may lack some libraries supporting modern protocols (AMQP, for example), but programming in Tcl just feels great. Another interesting language is Scheme. There are many dialects of this uncommon but beautiful language. Racket has one of the largest libraries, but it's rather a language for students and teachers than for the real world applications. Chicken Scheme and Guile are way more practical and just as rich. Other options include Erlang and Haskell. Go language is also interesting, but it is IMHO a language for real programmers.