|
That sounds good. Although the removing method checks if the given type is in the list and if it is it removes it. If it is not it simply does nothing. Although the generic would make it clear that you can only remove IMyInterfaceClasses, since those are the only ones you can add
My 5 for the suggestion.
It's an OO world.
|
|
|
|
|
Silently ignoring a call that passes an incompatible type is not a good idea. In 100 cases out of 100, calls like this indicate that the caller has made a typo: he couldn't have possibly added the item that he is trying to remove, so it's a logical error. As the result, whatever he meant to remove does not get removed, and it all happens silently. The piece of code that finds the item that has been left behind may be far away from the code containing the actual error. That's why I'd prefer a generic: it catches the typos at compile time, preventing potentially costly debugging sessions virtually for free.
|
|
|
|
|
dasblinkenlight wrote: In 100 cases out of 100, ...That's why I'd prefer a generic: it catches the typos at compile time,
preventing potentially costly debugging sessions virtually for free.
In 40 years of programming I haven't seen 100 errors associated with incorrect type usage.
Not even sure I have seen 10.
On the other hand I have seen more than 10 and probably as many as 50 logic errors in code in the past 4 years that either were explicit security problems or had the potential for that.
And thousands of other types of logic errors.
And quite few very obtuse errors some that required hours (at least) to debug involving reflection.
So generics are amusing but they are far from vital.
|
|
|
|
|
The other posts have already given a good answer to your question, so all I'd like to add is:
When first reading the code, your version of the code is clearer (to me). It's very clear that you are adding what's in the parameter.
In your co-workers example, I'd think AddToList does something with adding "Key" to a list, and I wouldn't readily be able to figure out what the generic is doing there in that function.
Same with the deletion: your code makes it clear *what* you are deleting, whereas the alternative leaves it unclear to me what is actually being deleted. Though it is less confusing with the delete than with the add.
So, for first time readability, I'd use your code too.
Combining that with the previous comments: either leave your code as it is, or use your code for adding and the co-workers code for removing (so you get the compile-time type checks).
Best Regards,
MicroVirus
|
|
|
|
|
Generics is about knowing the type at compile-time - you only know the type at execution time.
There are two ways of fixing this:
*
Make the generic code call the non-generic code instead. That's easy, but you won't have any of the benefits of generics.
*
Use reflection to call the generic code from the non-generic code. That's fiddly and won't perform as well, but you can deprecate the non-generic code and eventually remove it.
|
|
|
|
|
I don't follow the code your coworkers wrote. I understand your code though, it makes perfect sense.
If you do any MVVM programming, you have pass not only classes, but delegates (which is even more confusing) to methods in order to do asynchronous programming. Your co worker is all kinds of crazy.
I didn't get any requirements for the signature
|
|
|
|
|
ToddHileHoffer wrote: Your co worker is all kinds of crazy.
I was just going to bed. After reading this I will sleep very well
I do not think delegates are even allowed in our company... To confusing, as you mentioned
It's an OO world.
|
|
|
|
|
I read the question and all the responses. All were at a high level. I am a beginning programmer, 1 1/2 quarters to go for my degree.
The first implementation makes the most sense to me. Up until now I had never seen parameters sent separatly i.e f()() they have always been f( , ).
As I said, I am beginning and may be all wet in the way I read the code, but will use this post to try some new ideas.
Thanks, this was interesting.
dj
|
|
|
|
|
My example may seem a bit weird to you. Try declaring a List(Of String). You probably have done that sometime? Well, surprise, you can actually say List(Of String)(10), where 10 is the capacity of the list, which is the same syntax as my example.
Perhaps it would be clearer in C#, where it would be typed List<string>(10);. You can now clearly see there is a difference between the first and second 'parameters'
The first specifies a Type (for example String or Integer, which will be used elsewhere in the Class or Method) while the second are actually parameters you pass to the method, usually of the Type you just specified.
I think when you try it out you will find it very easy
It's an OO world.
|
|
|
|
|
Thank you, that clears up the syntax for me. I will have to find a required progam that I have to write to try it out on.
DJ
|
|
|
|
|
Actually a List(Of T) can be used in almost any program. You could look in the System.Collections.Generic Namespace to find more types of Generic Collections. Or you could write your own Generic Class. I always just write some stupid program that does absolutely nothing, but where I use some techniques I am not yet familiar with to practice. Good luck!
It's an OO world.
|
|
|
|
|
This seems to be the best forum for my questions, so here goes.
My company's website is being redesigned, and I would like to add more security regarding some of the user information we store. My questions are about best practices and which of the .Net Framework's methods are preferable.
Some data, like contact information, will be encrypted. This allows the data to be stored securely and be converted back into plaintext for display in various contexts. Is there a particular method in System.Security.Cryptography that is considered better than the rest?
I'm not sure whether passwords will be encrypted or hashed. I believe hashing is faster, but if a user forgets his password it cannot be looked up and will have to be changed. Also, we have business rules saying that a user must change his password every 30 days and cannot change it to any password used in the last 6 months: whatever method I implement must be compatible with these rules. Any suggestions?
|
|
|
|
|
If you are concerned about encrypting data in the database I think you need to also look at your procedures for accessing the database. However, if you are using SQL Server you can encrypt the data there, http://technet.microsoft.com/en-us/library/bb510663.aspx[^]
Hashing password is the most secure. So what if the user forgets and must reset it. The old passwords can be stored in a separate table, still hashed, and compared against any new ones. You could create a SQL job that removes all passwords in this table older than six months.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
You can't un-hash something, so encryption is the best way.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
John Simmons / outlaw programmer wrote: You can't un-hash something
The stoner motto.
|
|
|
|
|
Encryption is the act of converting data from an understandable form to a non-understandable one in such a way that it can be converted back with no loss of information.
A related topic to encryption is one-way hashing. One-way hashing algorithms work in many ways the same as encryption with a few important differences.
For Details Help,-
http://www.zdnet.com/news/encryption-hashing-and-obfuscation/128604[^]
May be this can help you.
|
|
|
|
|
What is the latest Third party .Net Tools and Architecture (Like,- Dev Express, Telerik, Mygeneration). What is the easiest way to learn that?
modified on Wednesday, April 13, 2011 9:46 AM
|
|
|
|
|
You don't need to use the code block formatting for your question.
You also don't need to ask this question.
0) Search!
1) RTFM!
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
prasanta_prince wrote: What is the easiest way to learn that?
Download the trials and build something with them. Any specific third party control problem then read either the user guide or visit their forum (or ask a question here!)
As barmey as a sack of badgers
Dude, if I knew what I was doing in life, I'd be rich, retired, dating a supermodel and laughing at the rest of you from the sidelines.
|
|
|
|
|
Check their websites to see which of them have latest releases or betas.
You need to visit their forums and knowledge base articles to learn them.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
|
|
|
|
|
Hi,
I'm experimenting with remoting, trying to see if it's a valid tool to use for our application. But, as luck would have it, I'm lost again. I wonder, is it possible to create an object on the server side and send it to the client? So far, all the examples I've seen and information found, I only found information about instantiating an object on the server from the client.
But if I want to call a method from the client on the server (for instance: public User GetUser(string username) {}), is it possible for the server to return me the User object which the server has created (from a database-helper or equivalent)?
So far, I've only been successful in transferring .net only objects (strings, ints, guids etc). That worked, but now that other thing ..
A good programmer is someone who always looks both ways before crossing a one-way street. (Doug Linder)
|
|
|
|
|
Of course it's possible, but I'd consider looking at WCF instead. There's no compelling reason to use remoting now when you can accomplish the same quite easily via WCF.
|
|
|
|
|
Okay, then what would you suggest I use then? These are the conditions in which it should work:
1) no webserver present (or other software, just the .net runtime)
2) need to change port & protocol at runtime dynamically.
Thanx in advance!
A good programmer is someone who always looks both ways before crossing a one-way street. (Doug Linder)
|
|
|
|
|
Helfdane wrote: 1) no webserver present (or other software, just the .net runtime)
That's not a problem. You don't need a web server to run WCF - that's just a convenience called self hosting. It's entirely possible to talk from exe to exe using WCF.
Helfdane wrote: 2) need to change port & protocol at runtime dynamically.
Again, that's no problem. By convention, people tend to use the config files to convigure WCF services, but that's not a requirement of WCF. WCF settings can be set entirely from code (and it's easier to change protocols with WCF too).
|
|
|
|
|
I have actually been looking at something similar, specifically an in-house instant messaging set-up that would operate exclusively on our company network and off of the internet. The only examples of an IM system using WCF that I have been able to find involve web hosting and global internet capability; the stuff I've tried doesn't like our firewall. I don't suppose you can provide some links or other resources that might be useful? Even a few recent book titles would be nice, and I don't care whether they use C# or VB.net.
|
|
|
|