Hacker News new | ask | show | jobs
by viraptor 5169 days ago
That is exactly what I meant - this is a synthetic example. The article has synthetic examples. People want code blocks, but no one is really showing why. Own control structures are cool, ok, but what are you trying to solve with them? Where are the real, convincing before and after examples that are not easily solvable otherwise?
1 comments

Here's some Haskell code I really like, and I think it would be far less nice in Python:

  replicateM 10 . forkIO . forever $ do
    ..
Which is basically the same as:

  replicateM 10 (forkIO (forever (do ..)))
replicateM 10 executes its code block argument 10 times. forkIO executes its code block argument in a new thread. forever loops forever.

So this line basically creates a thread pool with 10 threads, all infinitely executing the given code block.

How would you solve this in Python?

> How would you solve this in Python?

The question is how does codeblocks solve this problem in Python, not how does Haskell solve this problem in Haskell.

Hypothetical Python:

  times(10, forkIO(forever(block:
     ...
     )))
That's not what codeblocks does, though. You use a with statement and a new operator (<<). Then use indentation for the blocks. It doesn't look like you're passing a block to a function. The result is quirky code that will be hard to trace and sort out if you don't already know what's happening.
Oh, I thought you meant code blocks in general, not the particular OP "codeblocks"... Sorry.

I'm not sure that codeblocks actually solves the problem.