3 ms·
In his book "Zen of Assembly Language", Michael Abrash has a chapter named "Billy, don't be a compiler" and tells the story of a man who coded Assembly like a C
by mahmud 16y ago
In his book "Zen of Assembly Language", Michael Abrash has a chapter named "Billy, don't be a compiler" and tells the story of a man who coded Assembly like a C compiler.
I apologize in advance, but I can't help but extend to you the same advice, cperciva.
"Make it hard to figure out what your variables are by mixing up code with their declarations."
In the right language, binding of variables is usually done by a LET construct, and within its scope where the variable is visible, the code is indented in ward. When you nest LETS you can see the liveness of a variable.
"Construct new values" --> Manually do what the first pass of the compiler already does. Except don't use the const keyword
He misspoke. He meant construct new variables. I am sure you would agree with him that a 'promiscuous tmp' is a royal pain in the ass when you're stepping through bad C code.
"Make functions, not procedures" --> "Don't check for errors. Don't even make it possible to check for errors."
Again, you're thinking at an abnormally low level of abstraction. Results are not for error handling, that's what the condition system is for (some erroneously call it an exception handling system)
"Make your objects immutable" --> "Let's see how much time we can spend in malloc!"
That's what the GC is for. When you make objects immutable you're buying yourself the piece of mind that comes with referential transparency.
"Use purely functional data structures" --> "Arrays and hash tables are often the optimally performant data structures... but you shouldn't use them."
There are ways to implement functional arrays and hashtables, but none too apparent without getting into academic wankery. I agree on this point.
- deleted 16y ago[deleted]
- loup-vaillant 16y agoLanguage specific? Could you specify the languages you have in mind? I used a C/C++/Java syntax, but I meant any language. Or at least the ones with garbage collection.
- mfukar 16y agoI will actually make a blog post of it. There are a few more things to be said, and too little space here.
- loup-vaillant 16y agoGreat. Please send me an e-mail when you're done.
- philwelch 16y agoImperative exception handlers, like in C++, are a lot like glorified longjumps. When learning Erlang I was pleased that a more functional language can handle exceptions much more neatly--if a given expression causes an exception, the value of that expression is the exception, and that recurses in a certain way. It's conceptually less like exception handling in an imperative language and much more like an automatically mediated means of returning error codes.