I don't think I'm personally sold on this proposal either, but I'm curious what bad experiences you've had with post-fix conditionals. I haven't personally used a language with post-fix conditionals and it sounds like that might be to my benefit :)
On Mon, Nov 2, 2020 at 9:09 PM 'Dan Kortschak' via golang-nuts < [email protected]> wrote: > My first professional programming language was Perl, decades later I > still wake up in a sweat thinking about post-fix conditionals and the > 'unless' conditional. > > Please no. > > On Mon, 2020-11-02 at 14:26 -0800, Jeffrey Paul wrote: > > Hello Gophers, > > > > There's two tiny pieces of syntactic sugar I really miss from a few > > other languages that I think would add a nice bit of ergonomics and > > convenience to Go (which I now play as my main) without increasing > > any magic or spooky action at a distance. > > > > They are: > > > > - postfix conditionals > > > > and > > > > - until (while!) and unless (if!) (which probably also means adding > > `while`) > > > > This allows for lovely expressions such as the following examples: > > > > i.NotifySomeone() if j.HasExpiredItems() > > > > time.Sleep(1 * time.Second) until thing.IsReady() > > > > b.ReportActivity(e) unless u.HasOptedOut() > > > > q.ProcessItem() while server.Active() > > > > until(time.Now().After(notAfter)) { > > // do something while we still can > > } > > > > p.processEvents() until p.shutdownRequested > > > > and, my favorite: > > > > panic("can't even") if err != nil > > > > There are, of course, various ways of doing some of this sort of > > synchronization stuff in these contrived examples using > > channels/goroutines/timers, but this sort of syntax is quite useful > > for simple straight-line synchronous code, and, in my view, increases > > readability without sacrificing anything. > > > > I know that `while` isn't a distinct thing in Go, and for > > consistency's sake, this might necessitate adding such a construct as > > well (if you can use it as a postfix conditional, you should probably > > be able to use it as `while(cond) {}` too). > > > > What do you think? I really miss this syntax from other > > languages. It's been in Perl and Ruby for ages, and, more recently, > > CoffeeScript had it for a moment, but it didn't make it over into ES > > with the other notable features from it. I think it's a lovely > > convenience without changing the operation of the language itself. > > > > Best, > > -sneak > > > > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/99896e4fcd832c0003bb5e23ffd1a72837ea49bd.camel%40kortschak.io > . > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAA%3DXfu1RfkK%2B-4kKXUYSYiOve1Kq57ZNxAnOdGh7jbuDdUsKYA%40mail.gmail.com.
