Example
GLORP (Generic Lightweight Object Relational Persistence) allows you to specify queries as blocks of code.
db readManyOf: User where: [:user | user username = 'Blanchard' && user password = 'passW0rd' ].
given a table: CREATE TABLE USER (USER_NAME varchar(60), PASSWORD varchar(60))
how can this work?
The second argument to readManyOf:where: is a block of code. The block is evaluated with a MessageLogger standing in for user. ie
readManyOf: aClass where: aBlock
| aMessageLogger |
aMessageLogger := MessageLogger forClass: aClass
aBlock value: aMessageLogger.
The MessageLogger's doesNotUnderstand is examining the messages and producing an equivalent SQL translation based on some attribute to column mapping data it has. Since even the operators are actually messages, this is relatively straightforward to do. In Smalltalk that is.
This is just plain impossible in Java/C++/Object Pascal/etc.
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
Example
GLORP (Generic Lightweight Object Relational Persistence) allows you to specify queries as blocks of code.
db readManyOf: User where: [:user | user username = 'Blanchard' && user password = 'passW0rd' ].
given a table: CREATE TABLE USER (USER_NAME varchar(60), PASSWORD varchar(60))
how can this work?
The second argument to readManyOf:where: is a block of code. The block is evaluated with a MessageLogger standing in for user. ie
readManyOf: aClass where: aBlock
| aMessageLogger |
aMessageLogger := MessageLogger forClass: aClass
aBlock value: aMessageLogger.
The MessageLogger's doesNotUnderstand is examining the messages and producing an equivalent SQL translation based on some attribute to column mapping data it has. Since even the operators are actually messages, this is relatively straightforward to do. In Smalltalk that is.
This is just plain impossible in Java/C++/Object Pascal/etc.
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