October 13, 2010 OO syntax | ||||
---|---|---|---|---|
| ||||
Hello, (completely new to D and to the list) I just read the following in the doc about arrays at http://www.digitalmars.com/d/2.0/arrays.html: ========================= If the first parameter to a function is an array, the function can be called as if it were a property of the array: int[] array; void foo(int[] a, int x); foo(array, 3); array.foo(3); // means the same thing ========================= Does this OO-like syntax also work with other parameter types? Else, why not? I mean, also, why allow it for arrays? (Comment: Unifying syntax for type-specific "function-methods" would simplify and clarify code, don't you think?). Denis -- -- -- -- -- -- -- vit esse estrany ☣ spir.wikidot.com |
October 13, 2010 Re: OO syntax | ||||
---|---|---|---|---|
| ||||
Posted in reply to spir | spir: > Does this OO-like syntax also work with other parameter types? No, it currently doesn't. > Else, why not? I mean, also, why allow it for arrays? It was originally a compiler bug relative to just arrays. Some people have appreciated it, and it became a feature. Some people have asked to extend it to all other types, and maybe this will be implemented, but if you mix it with operator overloading, it gives syntax problems. You have to design such shortcuts with a lot of care, because they are a bit handy, but they may have serious side effects. Often keeping the syntax more clean, with less magic, is the safest and wiser thing to do. Bye, bearophile |
Copyright © 1999-2021 by the D Language Foundation