July 19, 2006 Re: DMD 0.163 release | ||||
|---|---|---|---|---|
| ||||
Posted in reply to clayasaurus | clayasaurus wrote: > Walter Bright wrote: > >> >> http://www.digitalmars.com/d/changelog.html >> >> This has all the new import changes in it. That breaks a lot of existing code (like dmdscript), the fixes are simple (adding more import declarations) but tedious. >> >> I couldn't find a better keyword choice than "static import". >> >> The renaming uses '=' instead of 'as', 'from', or 'alias' for the reasons: >> >> 1) didn't want to add new keywords, especially ones like 'as' as I use that as a variable name >> >> 2) didn't need to add new keywords - adding them should be done only if using punctuation is completely unappealing >> >> 3) using '=' and ':' is visually more distinct than embedded keywords. > > > *Imports now default to private instead of public. Breaks existing code.* > > Horray! :) This shouldn't break too much of my code because I already use 'private import' everywhere. > > *Object.opCmp now throws an error. Should override it if used. Breaks existing code.* > > Can someone spell this out for me? *confused* > If you write a class that does not override "opCmp", it is now a runtime error to attempt to compare instances of it: class A { } void main() { A a = new A; A b = new A; if (a < b) { // Error is thrown // ... } } Previously, the base Object class defined opCmp to compare the addresses in memory of the two instances (or something like that). Thus, it worked, but did nothing particularly useful, except insofar as "opCmp" always compared /something/. (This can be useful when writing, e.g. some templated container classes.) I think this is probably a good change. > *Added static imports, renamed imports, and selective importing.* > > Can someone show me how this is supposed to work as well? *confused* > The best explanation is in the spec: http://www.digitalmars.com/d/module.html#ImportDeclaration On a slightly related note, I have updated my keyword index with the new meaning of "static": http://www.prowiki.org/wiki4d/wiki.cgi?LanguageSpecification/KeywordIndex > > Thanks! Nice to see some positive changes. > > ~ Clay > -- Kirk McDonald Pyd: Wrapping Python with D http://dsource.org/projects/pyd/wiki | |||
July 19, 2006 Re: DMD 0.163 release | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Walter Bright wrote:
>
> http://www.digitalmars.com/d/changelog.html
>
> This has all the new import changes in it. That breaks a lot of existing code (like dmdscript), the fixes are simple (adding more import declarations) but tedious.
>
> I couldn't find a better keyword choice than "static import".
>
> The renaming uses '=' instead of 'as', 'from', or 'alias' for the reasons:
>
> 1) didn't want to add new keywords, especially ones like 'as' as I use that as a variable name
>
> 2) didn't need to add new keywords - adding them should be done only if using punctuation is completely unappealing
>
> 3) using '=' and ':' is visually more distinct than embedded keywords.
Default private imports are a fantastic thing long in coming! Thank you Walter.
Also, while I still have some minor reservations on using the 'static' keyword in this way, I very much love the new additions to the import system. I look forward to collapsing some long names down to something more feasible, and to yoinking one or two functions from a utility module without further polluting my namespace (and without having to resort to qualified names when they aren't the summit of elegance). I am intrigued by the exact syntax you settled on, in particular the use of ':' to do selective importing. There are just a couple things that I wonder about.
Is it possible to do a static selective import? In other words:
# static import foo : bar ; // must use 'foo.bar' to refer to it
Or to do a static renamed selective import, even:
# static import abc = foo : def = bar ; // must use 'abc.def', which defers to 'foo.bar'
And I assume there is no way to import more than one module selectively in one module declaration, since there is no syntax to terminate the symbol list after the ':' terminal, aside from ending the declaration altogether.
One last time: hooray for default private imports! ;) You are an amazing individual, Mr. Bright. And D is an amazing language.
-- Chris Nicholson-Sauls
| |||
July 19, 2006 Re: DMD 0.163 release | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Walter Bright wrote:
>
> http://www.digitalmars.com/d/changelog.html
>
> This has all the new import changes in it. That breaks a lot of existing code (like dmdscript), the fixes are simple (adding more import declarations) but tedious.
>
> I couldn't find a better keyword choice than "static import".
>
> The renaming uses '=' instead of 'as', 'from', or 'alias' for the reasons:
>
> 1) didn't want to add new keywords, especially ones like 'as' as I use that as a variable name
>
> 2) didn't need to add new keywords - adding them should be done only if using punctuation is completely unappealing
>
> 3) using '=' and ':' is visually more distinct than embedded keywords.
I am sure you are tired of hearing it Walter, but You Da Man!
=D
-DavidM
| |||
July 19, 2006 Re: DMD 0.163 release | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Kirk McDonald | Kirk McDonald wrote:
> clayasaurus wrote:
>> Walter Bright wrote:
>>
>>>
>>> http://www.digitalmars.com/d/changelog.html
>>>
>>> This has all the new import changes in it. That breaks a lot of existing code (like dmdscript), the fixes are simple (adding more import declarations) but tedious.
>>>
>>> I couldn't find a better keyword choice than "static import".
>>>
>>> The renaming uses '=' instead of 'as', 'from', or 'alias' for the reasons:
>>>
>>> 1) didn't want to add new keywords, especially ones like 'as' as I use that as a variable name
>>>
>>> 2) didn't need to add new keywords - adding them should be done only if using punctuation is completely unappealing
>>>
>>> 3) using '=' and ':' is visually more distinct than embedded keywords.
>>
>>
>> *Imports now default to private instead of public. Breaks existing code.*
>>
>> Horray! :) This shouldn't break too much of my code because I already use 'private import' everywhere.
>>
>> *Object.opCmp now throws an error. Should override it if used. Breaks existing code.*
>>
>> Can someone spell this out for me? *confused*
>>
>
> If you write a class that does not override "opCmp", it is now a runtime error to attempt to compare instances of it:
>
> class A { }
>
> void main() {
> A a = new A;
> A b = new A;
> if (a < b) { // Error is thrown
> // ...
> }
> }
>
> Previously, the base Object class defined opCmp to compare the addresses in memory of the two instances (or something like that). Thus, it worked, but did nothing particularly useful, except insofar as "opCmp" always compared /something/. (This can be useful when writing, e.g. some templated container classes.) I think this is probably a good change.
>
>> *Added static imports, renamed imports, and selective importing.*
>>
>> Can someone show me how this is supposed to work as well? *confused*
>>
>
> The best explanation is in the spec:
> http://www.digitalmars.com/d/module.html#ImportDeclaration
>
> On a slightly related note, I have updated my keyword index with the new meaning of "static":
> http://www.prowiki.org/wiki4d/wiki.cgi?LanguageSpecification/KeywordIndex
>
Thanks!
~ Clay
| |||
July 19, 2006 Re: DMD 0.163 release | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Walter Bright wrote: > > http://www.digitalmars.com/d/changelog.html > > This has all the new import changes in it. That breaks a lot of existing code (like dmdscript), the fixes are simple (adding more import declarations) but tedious. > > I couldn't find a better keyword choice than "static import". > > The renaming uses '=' instead of 'as', 'from', or 'alias' for the reasons: > > 1) didn't want to add new keywords, especially ones like 'as' as I use that as a variable name > > 2) didn't need to add new keywords - adding them should be done only if using punctuation is completely unappealing > > 3) using '=' and ':' is visually more distinct than embedded keywords. I just updated Pyd to work with 0.163 (which was pretty painless), and uncovered a pecular bug. I can't seem to reproduce the exact error with a small example, but (in short) it doesn't seem to like source files named "object.d". Renaming the source file in question (to "dpyobject.d", which is actually a more fitting name and a change I've been meaning to make) solved the problem. For what it's worth, the precise compiler error was: C:\Python24\lib\site-packages\celerid\infrastructure\pyd\object.d(41): identifier 'Object' is not defined C:\Python24\lib\site-packages\celerid\infrastructure\pyd\object.d(41): Object is used as a type Assertion failure: 'b->type->ty == Tclass' on line 342 in file 'class.c' Line 41 is the top of the DPyObject class. It looks like, by calling my file object.d, it was somehow masking Phobos's object.d, and thus the Object class could not be found to subclass DPyObject from. Whatever. I renamed the file and it is now happy. -- Kirk McDonald Pyd: Wrapping Python with D http://dsource.org/projects/pyd/wiki | |||
July 19, 2006 Re: DMD 0.163 release | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Tue, 18 Jul 2006 13:13:37 -0700, Walter Bright wrote: > http://www.digitalmars.com/d/changelog.html > > This has all the new import changes in it. That breaks a lot of existing code (like dmdscript), the fixes are simple (adding more import declarations) but tedious. Thanks Walter. v0.163 compiled Build and all its modules without having to change a single line of code. None of my code was broken with this release. However, I will need to upgrade Build to cater for the new module renaming syntax ASAP. > I couldn't find a better keyword choice than "static import". Given that the form "static import XXX" and "import XXX = whatever" both require XXX to be used when referencing members, the 'static' import is only required when one is not renaming the module, eg. "import io = std.stdio;" and "static import io = std.stdio;" are identical, I sort of liked the idea that dropped the need for 'static' and if one wanted to force FQN using the normal module name, one could have written "import std.stdio = std.stdio;". -- Derek (skype: derek.j.parnell) Melbourne, Australia "Down with mediocrity!" 19/07/2006 2:01:37 PM | |||
July 19, 2006 Re: DMD 0.163 release | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Chris Nicholson-Sauls | Chris Nicholson-Sauls wrote: > Is it possible to do a static selective import? In other words: > # static import foo : bar ; // must use 'foo.bar' to refer to it No. > Or to do a static renamed selective import, even: > # static import abc = foo : def = bar ; // must use 'abc.def', which defers to 'foo.bar' No. > And I assume there is no way to import more than one module selectively in one module declaration, since there is no syntax to terminate the symbol list after the ':' terminal, aside from ending the declaration altogether. That's right. You'll need to do it as a separate declaration. > One last time: hooray for default private imports! ;) You are an amazing individual, Mr. Bright. And D is an amazing language. Thank-you (!) | |||
July 19, 2006 Re: DMD 0.163 release | ||||
|---|---|---|---|---|
| ||||
Posted in reply to David Medlock | David Medlock wrote:
> I am sure you are tired of hearing it Walter, but You Da Man!
No, I never tire of that <g>. "You're welcome" to all here who said thanks.
| |||
July 19, 2006 Re: DMD 0.163 release | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Kirk McDonald | Kirk McDonald wrote:
> I just updated Pyd to work with 0.163 (which was pretty painless), and uncovered a pecular bug. I can't seem to reproduce the exact error with a small example, but (in short) it doesn't seem to like source files named "object.d". Renaming the source file in question (to "dpyobject.d", which is actually a more fitting name and a change I've been meaning to make) solved the problem.
Yes, "object.d" is special and must be the Phobos one that defines "Object". The compiler assumes it is, and gets all confused if it isn't.
| |||
July 19, 2006 Re: DMD 0.163 release | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Derek Parnell | Derek Parnell wrote:
> Given that the form "static import XXX" and "import XXX = whatever" both
> require XXX to be used when referencing members, the 'static' import is
> only required when one is not renaming the module, eg. "import io =
> std.stdio;" and "static import io = std.stdio;" are identical, I sort of
> liked the idea that dropped the need for 'static' and if one wanted to
> force FQN using the normal module name, one could have written "import
> std.stdio = std.stdio;".
I thought of that too, but it would be a weird special case, as having:
import foo.bar = std.stdio;
would be quite bizarre.
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply