Re: Compiler error with static vars/functions
On 02/10/12 15:18, Don Clugston wrote: On 09/02/12 23:03, Jonathan M Davis wrote: On Thursday, February 09, 2012 14:45:43 bearophile wrote: Jonathan M Davis: Normally, it's considered good practice to give modules names which are all lowercase (particularly since some OSes aren't case-sensitive for file operations). That's just a Walter thing, and it's bollocks. There's no need to use all lower case. No, having non-lower case filenames would just lead to problems. Like different modules being imported depending on the filesystem being used, or the user's locale settings. There's no need for upper and mixed case module file names. artur
Re: Compiler error with static vars/functions
On Fri, Feb 10, 2012 at 04:08:36PM +0100, Artur Skawina wrote: On 02/10/12 15:18, Don Clugston wrote: On 09/02/12 23:03, Jonathan M Davis wrote: On Thursday, February 09, 2012 14:45:43 bearophile wrote: Jonathan M Davis: Normally, it's considered good practice to give modules names which are all lowercase (particularly since some OSes aren't case-sensitive for file operations). That's just a Walter thing, and it's bollocks. There's no need to use all lower case. No, having non-lower case filenames would just lead to problems. Like different modules being imported depending on the filesystem being used, or the user's locale settings. There's no need for upper and mixed case module file names. [...] The real problem is that some OSes have case-insensitive filesystems. T -- It's amazing how careful choice of punctuation can leave you hanging:
Re: Compiler error with static vars/functions
On 10/02/12 16:08, Artur Skawina wrote: On 02/10/12 15:18, Don Clugston wrote: On 09/02/12 23:03, Jonathan M Davis wrote: On Thursday, February 09, 2012 14:45:43 bearophile wrote: Jonathan M Davis: Normally, it's considered good practice to give modules names which are all lowercase (particularly since some OSes aren't case-sensitive for file operations). That's just a Walter thing, and it's bollocks. There's no need to use all lower case. No, having non-lower case filenames would just lead to problems. Like different modules being imported depending on the filesystem being used, or the user's locale settings. I don't think it's possible without deliberate sabotage. You can't have two files with names differing only in case on Windows. And module declarations acts as a check anyway. The D community is a *lot* of experience with mixed case names. No problems have ever been reported.
Re: Compiler error with static vars/functions
On Fri, Feb 10, 2012 at 04:38:12PM +0100, Artur Skawina wrote: On 02/10/12 16:18, Don Clugston wrote: On 10/02/12 16:08, Artur Skawina wrote: [...] No, having non-lower case filenames would just lead to problems. Like different modules being imported depending on the filesystem being used, or the user's locale settings. I don't think it's possible without deliberate sabotage. You can't have two files with names differing only in case on Windows. And module declarations acts as a check anyway. What if you have two modules in the import path, eg a thread provided by some library and another Thread elsewhere? Now import Thread; will do different things depending on the filesystem on which Thread.d resides. It simply can't work, it would be great if no filesystem tried to muck with the case, but unfortunately they do. The compiler should probably enforce module names to be plain ascii and lower case every filename before trying to access it. Having mixed-case *module* names makes sense, just not the filenames. [...] Currently the following code works: // Б.d string Ж() { return Жаба; } // main.d import std.stdio; import Б; void main() { auto Ш = Ж(); writeln(Ш); } Now, this is on a Linux system with UTF-8 locale. I've no idea what would happen if this was attempted on a non-UTF8 locale, or on a filesystem that doesn't support UTF-8 filenames, say on Windows. If the UTF-8 of a particular module name just *happens* to be binary-equal to another module name in the native system encoding (non-UTF8), then we could have a rather nasty problem. T -- GEEK = Gatherer of Extremely Enlightening Knowledge
Compiler error with static vars/functions
Hello, I'm fighting with a strange compiler error. This here compiles and runs fine: -- main.d - class Foo { static int z = 4; static int bar() { return 6; } int foobar() { return 7; } } int main(string[] argv) { writeln(Foo.z); writeln(Foo.bar()); // produces 6 Foo f; writeln(f.bar()); // produces 6; writeln(f.foobar()); return 0; } Whereas this does not compile: -- main.d - import Foo; int main(string[] argv) { writeln(Foo.z); // Error: undefined identifier module Foo.z writeln(Foo.bar()); // Error: undefined identifier module Foo.bar Foo f; writeln(f.bar()); writeln(f.foobar()); return 0; } -- Foo.d -- class Foo { public static int z = 4; public static int bar() { return 6; } public int foobar() { return 7; } } This is a bit strange for me. Apparently, must be some kind of import problem importing Foo. But I don't see how ... Thanks for any hints. Cheers, Oliver -- Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de
Re: Compiler error with static vars/functions
On Thursday, February 09, 2012 14:57:08 Oliver Plow wrote: Hello, I'm fighting with a strange compiler error. This here compiles and runs fine: [snip] This is a bit strange for me. Apparently, must be some kind of import problem importing Foo. But I don't see how ... It's because you named both your module and type Foo. So, when you import Foo, Foo.z is a module-level symbol in Foo (which does not exist). You'd need to do Foo.Foo.z. If your module were named something completele different (e.g. xyzzy), then Foo.z would then be referring to your class Foo's z variable, and it would work. Normally, it's considered good practice to give modules names which are all lowercase (particularly since some OSes aren't case-sensitive for file operations). Renaming your module to foo should fix your problem. - Jonathan M Davis
Re: Compiler error with static vars/functions
On 02/09/2012 02:57 PM, Oliver Plow wrote: Hello, I'm fighting with a strange compiler error. This here compiles and runs fine: -- main.d - class Foo { static int z = 4; static int bar() { return 6; } int foobar() { return 7; } } int main(string[] argv) { writeln(Foo.z); writeln(Foo.bar()); // produces 6 Foo f; writeln(f.bar()); // produces 6; writeln(f.foobar()); return 0; } Whereas this does not compile: -- main.d - import Foo; int main(string[] argv) { writeln(Foo.z);// Error: undefined identifier module Foo.z writeln(Foo.bar()); // Error: undefined identifier module Foo.bar Foo f; writeln(f.bar()); writeln(f.foobar()); return 0; } -- Foo.d -- class Foo { public static int z = 4; public static int bar() { return 6; } public int foobar() { return 7; } } This is a bit strange for me. Apparently, must be some kind of import problem importing Foo. But I don't see how ... Thanks for any hints. Cheers, Oliver As your class is named the same as your module, writeln(Foo.z) looks for z in module Foo. Foo.Foo.z shoulde give you module.class.instance.
Re: Compiler error with static vars/functions
Jonathan M Davis: Normally, it's considered good practice to give modules names which are all lowercase (particularly since some OSes aren't case-sensitive for file operations). That's just a fragile work-around for a module system design problem that I didn't like from the first day I've seen D. I'll take a look in Bugzilla if there is already something on this. Bye, bearophile
Re: Compiler error with static vars/functions
On Thursday, February 09, 2012 14:45:43 bearophile wrote: Jonathan M Davis: Normally, it's considered good practice to give modules names which are all lowercase (particularly since some OSes aren't case-sensitive for file operations). That's just a fragile work-around for a module system design problem that I didn't like from the first day I've seen D. I'll take a look in Bugzilla if there is already something on this. What design problem? The only design problem I see is the fact that some OSes were badly designed to be case insensitive when dealing with files, and that's not a D issue. - Jonathan M Davis
Re: Compiler error with static vars/functions
On Thursday, February 09, 2012 22:42:17 Oliver Plow wrote: Thanks for the answer. This means that all classes belonging to the same module must be in the same *.d file? I mean not one *.d file per class as in most languages? There is no connection between modules and classes other than the fact that they have to go into modules (like all code in D does). You could have 1000 public classes in the same module if you wanted to (though obviously that would be a maintenance nightmare). structs, classes, and free functions can all mix in a single module, and the module's name can be anything you want as long as it's a valid symbol name. It doesn't have to match any of the symbol names within tho module. And I'd dispute the most languages bit. The only languages that I'm aware of which make such a connection are Java and C#, and I'm not even sure that C# is that strict about it (it's been a while since I programmed in C#). I believe that the one public class per file requirement is something that Java introduced and which is not common among programming languages in general. - Jonathan M Davis
Re: Compiler error with static vars/functions
On 2/10/2012 1:00 PM, Mike Parker wrote: On 2/10/2012 6:42 AM, Oliver Plow wrote: Thanks for the answer. This means that all classes belonging to the same module must be in the same *.d file? I mean not one *.d file per class as in most languages? Regards, Oliver Actually, yes. You can't have two modules of the same name. In D, And I should append in the *same package*. Modules in different packages can have the same name. 'module' is synonymous with 'file'. However, you also have packages at your disposal. And 'package' is synonymous with 'directory'. So you can keep one class per module (should you choose to do so) and group them all under a common package name. So given the directory foo with two files: foo - bar.d - baz.d You would have this in bar.d: module foo.bar; And then in baz.d module foo.baz Then you can put your Bar class in bar.d and your Baz class in baz.d if that's the approach you prefer.
Re: Compiler error with static vars/functions
On 2/10/2012 6:42 AM, Oliver Plow wrote: Thanks for the answer. This means that all classes belonging to the same module must be in the same *.d file? I mean not one *.d file per class as in most languages? Regards, Oliver Actually, yes. You can't have two modules of the same name. In D, 'module' is synonymous with 'file'. However, you also have packages at your disposal. And 'package' is synonymous with 'directory'. So you can keep one class per module (should you choose to do so) and group them all under a common package name. So given the directory foo with two files: foo - bar.d - baz.d You would have this in bar.d: module foo.bar; And then in baz.d module foo.baz Then you can put your Bar class in bar.d and your Baz class in baz.d if that's the approach you prefer.