Path: ...!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: David Brown Newsgroups: comp.unix.shell,comp.unix.programmer,comp.lang.misc Subject: Re: Command Languages Versus Programming Languages Date: Wed, 3 Apr 2024 21:33:58 +0200 Organization: A noiseless patient Spider Lines: 70 Message-ID: References: <20240329084454.0000090f@gmail.com> <20240329101248.556@kylheku.com> <20240329104716.777@kylheku.com> <20240330112105.553@kylheku.com> <87r0fp8lab.fsf@tudado.org> <87wmpg7gpg.fsf@tudado.org> <87plv6jv1i.fsf@nosuchdomain.example.com> <87le5ujrd0.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 03 Apr 2024 19:33:58 +0200 (CEST) Injection-Info: dont-email.me; posting-host="5088b5348498eb86262c097b8448a540"; logging-data="131190"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18UbLlIfVoiUEepZZ2RuYBtMkxDjrekqfk=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:TA4zyhuCbjWV8SYlYGFCjm5/8S4= In-Reply-To: <87le5ujrd0.fsf@nosuchdomain.example.com> Content-Language: en-GB Bytes: 4843 On 03/04/2024 19:19, Keith Thompson wrote: > David Brown writes: >> On 03/04/2024 18:00, Keith Thompson wrote: >>> David Brown writes: > [...] >>>> That's probably the reason almost no one uses it. That post is the >>>> first time I have ever seen conditional expressions outside of a brief >>>> mention in a tutorial on Python conditionals showing how to write >>>> normal conditionals in the language. I think Python stole this one >>>> from Perl. >>> No, Perl's conditional expressions use the same syntax as C's. >> >> I am not very familiar with Perl, and don't know what are expressions >> or statements. Perhaps I have been imagining things. I had the idea >> that in Perl you could write " if " as an >> alternative to the more common imperative language ordering "if >> then ". > > Yes, but it's not the same thing. Perl has postfix conditionals, so you > can write: > > statement if condition; > > but that's a statement, not an expression, and there's no form > equivalent to if/else. It's a specific case of "statement modifiers", > where the keyword can be any of if, unless, while, until, for, foreach, > or when. (The latter is for an experimental "switch" feature, disabled > by default in recent releases.) OK. That's a lot more than I knew. However, I don't see a relevant distinction between a statement and an expression as particularly significant here, at least in terms of code clarity. > > https://perldoc.perl.org/perlsyn#Statement-Modifiers > >>> As for whether Python's conditional expression syntax, it's not >>> clear >>> that (cond ? expr1 : expr2) is better or worse than (expr1 if cond else >>> expr2) (unless you happen to be familiar with one of them). >> >> I think expr1 and expr2 belong naturally together, as you are >> selecting one or the other. If you are using a short-circuit >> evaluation, you would express it in words as "evaluate cond, and based >> on that, evaluate either expr1 and expr2". Having "expr1" first is a >> bit like a recipe that says "add the sugar to the egg whites, having >> first beaten the egg whites". It is an ordering that does not suit >> well in an imperative language (I know Python is multi-paradigm, but >> it is basically imperative). >> >> But I agree that familiarity could be a big factor in my subjective >> opinion here. > > I don't have a strong opinion one way or the other, beyond a willingness > to accept the syntax and other rules of whatever language I'm using. Of course we use the languages we use, warts and all. It's rare that anyone uses a language for a significant amount of work and doesn't dislike at least some aspects of the language. > But I suggest that Python's "expr1 if condition else expr2" is intended > to emphasize expr1 over expr2, treating the condition being true as the > "normal" case. That's not necessarily a bad thing. > Perhaps.