| |
 | Posted by H. S. Teoh in reply to Ali Çehreli | Permalink Reply |
|
H. S. Teoh 
Posted in reply to Ali Çehreli
| On Fri, Jan 20, 2023 at 01:32:22PM -0800, Ali Çehreli via Digitalmars-d-learn wrote:
> On 1/20/23 07:01, torhu wrote:
>
> > But why not have drawLine just be a free function?
>
> Exactly.
>
> If I'm not mistaken, and please teach me if I am wrong, they are practically free functions in Java as well. That Java class is working as a namespace.
Exactly. Every time you see a static singleton class, you're essentially looking at a namespace. Only, in OO circles non-class namespaces are taboo, it's not OO-correct to call them what they are, instead you have to do lip service to OO by calling them static singleton classes instead. And free functions are taboo in OO; OO doctrine declares them unclean affronts to OO purity and requires that you dress them in more OO-appropriate clothing, like putting them inside a namesp^W excuse me, static singleton class.
;-)
> So, the function above is the same as the following free-standing function in D, C++, C, and many other languages:
>
> void Algo_drawLine(Canvas c, Pos from, Pos to) { ...... };
[...]
That way of naming a global function is essentially a poor man's^W^Wexcuse me, I mean, C's way of working around the lack of a proper namespacing / module system. In D, we do have a proper module system, so you could just call the function `drawLine` and put it in a file named Algo.d, then you can just use D's symbol resolution rules to disambiguate between Algo.drawLine and PersonalSpace.drawLine, for example. :-P
T
--
Public parking: euphemism for paid parking. -- Flora
|