What do you think this is about?
-
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.
-
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.
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[^]
-
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[^]
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"
-
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"
-
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.
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 thatFoo
has a member of typeMyCollection.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
-
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.
-
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 thatFoo
has a member of typeMyCollection.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
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.
-
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.
-
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
Could you explain what you mean by that? Or point me to a link, Google isn't finding anything with that term.
-
Could you explain what you mean by that? Or point me to a link, Google isn't finding anything with that term.
-
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.
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.
-
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.
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
-
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
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.