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

-- 
Jeffrey Paul - sneak@sneak.berlin
+1 312 361 0355 (voice, sms, Signal)
5539 AD00 DE4C 42F3 AFE1 1575 0524 43F4 DF2A 55C2

-- 
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/D50EAFC9-4662-429B-AF4E-9C0612F86D66%40sneak.berlin.

Reply via email to