4 ms·
Knowing that Ruby libraries used block (lambda) pattern for the past 25-ish years, it was very painful to read through the first 90% of the article explaining a
by oleganza 3y ago
Knowing that Ruby libraries used block (lambda) pattern for the past 25-ish years, it was very painful to read through the first 90% of the article explaining all the issues with abusing destructors.
Maybe because first-class support for lambdas was added too late in C++ and Java, or maybe because it was always PITA to type.
Ruby syntax is the lightest there could be (and it supports both {braces} and do/end keywords)
transaction do
foo()
bar()
end
- rco8786 3y agoYup, came to say this same thing! I read this whole article going “this is easily solved in Ruby”
- mrkeen 3y agoHow does ruby prevent you from doing non-transactional things between 'do' and 'end'?
- slondr 3y agoThe same way you would be prevented from doing non-transactional things between calls to transaction.start() and transaction.end()
- mrkeen 3y agoWhen I write this: someTransaction = do incrementCounter writeFile "foo.txt" "bar" decrementCounter I get this: src/Lib.hs:11:5: error: • Couldn't match type ‘IO’ with ‘STM’ Expected: STM () Actual: IO () • In a stmt of a 'do' block: writeFile "foo.txt" "bar" In the expression: do incrementCounter writeFile "foo.txt" "bar" decrementCounter In an equation for ‘someTransaction’: someTransaction = do incrementCounter writeFile "foo.txt" "bar" decrementCounter | 11 | writeFile "foo.txt" "bar" | ^^^^^^^^^^^^^^^^^^^^^^^^^
- hiddew 3y ago> Ruby syntax is the lightest there could be Kotlin can have exactly the same code with lambdas, using either a receiver type, or a context receiver. And it's type safe. transaction { foo() bar() } Type-safe DSLs become a pleasure to build and use.