[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: [OT] Swiftly return multiple values
- From: William Ahern <william@...>
- Date: Tue, 3 Jun 2014 12:35:34 -0700
On Tue, Jun 03, 2014 at 12:06:19PM +0200, steve donovan wrote:
> On Mon, Jun 2, 2014 at 10:24 PM, Elias Barrionovo
> <email@example.com> wrote:
> > Well, it's a bit OT and nitpicking, but in Python when you do this:
> > def foo(a, b):
> > return a, b
> > you are actually returning only one value, (a, b), which is an
> > instance of tuple  (parenthesis is optional for tuple literals).
> And that's the point - it's more expensive than it looks. True
> multiple returns in Lua and Go are cheap. (In both languages, often
> used for distinct error returns)
> That's why I prefer Lua to Python - there is less 'convenience magic' happening.
I think alot of it has to do with the beautiful (i.e. straight-forward) VM
design. Python has always been held back by it's VM. This is why Python
can't support coroutines that can yield across function invocations (instead
you have to use ridiculous trampoline patterns). Same problem exists in
reengineering the stack management**), and it's why thread-like coroutines
won't come to ECMAScript anytime soon. And why they're hyping Promises and
other half-measures. Not that the Promise pattern isn't useful, but with
more powerful primitive like Lua's coroutines you can implement such
patterns and many more.
The Lua VM has been overhauled and rewritten many times, and it seems like
the authors have got it down to a science.
> As for Swift - it's fashionable for big companies to have their own
> new programming language. A well-known advertising agency  has
> spawned at least two recently. Despite its oddities, Swift seems a lot
> more readable than Objective-C, which always made my eyes bleed.
I've only briefly looked at the langage, but I'm guessing the language was
basically a vehicle for Apple's fat-pointer compiler technology. A lot of
the language looks rough hewn and annoying, but I bet their type system and
memory management looks really slick underneath the hood.
** Yes, I know about Node.js Fibers, but it's clearly a hack and has many