August 15, 2006
Kirk McDonald wrote:
> Lutger wrote:
>> Derek Parnell wrote:
>>
>>> No, I suggest you use a different naming convention. I would have your
>>> class name start with a Capital letter and have your source file name all
>>> lowercase. And if you stick to one class per file, have your filename
>>> different to the class by adding a suffix or prefix. For example,
>>>
>>>   module foo_m;
>>>   class Foo
>>>   {
>>>    ...
>>>   }
>>
>>
>> Can I ask you, what is your reason for naming a source file differently than the class? Does it have something to do with importing magic?
> 
> The name of the source file and the name of the class are completely orthogonal. They have nothing to do with each other. They may be the same or different as you wish. This is not Java: A source file can contain zero classes or as many classes as you like.
> 
> That said, it is convention to name source files and modules completely lower-case, and to start class names with a capital. However, the language does not actually enforce either of these. If nothing else, it is a /very bad/ idea to ever name the source file and the module different things, even if they just differ in capitalization.
> 

I've noticed that unfortunatly, it can create quite a mess. I'm coming from C++, I don't know how Java handles it. Does it enforce it that hard?

Maybe I've misunderstood it, I thought Derek Parnell meant the following:

    module foo.bar; // corresponds to foo/bar.d
    class Bar // don't do this, use a different name
    {
        ...
    }
To avoid names such foo.bar.Bar, "if you stick to one class per file." This is something different than naming source file and module different.
August 16, 2006
On Wed, 16 Aug 2006 00:31:47 +0200, Lutger wrote:

> Derek Parnell wrote:
> 
>> No, I suggest you use a different naming convention. I would have your class name start with a Capital letter and have your source file name all lowercase. And if you stick to one class per file, have your filename different to the class by adding a suffix or prefix. For example,
>> 
>>   module foo_m;
>>   class Foo
>>   {
>>    ...
>>   }
> 
> Can I ask you, what is your reason for naming a source file differently than the class? Does it have something to do with importing magic?

It is a personal POV of course, but I do it to avoid source code looking like its hard to read. In other words, the references would look like ...

  auto x = new  foo_m.Foo;

rather than
  auto x = new Foo.Foo;

The duplication of symbols can get confusing after a while.

In Build, the class called 'Source' is contained in the module 'source.d' and this makes a lot of code look strange. Especially when using static members of the class.

  foreach(Source s; source.Source.AllFiles) ...


But each to their own.

-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Down with mediocrity!"
16/08/2006 10:18:56 AM
August 16, 2006
Lutger wrote:
> Kirk McDonald wrote:
> 
>> Lutger wrote:
>>
>>> Derek Parnell wrote:
>>>
>>>> No, I suggest you use a different naming convention. I would have your
>>>> class name start with a Capital letter and have your source file name all
>>>> lowercase. And if you stick to one class per file, have your filename
>>>> different to the class by adding a suffix or prefix. For example,
>>>>
>>>>   module foo_m;
>>>>   class Foo
>>>>   {
>>>>    ...
>>>>   }
>>>
>>>
>>>
>>> Can I ask you, what is your reason for naming a source file differently than the class? Does it have something to do with importing magic?
>>
>>
>> The name of the source file and the name of the class are completely orthogonal. They have nothing to do with each other. They may be the same or different as you wish. This is not Java: A source file can contain zero classes or as many classes as you like.
>>
>> That said, it is convention to name source files and modules completely lower-case, and to start class names with a capital. However, the language does not actually enforce either of these. If nothing else, it is a /very bad/ idea to ever name the source file and the module different things, even if they just differ in capitalization.
>>
> 
> I've noticed that unfortunatly, it can create quite a mess. I'm coming from C++, I don't know how Java handles it. Does it enforce it that hard?

Java mandates that each source file contain a single class with the same name as the file. Java is more strictly object-oriented than C++ or D, and can't have anything outside of a class.

> 
> Maybe I've misunderstood it, I thought Derek Parnell meant the following:
> 
>     module foo.bar; // corresponds to foo/bar.d
>     class Bar // don't do this, use a different name
>     {
>         ...
>     }
> To avoid names such foo.bar.Bar, "if you stick to one class per file." This is something different than naming source file and module different.

Well, that's fine. I see nothing wrong with that.

-- 
Kirk McDonald
Pyd: Wrapping Python with D
http://pyd.dsource.org
August 17, 2006
Derek Parnell wrote:
> On Wed, 16 Aug 2006 00:31:47 +0200, Lutger wrote:
> 
>> Derek Parnell wrote:
>>
>>> No, I suggest you use a different naming convention. I would have your
>>> class name start with a Capital letter and have your source file name all
>>> lowercase. And if you stick to one class per file, have your filename
>>> different to the class by adding a suffix or prefix. For example,
>>>
>>>   module foo_m;
>>>   class Foo
>>>   {
>>>    ...
>>>   }
>> Can I ask you, what is your reason for naming a source file differently than the class? Does it have something to do with importing magic?
> 
> It is a personal POV of course, but I do it to avoid source code looking
> like its hard to read. In other words, the references would look like ...
> 
>   auto x = new  foo_m.Foo;
> 
> rather than
>   auto x = new Foo.Foo;
> 
> The duplication of symbols can get confusing after a while.
> 
> In Build, the class called 'Source' is contained in the module 'source.d'
> and this makes a lot of code look strange. Especially when using static
> members of the class.
> 
>   foreach(Source s; source.Source.AllFiles) ...
> 
> 
> But each to their own.
> 

Why do you access Source above in two different ways, in the same line? with base name "Source" and later with FQN "source.Source"?

-- 
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
August 17, 2006
On Thu, 17 Aug 2006 12:04:50 +0100, Bruno Medeiros wrote:


>>   foreach(Source s; source.Source.AllFiles) ...


> Why do you access Source above in two different ways, in the same line? with base name "Source" and later with FQN "source.Source"?

Because I mis-quoted myself. ;-)

   foreach(source.Source s; source.Source.AllFiles) ...

There, is that better sir?

-- 
Derek Parnell
Melbourne, Australia
"Down with mediocrity!"
1 2
Next ›   Last »