The process of preparing programs for a digital computer is especially attractive, not only because it can be economically and scientifically rewarding, but also because it can be an aesthetic experience much like composing poetry or music.
why? I think it's good thing, using () only produces mess in code. When I see bomb.explode() I now I should expect the object bomb to explode. But bomb() doesn't say me anything. Worst thing, the requirements for () changes, old comment stays and i can find something like:
// this operator explodes the bomb
operator()() { /* explode() */ save_the_world(); }
Each run will increment the value and print the new version, but you can also alter that property however and whenever you like, so in Javascript you tend to use real closures for holding state, instead:
I am being sponsored by Syntress! They bought me an amazing dedicated server to run catonmat on. If you're looking web services, I highly recommend the Syntress guys!
Education Sponsors
I am being sponsored by A-Writer! If you ever need help with essay writing, look no further than A-Writer! They will help you with your writing in as quickly as 3 hours!
Very nice article! It's sad that other popular languages doesn't implement operator()-like
Keep up good work Pete!
Comment Responses
why? I think it's good thing, using () only produces mess in code. When I see bomb.explode() I now I should expect the object bomb to explode. But bomb() doesn't say me anything. Worst thing, the requirements for () changes, old comment stays and i can find something like:
// this operator explodes the bomb
operator()() { /* explode() */ save_the_world(); }
Python does - you just need to implement the __call__ method:
All functions in Javascript are implicitly C++-functors, but defined in a reverse order.
Each run will increment the value and print the new version, but you can also alter that property however and whenever you like, so in Javascript you tend to use real closures for holding state, instead:
or you can define objects to instantiate if you need more than one:
Scala also has "()":
Reply To This Comment