Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Ticket #548 (closed wishlist: fixed)

Opened 17 years ago

Last modified 14 years ago

alias char[] string

Reported by: mwarning Assigned to: kris
Priority: major Milestone: 1.0
Component: Core Functionality Version: trunk
Keywords: Cc:

Description

Since Phobos introduced this very handy alias (and also wstring,dstring), Tango should also adopt it, too.

Just a reminder for the tango team. :P

Change History

09/30/07 23:10:29 changed by kris

  • owner changed from sean to kris.
  • milestone set to 2.0.

(follow-up: ↓ 14 ) 02/08/08 18:33:58 changed by lindquist

  • priority changed from normal to major.
  • milestone deleted.

This really needs to be added. Right now people do it in their own code, but unless the alias is marked private (easy to forget), it will eventually conflict and you have to fully qualify the name.

having to type 'my.longnamedmodule.string' makes it useless.

also by making it private you essentially have to do it in every single module.

Please add these to object.d ASAP

02/11/08 02:46:44 changed by kris

  • status changed from new to assigned.
  • milestone set to 0.99.6.

Neither Sean nor I are comfortable about this macro. It adds a keyword to the language, though not a real keyword, which seems kinda bogus when Walter is trying to keep the keyword list short. We need to think about it some more, so all I can offer for now are my apologies that it may take some time to resolve

02/13/08 02:13:55 changed by baxissimo

If not for all cases, I think this should at least be defined in a version(PhobosCompatibility?) block.

Otherwise Tangobos does not really make it possible to compile most Phobos code without modifying the source code.

02/13/08 02:23:10 changed by baxissimo

In fact, if Tangobos is to work properly, then the entire contents of Tangobos' std.compat should be included in tango in a version(PhobosCompatibility?) block in Tango's object.di or equivalent.

For reference, those contents are:

extern (C) int printf(char *, ...);

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

alias Exception Error;
alias bool      bit;

Actually I could live without the bool-bit thing, since that's deprecated. But using 'string' instead of 'char[]' is actually pushed by Walter as being the preferred style for writing code these days. So you can expect that a lot of Phobos code will be using it.

02/13/08 02:55:12 changed by baxissimo

Or, rather than putting those aliases directly in object.di, maybe this would be better:

version(PhobosCompatibility) { public import std.compat; }

02/13/08 07:59:13 changed by larsivi

Gah, printf!

Another reason for string and friends being problematic; They were added to D 2.0 as the invariant string definitions, and then in D 1.0 for compatibility. But the semantics for a D 1.0 string is very very different from a D 2.0 string, not really making code portable between the two versions at all.

02/14/08 13:37:27 changed by larsivi

See also #902.

02/14/08 14:17:09 changed by mandel

I think code have to be ported from D1 to D2 anyway at some point in the future. In many cases the D2 meaning is favourable.

It is likely that the compiler will give proper errors if the semantics won't fit.

Maybe the D2-Tango ppl have experience with this they want to share? :P

02/14/08 14:34:46 changed by larsivi

It depends somewhat on what becomes implicitly convertible to what, but at least I have doubts about very much invariant use in Tango.

02/20/08 00:34:25 changed by baxissimo

  • priority changed from major to blocker.

You have to make a decision on this, people.

If it's not going to happen you need to close this wontfix ASAP so people know that everyone is to be responsible for working around this incompatibility for themselves.

If it is going to happen you need to do it ASAP so people can start using it and stop creating their own workarounds.

02/20/08 00:36:13 changed by baxissimo

  • milestone changed from 0.99.6 to 0.99.5.

02/23/08 05:03:14 changed by kris

  • priority changed from blocker to normal.
  • milestone changed from 0.99.5 to 0.99.6.

Won't be resolved in 99.5

(in reply to: ↑ 2 ) 03/24/08 21:04:05 changed by Mike Wey

Replying to lindquist:

This really needs to be added. Right now people do it in their own code, but unless the alias is marked private (easy to forget), it will eventually conflict and you have to fully qualify the name.

This might be a compiler bug, but last time i tried (dmd 1.028 and 1.027) private aliases also conflicted.

file main.d

import test;
import test2;

void main(string[]) {}

file test.d

module test;

private alias char[] string;

file test2.d

module test2;

private alias char[] string;

dmd main.d test.d test2.d output:

main.d(4): Error: test.string at test.d(3) conflicts with test2.string at test2.d(3)

When libraries want to be D2 compatible they are going to use the string alias. If someone whould use more than one library witch defines a alias for string, they will run into the problem with the string alias. This problem won't exist if Tango includes a string alias because then there will only be one library with the alias.

04/18/08 04:53:27 changed by kris

  • milestone changed from 0.99.6 to 1.0.

05/24/08 19:17:42 changed by larsivi

#558 marked as a duplicate of this.

(follow-up: ↓ 18 ) 01/19/09 00:41:00 changed by kris

  • status changed from assigned to closed.
  • resolution set to fixed.

(in reply to: ↑ 17 ) 01/19/09 01:24:31 changed by baxissimo

Replying to kris:

Was it fixed? I don't see any change in the svn online. Is it supposed to be a wontfix instead of fixed?

01/19/09 01:51:28 changed by kris

it's in Sean's recent stuff

11/13/09 23:17:14 changed by rawler

As I pointed out in #1777, it's not just Phobos that does this, but D1-language docs, "The name string is aliased to char[]". (http://www.digitalmars.com/d/1.0/arrays.html)

It still doesn't show up in trunk, AFAICT.

From my point of view, this is just an unnecessary incompatibility between Tango and Phobos, as well as contradictory with the language docs.

12/06/09 17:33:17 changed by rawler

  • priority changed from normal to major.
  • status changed from closed to reopened.
  • resolution deleted.

Still not in Trunk. Re-opening.

12/06/09 20:25:09 changed by torhu

To avoid conflicting string aliases, you can always call it something else than string in your library:

version (D_Version2)
  alias string _xstring;
else
  alias char[] _xstring;

Or something of that sort.

I suppose this wouldn't help tangobos, though.

03/28/10 13:13:27 changed by larsivi

  • status changed from reopened to closed.
  • resolution set to fixed.

The aliases are now present in Tango's object.di - wrapped in version (PhobosCompatibility)