5 ms·
A nice thing about "everything is an object" languages is that a.isGreaterThan(b) seems less ambigous than isGreaterThan(a,b). There are natural langauges that
by ppod 7y ago
A nice thing about "everything is an object" languages is that
a.isGreaterThan(b) seems less ambigous than isGreaterThan(a,b). There are natural langauges that are Verb-Subject-Object. It seems less common in natural language to have neither argument be an "agent". Is the copula in the natural language doing the work of the dot?
- gowld 7y agoThat doesn't scale past two arguments.
- ben509 7y agoYou can use fluent interfaces to get past two args: myObject.doThing(a).toAthing(b) Though that requires a good amount of boilerplate on the part of the library author.
- ppod 7y agoMary.give(apple).to(John) Mary.give(John, apple)
- reuben364 7y agoAdga does mixfix pretty well. A variable in scope can indicate the places for arguments with underscores (e.g. _+_ or _=<_>_). The tradeoff for being able to use pretty much any symbol in identifiers along with mixfix is that you have use whitespace (3 + 5, not 3+5). Though I agree it doesn't scale.
- wereHamster 7y agoIn Haskell you can make any (prefix) function infix (and vice versa). Some other languages (eg. Kotlin) support this as well. a + b -- '(+)' function used infix (+) a b -- '(+)' function used prefix min a b -- 'min' function used prefix a `min` b -- 'min' function used infix
- jodrellblank 7y agoIn natural language, "A isGreaterThan B" is a statement and reads as an assertion or a constraint, instead of a conditional test or question; it's ambiguous whether it should do anything. Esperanto has a flexible word order; I think the options would be: ĉu A estas pli granda ol B? (S-V-O) (lit. "whether A is more big than B?") ĉu A pli granda ol B estas? (S-O-V) ĉu estas A pli granda ol B? (V-O-S) and never "estas pli granda ol A B" as you suggest, but also never avoiding any indication that it's a question. From a natural language side, it feels very contrived and arbitrary to have one hill measure whether it is bigger than another hill, instead of having an observer measure both 'from the outside'. That suggests the imbalance in syntax between a. and (b) is strange. a > b is more balanced and looks more like an outsider doing the comparison.
- thaumasiotes 7y ago> In natural language, "A isGreaterThan B" is a statement and reads as an assertion or a constraint, instead of a conditional test or question; it's ambiguous whether it should do anything. The reason functions with these names (and comparator operators) return booleans is precisely to make the code read like natural language. Look at the C syntax: if ( a > b ) { doSomething(); } We read this is "if a is greater than b, do something", and by an amazing coincidence, that's what the code does. In order to get the code to do what it says it will do, we need the > operator to be a conditional test. It always looks like a conditional test because it always appears in the explicit context of a conditional test. The fact that "a > b" outside of a conditional context looks like a constraint rather than a test isn't really relevant, because placing it outside of that context in the code is a no-op and therefore doesn't come up.
- hikarudo 7y agoI think infix operators are even better for binary functions like this: a <= b. Haskell uses this to great effect (though some people think operators look like noise).