Hacker News new | ask | show | jobs
by stcredzero 5173 days ago

    "Here is what my DSL can look like with Blocks in Smalltalk"
    (condition)
        ifTrue: [ ... ]
        ifFalse: [ ... ]
        ifMaybe: [ ... ]
You can accomplish the same thing with named functions and function pointers, but it makes the DSL very awkward to use. Imagine if you had to write all of your conditional logic (if-then and if-then-else and switch) using the names of functions defined elsewhere. That would be much less readable than being able to write block of code inline.
1 comments

Surely that depends on how well you name the functions?
If by that, you mean that the intention revealing name of the function is always as good as being able to read their source code, then I'm a bit dubious. That's a little better than assuming the comments are never outdated or outright lies. The thing is, naming really well is often hard. By requiring so many more names, I think you've added a whole lot of workload to the developer.

In the right environment, that might actually encourage developers to write short methods. In the wrong one, it might encourage longer ones. It would discourage me from writing DSL control structures.

Gedankenexperiment. Imagine this: An IDE that quickly lets you browse the code for a function by pressing a key, or hovering over its name invoked in code. Some smart cookie then comes up with an add-on that provides a switchable view with in-lines for the function code, as if in a code block.