Post #110,933
7/22/03 4:09:32 PM
|
I don't think the basic argument is so much
against code generation - especially runtime code generation - so much as it is about using code generation at compile time to trick the compiler into bypassing the static type checking. Smalltalk can generate code on the fly as well, and methods can be attached dynamically in much the same way that you showed in Ruby.
One question, though. Can you detach/destroy a method from the object? That is, can you reverse out the process in Ruby to make it revert back to the method_missing. Just thinking that same methods are temporary methods (closures or delegates), that have a limited lifetime or change according to the context.
|
Post #110,940
7/22/03 4:35:10 PM
|
Re: I don't think the basic argument is so much
ChrisR: [...] as it is about using code generation at compile time to trick the compiler into bypassing the static type checking
But that's not what he said ... and such an interpretation sounds like an arbitrary restriction designed to punish statically typed languages.
Oh well. Moving on.
ChrisR: Can you detach/destroy a method from the object? That is, can you reverse out the process in Ruby to make it revert back to the method_missing.
Yes. remove_method(symbol) will remove it from the current class, but leaves any definitions in the super classes intact. undef_method(symbol) will remove it from the entire class hierarchy.
-- -- Jim Weirich jweirich@one.net [link|http://onestepback.org|http://onestepback.org] --------------------------------------------------------------------- "Beware of bugs in the above code; I have only proved it correct, not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)
|
Post #110,946
7/22/03 5:03:54 PM
|
Should probably let Todd defend his Laws....but.... :-)
But that's not what he said ... and such an interpretation sounds like an arbitrary restriction designed to punish statically typed languages. I'm guessing, but I don't think the question is whether code generation (or macros) is inherently and evil in and of itself - it can be a useful technique in limited circumstances. The problem is when you begin to rely on such techniques as a workaround to the Type system - and yes it's biased against Static Typing because ST tends to want to prevent you from doing things. In the case you cite, you could have handled the missing_method with any number of techniques - including generating a function on the fly.
|
Post #110,948
7/22/03 5:14:31 PM
|
Still sounds arbitrary ...
ChrisR: and yes it's biased against Static Typing because ST tends to want to prevent you from doing things.
So it is OK to do if you don't need it. But if it you do need it, then it is not ok.
-- -- Jim Weirich jweirich@one.net [link|http://onestepback.org|http://onestepback.org] --------------------------------------------------------------------- "Beware of bugs in the above code; I have only proved it correct, not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)
|
Post #110,951
7/22/03 5:20:45 PM
|
On par with "Eval"
Which was how we got into this thread in the first place. Eval and Dynamic Code generation are powerful features. The problem is that when you start requiring these facilitaties to get around the barrier put up by the compile (aka Static Typing), then they are no longer luxories. It is indicative of the fact that you are fighting the language in order to achieve your ends.
Of course, it's the Blanchard Law, so I'll let him be more specific about the intents. Just trying to further the conversation. :-)
|
Post #110,963
7/22/03 6:10:00 PM
8/21/07 5:51:08 AM
|
Well said
Smalltalk is dangerous. It is a drug. My advice to you would be don't try it; it could ruin your life. Once you take the time to learn it (to REALLY learn it) you will see that there is nothing out there (yet) to touch it. Of course, like all drugs, how dangerous it is depends on your character. It may be that once you've got to this stage you'll find it difficult (if not impossible) to "go back" to other languages and, if you are forced to, you might become an embittered character constantly muttering ascerbic comments under your breath. Who knows, you may even have to quit the software industry altogether because nothing else lives up to your new expectations. --AndyBower
|
Post #110,964
7/22/03 6:11:20 PM
8/21/07 5:51:13 AM
|
No its not
Your example does not rely on code generation to work - it uses it as an optimization. You could (and do) make it work without the code generation.
There's the razor.
If the only way to accomplish a task is code generation - then the tool is not appropriate for the task.
As to whether this is designed by me to punish static languages. Turnabout is fair play. :-P
Smalltalk is dangerous. It is a drug. My advice to you would be don't try it; it could ruin your life. Once you take the time to learn it (to REALLY learn it) you will see that there is nothing out there (yet) to touch it. Of course, like all drugs, how dangerous it is depends on your character. It may be that once you've got to this stage you'll find it difficult (if not impossible) to "go back" to other languages and, if you are forced to, you might become an embittered character constantly muttering ascerbic comments under your breath. Who knows, you may even have to quit the software industry altogether because nothing else lives up to your new expectations. --AndyBower
|
Post #110,982
7/22/03 7:48:18 PM
|
Ok, I get it.
I was trying to use the law in determining when code generation is a good idea. That's not what the law is for. It is a measure of the power and/or flexibility of your implementation language.
I'm ok with that.
Todd: As to whether this is designed by me to punish static languages. Turnabout is fair play. :-P
Heh, clever line. :-)
-- -- Jim Weirich jweirich@one.net [link|http://onestepback.org|http://onestepback.org] --------------------------------------------------------------------- "Beware of bugs in the above code; I have only proved it correct, not tried it." -- Donald Knuth (in a memo to Peter van As to whether this is designed by me to punish static languages. Turnabout is fair play. :-PEmde Boas)
|
Post #110,987
7/22/03 8:17:05 PM
8/21/07 5:51:33 AM
|
Yep
Smalltalk is dangerous. It is a drug. My advice to you would be don't try it; it could ruin your life. Once you take the time to learn it (to REALLY learn it) you will see that there is nothing out there (yet) to touch it. Of course, like all drugs, how dangerous it is depends on your character. It may be that once you've got to this stage you'll find it difficult (if not impossible) to "go back" to other languages and, if you are forced to, you might become an embittered character constantly muttering ascerbic comments under your breath. Who knows, you may even have to quit the software industry altogether because nothing else lives up to your new expectations. --AndyBower
|