Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does 'until' exist?

Tags:

Is there any reason why the command until was implemented into bash/shell (I'm still unsure which)? Is there anything you can't do with a negation on a while statement? Is it faster than using the NOT CPU function? - unlikely...

like image 931
niraami Avatar asked Apr 10 '17 08:04

niraami


1 Answers

Bash supports it because it conforms to POSIX - specifically, IEEE Std 1003.1, 2004 Edition - Shell Command Language - The until Loop. The feature predates GNU, and GNU bash repo has it since the 1st commit 21 years ago.

As Guillaume also explains in another answer, the rationale behind the feature was (a misguided attempt at) readability. They tried to micromanage things here because shell language was initially targeted at end users rather than professional programmers (like BASIC and SQL).

However, such redundant syntax that does exactly the same thing at the same code complexity proved to be more trouble than it's worth: by providing two, rather than one, canonical forms for a stock construct, it actually hurt readability rather than improve it and introduced unnecessary decisions to make1. That's why it's only present in a few languages designed around that time and likewise intended to be "close to natural language" - like Perl and Visual Basic.

Nowadays, this approach has evolved into the syntax sugar concept2: a redundant construct is only introduced if it significantly simplifies code by replacing an entire boilerplate construct that is used sufficiently often. C# is a good example of this.


1"which one to use here? change it when I change the condition or not? why do I even care?" From my experience, it's the same in Pascal procedures vs functions: I remember having to switch a subroutine between these two multiple times as I design the code. It simply imposes redundant work on the programmer, thus wasting their time.

2I narrow down the term here because I'm expressing things from a language designer's point of view. It's rather "what is now considered good syntax sugar". Since from a language designer's POV, any other SS effectively doesn't exist.

like image 57
ivan_pozdeev Avatar answered Sep 28 '22 03:09

ivan_pozdeev