3 ms·
Ask HN: Which languages use method.object() order?
I read http://verraes.net/2014/09/objects-as-contracts-for-behaviour/ today and liked his idea of putting method calls before the object.
So rather than write 'invoice.pay(anAmount') or 'appointment.reschedule(aDate)' you would write 'pay.invoice(anAmount)' and 'reschedule.appointment(aDate)'
Are there any programming languages which allow this? Has it been tried and failed?
- RodgerTheGreat 12y agoAn obvious inconvenient side-effect of this approach would be that if expressions are still typed left-to-right it would be very difficult to provide the kind of tab-completion that is common in IDEs and text editors, since the information necessary to narrow the range of a search only becomes available as you finish the expression.
- bjourne 12y agoPolymorphic functions exist in many languages: pay(invoice, anAmount), reschedule(appointment, aDate). Lisp, Scheme, Haskell, Erlang.. They all can do that. If the function can dispatch on the first parameter given, they become equivalent to the object oriented syntax. But many languages go one step further and let you dispatch on any of the arguments, or a combination of them and so on.