Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. What do you think this is about?

What do you think this is about?

Scheduled Pinned Locked Moved C#
regexquestiondiscussion
13 Posts 5 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jasmine2501
    wrote on last edited by
    #1

    I'm at a loss for what this is supposed to be? Ever seen this pattern before?

    [Serializable]
    public class MyCollection : ArrayList {
    public enum MyUpdateFields {
    MyGroupName
    }
    }

    So, that's basically an ArrayList that defines a useless enum? Why even create this in the first place? I would not even know this exists if Code Analysis hadn't complained about it.

    L RaviBeeR B B 4 Replies Last reply
    0
    • J Jasmine2501

      I'm at a loss for what this is supposed to be? Ever seen this pattern before?

      [Serializable]
      public class MyCollection : ArrayList {
      public enum MyUpdateFields {
      MyGroupName
      }
      }

      So, that's basically an ArrayList that defines a useless enum? Why even create this in the first place? I would not even know this exists if Code Analysis hadn't complained about it.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Jasmine2501 wrote:

      So, that's basically an ArrayList

      Basically, yes. The author should be complimented for writing a specific collection-class, as opposed to using generics throughout the app for each collection. It makes changes easier, as one can easily change the collection-class, without having to check each method that uses the collection.

      Jasmine2501 wrote:

      that defines a useless enum?

      I'm not sure whether it's "useless"; it's merely defined in the collection-class, implying that it's used there, or in conjunction with that class. If it's not used (place the cursor there an hit F12 to find all references) than it'd be better to remove it.

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

      J 1 Reply Last reply
      0
      • L Lost User

        Jasmine2501 wrote:

        So, that's basically an ArrayList

        Basically, yes. The author should be complimented for writing a specific collection-class, as opposed to using generics throughout the app for each collection. It makes changes easier, as one can easily change the collection-class, without having to check each method that uses the collection.

        Jasmine2501 wrote:

        that defines a useless enum?

        I'm not sure whether it's "useless"; it's merely defined in the collection-class, implying that it's used there, or in conjunction with that class. If it's not used (place the cursor there an hit F12 to find all references) than it'd be better to remove it.

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

        J Offline
        J Offline
        Jasmine2501
        wrote on last edited by
        #3

        I don't see the point in having an Enum that only defines one value. What possible purpose could that have? I can make it private and the app still builds - nobody is using it, and I posted all the code for the class, it's not using it. My concern is not about the unused code though, it's about and Enum with only one value. How do you think that might be used? It can only ever have one value, and it can't be null. I don't see the point. I was kind of wondering if it's done for some reason I've never heard of - a lot of this codebase is copied straight from the MSDN. I agree that sometimes a named class that doesn't extend the "system" class makes sense. However, I don't have any issues with using ArrayList, if that's what you need. It is a waste of code and a useless increase in complexity - I don't need my own special ArrayList class, the system one is fine. I agree with what you're saying, but I don't think it's enough of an advantage in most cases. "Don't use the generic class" is often used to increase complexity for no reason at all. When the code is not very well documented, it puts me in the position of "OK, I see this class doesn't do anything extra from ArrayList, so why is it here?" and I can go and look at places where it's used and it's doing nothing special, and then I think "certainly the guy before me didn't write extra code just because someone told him not to use the generic classes" - sends me down a rabbit hole of trying to understand reasoning I didn't participate in. In this question, I'm looking for someone to say, "oh yeah, that's the Lipshitz design pattern, here's a link"

        L 1 Reply Last reply
        0
        • J Jasmine2501

          I don't see the point in having an Enum that only defines one value. What possible purpose could that have? I can make it private and the app still builds - nobody is using it, and I posted all the code for the class, it's not using it. My concern is not about the unused code though, it's about and Enum with only one value. How do you think that might be used? It can only ever have one value, and it can't be null. I don't see the point. I was kind of wondering if it's done for some reason I've never heard of - a lot of this codebase is copied straight from the MSDN. I agree that sometimes a named class that doesn't extend the "system" class makes sense. However, I don't have any issues with using ArrayList, if that's what you need. It is a waste of code and a useless increase in complexity - I don't need my own special ArrayList class, the system one is fine. I agree with what you're saying, but I don't think it's enough of an advantage in most cases. "Don't use the generic class" is often used to increase complexity for no reason at all. When the code is not very well documented, it puts me in the position of "OK, I see this class doesn't do anything extra from ArrayList, so why is it here?" and I can go and look at places where it's used and it's doing nothing special, and then I think "certainly the guy before me didn't write extra code just because someone told him not to use the generic classes" - sends me down a rabbit hole of trying to understand reasoning I didn't participate in. In this question, I'm looking for someone to say, "oh yeah, that's the Lipshitz design pattern, here's a link"

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Jasmine2501 wrote:

          What possible purpose could that have?

          Was it in one of their examples? Isn't it just there as a proxy for "you could hypothetically have a enum here.."?

          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

          J 1 Reply Last reply
          0
          • J Jasmine2501

            I'm at a loss for what this is supposed to be? Ever seen this pattern before?

            [Serializable]
            public class MyCollection : ArrayList {
            public enum MyUpdateFields {
            MyGroupName
            }
            }

            So, that's basically an ArrayList that defines a useless enum? Why even create this in the first place? I would not even know this exists if Code Analysis hadn't complained about it.

            RaviBeeR Offline
            RaviBeeR Offline
            RaviBee
            wrote on last edited by
            #5

            It's not a useless enum!  The enum is simply scoped to the class MyCollection (a terrible name, if that's the actual name).  So you can do stuff like this (for example).  It's assumed that Foo has a member of type MyCollection.MyUpdateFields.

            MyCollection coll = new MyCollection();
            Foo f = new Foo();
            foo.UpdateField = MyCollection.MyGroupName;
            coll.Add (foo);

            It's too bad the author hasn't commented their code.  (This wouldn't even be accepted for a code review where I work). /ravi

            My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

            J 1 Reply Last reply
            0
            • L Lost User

              Jasmine2501 wrote:

              What possible purpose could that have?

              Was it in one of their examples? Isn't it just there as a proxy for "you could hypothetically have a enum here.."?

              Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

              J Offline
              J Offline
              Jasmine2501
              wrote on last edited by
              #6

              I don't know where they got it from. I only had access to the previous developer for 'not long enough' and he showed me only the things he thought were important. He would be happy to admit that he has zero experience with ASP.Net - the site was converted from PHP, so it has some weird patterns and an overall odd style.

              1 Reply Last reply
              0
              • RaviBeeR RaviBee

                It's not a useless enum!  The enum is simply scoped to the class MyCollection (a terrible name, if that's the actual name).  So you can do stuff like this (for example).  It's assumed that Foo has a member of type MyCollection.MyUpdateFields.

                MyCollection coll = new MyCollection();
                Foo f = new Foo();
                foo.UpdateField = MyCollection.MyGroupName;
                coll.Add (foo);

                It's too bad the author hasn't commented their code.  (This wouldn't even be accepted for a code review where I work). /ravi

                My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                J Offline
                J Offline
                Jasmine2501
                wrote on last edited by
                #7

                I can see in your sample code that you have created a variable of the enum type, and set the value to be the only possible value for that enum - that is all fine and good, but what are you going to use that value for? Remember, setting values that don't get used is a waste of memory - the compiler even warns you about it sometimes. And yeah, I've changed the names to protect the innocent.

                RaviBeeR 1 Reply Last reply
                0
                • J Jasmine2501

                  I can see in your sample code that you have created a variable of the enum type, and set the value to be the only possible value for that enum - that is all fine and good, but what are you going to use that value for? Remember, setting values that don't get used is a waste of memory - the compiler even warns you about it sometimes. And yeah, I've changed the names to protect the innocent.

                  RaviBeeR Offline
                  RaviBeeR Offline
                  RaviBee
                  wrote on last edited by
                  #8

                  It's an example to demonstrate enum scoping. :doh: /ravi

                  My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                  J 1 Reply Last reply
                  0
                  • RaviBeeR RaviBee

                    It's an example to demonstrate enum scoping. :doh: /ravi

                    My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                    J Offline
                    J Offline
                    Jasmine2501
                    wrote on last edited by
                    #9

                    Could you explain what you mean by that? Or point me to a link, Google isn't finding anything with that term.

                    RaviBeeR 1 Reply Last reply
                    0
                    • J Jasmine2501

                      Could you explain what you mean by that? Or point me to a link, Google isn't finding anything with that term.

                      RaviBeeR Offline
                      RaviBeeR Offline
                      RaviBee
                      wrote on last edited by
                      #10

                      By scoped enum, I simply mean an enum that's scoped to a class.  See the answer to this[^] SO question. /ravi

                      My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                      1 Reply Last reply
                      0
                      • J Jasmine2501

                        I'm at a loss for what this is supposed to be? Ever seen this pattern before?

                        [Serializable]
                        public class MyCollection : ArrayList {
                        public enum MyUpdateFields {
                        MyGroupName
                        }
                        }

                        So, that's basically an ArrayList that defines a useless enum? Why even create this in the first place? I would not even know this exists if Code Analysis hadn't complained about it.

                        B Offline
                        B Offline
                        Bernhard Hiller
                        wrote on last edited by
                        #11

                        I'd rather think the code stayed incomplete for some reason. When overriding the Add() method of the collection (which he hasn't done yet), he could e.g. check that the item to be added has the correct value in its MyUpdateFields property and otherwise throw an exception. Of course, Generics are a better way to solve it, but they were not available in e.g. .Net 1.1. And since the application was originally written in PHP, some odd ways of doing things might have their origin there.

                        1 Reply Last reply
                        0
                        • J Jasmine2501

                          I'm at a loss for what this is supposed to be? Ever seen this pattern before?

                          [Serializable]
                          public class MyCollection : ArrayList {
                          public enum MyUpdateFields {
                          MyGroupName
                          }
                          }

                          So, that's basically an ArrayList that defines a useless enum? Why even create this in the first place? I would not even know this exists if Code Analysis hadn't complained about it.

                          B Offline
                          B Offline
                          BillWoodruff
                          wrote on last edited by
                          #12

                          Jasmine2501 wrote:

                          Why even create this in the first place?

                          Why even bother to try and figure out what this little-code-monster is, when you can get busy, and write better code than this dinosaur coprolite ? Probably, the author intended, at some point, to extend the enumeration, for some purpose: who cares ? :) 'ArrayList is deprecated, for good reasons. Suggest you review the section titled "Performance Considerations" here: [^]. yours, Bill

                          ~ “This isn't right; this isn't even wrong." Wolfgang Pauli, commenting on a physics paper submitted for a journal

                          J 1 Reply Last reply
                          0
                          • B BillWoodruff

                            Jasmine2501 wrote:

                            Why even create this in the first place?

                            Why even bother to try and figure out what this little-code-monster is, when you can get busy, and write better code than this dinosaur coprolite ? Probably, the author intended, at some point, to extend the enumeration, for some purpose: who cares ? :) 'ArrayList is deprecated, for good reasons. Suggest you review the section titled "Performance Considerations" here: [^]. yours, Bill

                            ~ “This isn't right; this isn't even wrong." Wolfgang Pauli, commenting on a physics paper submitted for a journal

                            J Offline
                            J Offline
                            Jasmine2501
                            wrote on last edited by
                            #13

                            BillWoodruff wrote:

                            Why even bother to try and figure out what this little-code-monster is, when you can get busy, and write better code

                            Because I'm in a testing phase right now and can't write additional code until that's done. The best I can do at the moment is try to understand what's here already. That is pretty important when taking over maintenance of undocumented apps.

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups