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 golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/99896e4fcd832c0003bb5e23ffd1a72837ea49bd.camel%40kortschak.io.