Thread overview
private alias ... isn't
Jun 23, 2006
David Medlock
Jun 23, 2006
Derek Parnell
Re: private alias ... isn't [~OT]
Jun 23, 2006
Lionello Lunesu
Jun 23, 2006
David Medlock
Jun 26, 2006
Lionello Lunesu
June 23, 2006
In several of my utility libraries I have declared :

private alias char[] string;

I don't even type char[] any longer, I always type string.

Every so often I run into conflicts

alias textures.string conflicts with trees.string ...
(several lines like this)

I can usually monkey around with various imports, but its a PITA.
I don't see any possible benefit for this behavior, if it is intended.

*** If it is a bug, ignore the rest of this post.

Names serve a much larger purpose than locating a variable or method, they are *abstractions*.  Why then would a private member be available elsewhere?

When I type private I expect that declaration to be removed from the namespace when the parser leaves the file.  Thats what *private* means(the English word).  Without power to hide some abstractions from others we leave the world of 'logic' and enter the 'zeros and ones' world again.  Black boxes shouldn't be clear plexiglass.

-puzzling
DavidM
June 23, 2006
On Thu, 22 Jun 2006 23:45:59 -0400, David Medlock wrote:

> In several of my utility libraries I have declared :
> 
> private alias char[] string;
> 
> I don't even type char[] any longer, I always type string.
> 
> Every so often I run into conflicts
> 
> alias textures.string conflicts with trees.string ...
> (several lines like this)
> 
> I can usually monkey around with various imports, but its a PITA.
> I don't see any possible benefit for this behavior, if it is intended.
> 
> *** If it is a bug, ignore the rest of this post.
> 
> Names serve a much larger purpose than locating a variable or method, they are *abstractions*.  Why then would a private member be available elsewhere?
> 
> When I type private I expect that declaration to be removed from the namespace when the parser leaves the file.  Thats what *private* means(the English word).  Without power to hide some abstractions from others we leave the world of 'logic' and enter the 'zeros and ones' world again.  Black boxes shouldn't be clear plexiglass.
> 
> -puzzling

This could be any other instance where there is a distinction between "visibility" and "accessibility".

A private alias may be visible from other modules even though it cannot be used by that other module.


However, after just testing that theory out, it seems that there is no such beastie as a 'private alias'. The 'private' qualifier is simply ignored.

Pity, because the concept is sound, IMHO.

-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Down with mediocrity!"
23/06/2006 2:49:54 PM
June 23, 2006
I, too, always create an "alias char[] string"! If only to prevent the barely readable: char[][char[]] string2string;

And I think it wouldn't hurt if we include the following aliases in Phobos, Ares:

alias char[] string;
alias wchar[] wstring;
alias dchar[] dstring;

L.

(And, perhaps, declare a tchar to be either char or wchar, and tstring a tchar[], much like windows' TCHAR and LPTSTR; indeed we'd get two built libraries, but I think the .lib on windows should always use wchar and the .a on linux should always use char.)
June 23, 2006
Lionello Lunesu wrote:
> I, too, always create an "alias char[] string"! If only to prevent the barely readable: char[][char[]] string2string;
> 
> And I think it wouldn't hurt if we include the following aliases in Phobos, Ares:
> 
> alias char[] string;
> alias wchar[] wstring;
> alias dchar[] dstring;
> 
> L.
> 
> (And, perhaps, declare a tchar to be either char or wchar, and tstring a tchar[], much like windows' TCHAR and LPTSTR; indeed we'd get two built libraries, but I think the .lib on windows should always use wchar and the .a on linux should always use char.)

YES please.

-DavidM
June 25, 2006
Lionello Lunesu wrote:

> And I think it wouldn't hurt if we include the following aliases in Phobos, Ares:
> 
> alias char[] string;
> alias wchar[] wstring;
> alias dchar[] dstring;

I think Walter preferred showing the array nature of strings. Then again he also preferred showing the bit nature of bools, things change... :-)

Maybe the time has come for offering a more "readable" alias for it ?

I used "str" myself, partly because it was shorter and partly to avoid mixing it up with "std::string" in my head. (since it is not a class)

http://www.prowiki.org/wiki4d/wiki.cgi?CharsAndStrs#SuggestedTypealiases

--anders
June 26, 2006
Anders F Björklund wrote:
> Lionello Lunesu wrote:
> 
>> And I think it wouldn't hurt if we include the following aliases in Phobos, Ares:
>>
>> alias char[] string;
>> alias wchar[] wstring;
>> alias dchar[] dstring;
> 
> I think Walter preferred showing the array nature of strings. Then again he also preferred showing the bit nature of bools, things change... :-)

char[] a;
It looks like an array of characters, but a[0] is NOT necessarily the first character, so that kind of reasoning can easily backfire.

> Maybe the time has come for offering a more "readable" alias for it ?
> 
> I used "str" myself, partly because it was shorter and partly to avoid mixing it up with "std::string" in my head. (since it is not a class)

I prefer short names for temporary variables: "string str;". And calling the alias "string" might not be a bad idea: you can mimic std::string's interface by creating all of its members global and passing "string" as first parameter. They can then be called as if they were member functions of the char[].

#alias char[] string;
#size_t find_last_of( string _this, dchar ch ) { ... }

#string str = "whatever";
#size_t p = str.find_last_of('e');

This must be my favorite feature in D!

L.