Details

    • Type: New Feature New Feature
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 0.7.5
    • Component/s: Compiler
    • Labels:
      None
    • Number of attachments :
      2

      Description

      add the "partial" modifier to type definitions such that you can spread the defintion of a class accross multiple physical files. example:

      in SomeClass-1.boo

      partial class SomeClass:
      field1 as string
      field2 as string

      def someOp():
      someOpInSecondFile()

      def someOpInFirstFile():
      pass

      in SomeClass-2.boo

      partial class SomeClass:
      def someOpInSecondFile():
      someOpInFirstFile()

      1. partial2.patch
        14 kB
        Doug H
      2. partial3.patch
        6 kB
        Doug H

        Issue Links

          Activity

          Hide
          Scott Fleckenstein added a comment -

          I've completed work to enable this feature and will commit it pending community approval. The behavior is as follows:

          -only class defintions (i.e. not structs, interfaces, or enums) can be declared partial.
          -partial classe defintions can appear in the same file, in different files, or both.
          -Nodes from all the files are simply concatenated together, so that if you declare foo() in 2 partial classes, the error will read like you had declared the same function within one traditional definition.
          -You can declare base classes or interface implementations on any of the partial class definitions. All such declarations will be unioned, that is, the following is valid:

          partial class foo (someInterface):
          pass
          partial class foo (someInterface, someInterface2):
          pass

          the merged class foo will implement both someInterface and someInterface2. If 2 or more different base classes are declared in each partial definition an error will be thrown just like you had declared 2 base classes in a full definition.

          Show
          Scott Fleckenstein added a comment - I've completed work to enable this feature and will commit it pending community approval. The behavior is as follows: -only class defintions (i.e. not structs, interfaces, or enums) can be declared partial. -partial classe defintions can appear in the same file, in different files, or both. -Nodes from all the files are simply concatenated together, so that if you declare foo() in 2 partial classes, the error will read like you had declared the same function within one traditional definition. -You can declare base classes or interface implementations on any of the partial class definitions. All such declarations will be unioned, that is, the following is valid: partial class foo (someInterface): pass partial class foo (someInterface, someInterface2): pass the merged class foo will implement both someInterface and someInterface2. If 2 or more different base classes are declared in each partial definition an error will be thrown just like you had declared 2 base classes in a full definition.
          Hide
          Doug H added a comment -

          Updated Scott Fleckenstein's partial classes patch against latest sources, added test cases, updated syntax files for new "partial" keyword. Everything works great!

          Show
          Doug H added a comment - Updated Scott Fleckenstein's partial classes patch against latest sources, added test cases, updated syntax files for new "partial" keyword. Everything works great!
          Hide
          Rodrigo B. de Oliveira added a comment -

          I do think partial classes are a very useful feature and it will certainly be part of boo some time soon.

          I'm still not sure if requiring the 'partial' keyword in the type declaration is the way for boo to go.

          I would like us to be able to do things like the following eventually:

          namespace System

          class String:
          def MyCoolStringMethod():
          return self.Trim().ToUpper()

          Open classes.

          I'm sure I'll be in a better position to suggest something more concrete after the PDC.

          Show
          Rodrigo B. de Oliveira added a comment - I do think partial classes are a very useful feature and it will certainly be part of boo some time soon. I'm still not sure if requiring the 'partial' keyword in the type declaration is the way for boo to go. I would like us to be able to do things like the following eventually: namespace System class String: def MyCoolStringMethod(): return self.Trim().ToUpper() Open classes. I'm sure I'll be in a better position to suggest something more concrete after the PDC.
          Hide
          Rodrigo B. de Oliveira added a comment -

          If we decide to go with the 'open classes' approach, this code will be legal.

          Show
          Rodrigo B. de Oliveira added a comment - If we decide to go with the 'open classes' approach, this code will be legal.
          Hide
          Doug H added a comment -

          Yeah, sounds interesting. Multimethods for adding methods to external classes maybe, and implicit partial classes for combining internal classes like this patch.
          This version of the patch works the same as before but doesn't require any partial keyword, if it is useful.

          Show
          Doug H added a comment - Yeah, sounds interesting. Multimethods for adding methods to external classes maybe, and implicit partial classes for combining internal classes like this patch. This version of the patch works the same as before but doesn't require any partial keyword, if it is useful.
          Hide
          Daniel Grunwald added a comment -

          I think the partial keyword should be required.
          It allows you to quickly see that a class is NOT partial, so you don't have to spend time searching the other parts. That is good both for humans and IDE's.
          And if you need a partial class, it's only 7 letters to add.

          Show
          Daniel Grunwald added a comment - I think the partial keyword should be required. It allows you to quickly see that a class is NOT partial, so you don't have to spend time searching the other parts. That is good both for humans and IDE's. And if you need a partial class, it's only 7 letters to add.

            People

            • Assignee:
              Rodrigo B. de Oliveira
              Reporter:
              Scott Fleckenstein
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: