2014-08-08 at

Lost in Stupid Parentheses

Ruby:


A subroutine is invoked by calling it name with parentheses around its arguments; parentheses can be ommitted, except when you want to pass the subroutine's output to another subroutine within the same expression, unless your first subroutine has arity-0; however you should cato canways use parentheses around arguments, except in instances frowned upon by the community-maintained style guide, such as in a DSL.

oCAML/Haskell:


Fuck all the parentheses.

In any event we're still all lost...

Extended Ruby hate

(I kid):

**Too Many Ways To Do Anything**

- See the Wiki book's page on Ruby: on literals (particularly Arrays and Hashes), and function calls.

- Sigils. Too much Perl here for me.

- Two types of closures, one of which reacts to "return" like a block (in C) and the other like a function (in C). [C just used, as a common example.]
1. Ruby wasn't initially designed to have closures.

2. Methods on classes, are designed in the OOP sense, as interfaces to objects.

3. Proc class objects are "procedures", behaving like blocks of code in parentheses, which at the time of their definition will "close over" the values of variables used in their definition ("at interpretation time"), and which may be defined with free variables so that varied input can later be passed to the Proc class object resulting in varied output. However with regards to the "return" keyword called inside a Proc class object ("at runtime"), a Proc class object behaves like a block of code, and control will be passed not to the nearest assignee of the Proc class object, but to the caller of the nearest surrounding function. Also, it behaves like a block of code in the sense that extra variables assigned in the Proc class object's scope ("at runtime") in the form of extranuous arguments, are simply ignored if the Proc class object's number of free variables ("at interpretation time") were lesser than the number of arguments passed into the Proc class object ("at runtime").

Proc class objects can be called explicitly, or implicitly. Explicitly, you call Proc.new, and do stuff with the new Proc class object. Implicitly, there are times when you simple apply the syntactic sugar x {:some_block}, and it creates a Proc class object accessible only to x.

4. The "lambda" keyword, recently introduced, produces closures that are like the anonymous functions of many other languages. Extra arguments passed in ("at runtime") which don't fit into the free variable schema ("at interpretation time") will throw an error. "Return" called inside a lambda simply terminates execution flow of code in the lambda, and passes a value to the assigner of the lambda's value. [bonus: ->(){} syntax]

At some point I'd like to open up Ruby's AST and see how these implementations are related under the hood.

Growing pains, I suppose, just like Python, and PHP, and... Javascript? Or is the latter actually the stablest of the lot now? I don't know, but I'll find out.

No comments :

Post a Comment