Click here to Skip to main content
15,899,935 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: I frequently type un-compilable code or comments to myself... Pin
puromtec17-Apr-11 14:33
puromtec17-Apr-11 14:33 
GeneralRe: I frequently type un-compilable code or comments to myself... Pin
Jörgen Andersson7-Apr-11 22:39
professionalJörgen Andersson7-Apr-11 22:39 
GeneralRe: I frequently type un-compilable code or comments to myself... Pin
Pete O'Hanlon13-Apr-11 12:33
mvePete O'Hanlon13-Apr-11 12:33 
GeneralRe: I frequently type un-compilable code or comments to myself... Pin
Jörgen Andersson13-Apr-11 19:02
professionalJörgen Andersson13-Apr-11 19:02 
GeneralRe: I frequently type un-compilable code or comments to myself... Pin
BillW3322-Apr-11 10:09
professionalBillW3322-Apr-11 10:09 
GeneralRe: I frequently type un-compilable code or comments to myself... Pin
StM0n8-Apr-11 22:33
StM0n8-Apr-11 22:33 
GeneralRe: I frequently type un-compilable code or comments to myself... Pin
BobJanova15-Apr-11 3:23
BobJanova15-Apr-11 3:23 
GeneralNew trend at work... Pin
Sander Rossel6-Apr-11 3:05
professionalSander Rossel6-Apr-11 3:05 
Less code is better...

This week I made some ManagerClass that keeps track of a Dictionary(Of String, IMyInterface)
There are Add and Remove Methods(ByVal s As String, ByVal myInterface As IMyInterface) in the ManagerClass that simply add or remove items from the dictionary if the dictionary does not already have them...
So now my boss wanted that the Dictionary(Of String, IMyInterface) could contain List(Of IMyInterface) instead of just the IMyInterface
Well, shiver me timbers! Luckily I have recently read about OOP and applied it here. I created a ListInterfaceClass that Implemented IMyInterface and made it so that it keeps a list. Problem solved (really, does everything it should).

However, when using these Classes you should first instantiate a New ListInterfaceClass, add IMyInterface items to it and then add it to the ManagerClass. If you really wanted to pass it a list of those interfaces that is... Maybe you want to pass it a single interface class. So both options are open, and any extension of IMyInterface could still be added.
On a side note: I think I am really getting the hang of OOD! Perhaps some of you are recognizing the Chain Of Command Pattern? Smile | :)

So I showed what I had made to my boss, but he thought that instantiating a New ListInterfaceClass was too much work and the ManagerClass should do it for you.
Results:
-The MangerClass is now limited to managing ListInterfaceClass only.
-Any extensions or surrogates for the ListInterfaceClass are not possible.
-The ManagerClass is now responsible for putting any IMyInterface it gets into a ListInterfaceClass (and checking if it already exists etc.).
-If for any reason the ListInterfaceClass would not suffice anymore I would have to rewrite the ManagerClass directly.

BUT! We do possibly save two lines of code when using the ManagerClass Thumbs Up | :thumbsup:

This is my second well-designed class structure (I think/hope) and this is the second time I had to throw it overboard because "the user of the classes has to write too much code." The users being my bosses and co-workers.
This company trend is making me worry... Unsure | :~
It's an OO world.

GeneralRe: New trend at work... Pin
Luc Pattyn6-Apr-11 6:37
sitebuilderLuc Pattyn6-Apr-11 6:37 
GeneralRe: New trend at work... Pin
Sander Rossel6-Apr-11 7:26
professionalSander Rossel6-Apr-11 7:26 
AnswerRe: New trend at work... Pin
Luc Pattyn6-Apr-11 15:12
sitebuilderLuc Pattyn6-Apr-11 15:12 
GeneralRe: New trend at work... Pin
Sander Rossel6-Apr-11 19:50
professionalSander Rossel6-Apr-11 19:50 
GeneralRe: New trend at work... Pin
TorstenFrings13-Apr-11 23:27
TorstenFrings13-Apr-11 23:27 
GeneralRe: New trend at work... Pin
Sander Rossel14-Apr-11 23:49
professionalSander Rossel14-Apr-11 23:49 
GeneralLogics is really hard to learn PinPopular
Vladimir Svyatski5-Apr-11 22:16
professionalVladimir Svyatski5-Apr-11 22:16 
GeneralRe: Logics is really hard to learn [modified] Pin
musefan6-Apr-11 0:31
musefan6-Apr-11 0:31 
AnswerRe: Logics is really hard to learn Pin
Eddy Vluggen6-Apr-11 2:33
professionalEddy Vluggen6-Apr-11 2:33 
GeneralRe: Logics is really hard to learn Pin
musefan6-Apr-11 3:22
musefan6-Apr-11 3:22 
GeneralRe: Logics is really hard to learn Pin
Eddy Vluggen6-Apr-11 20:55
professionalEddy Vluggen6-Apr-11 20:55 
GeneralRe: Logics is really hard to learn Pin
Jyothikarthik_N7-Apr-11 3:52
Jyothikarthik_N7-Apr-11 3:52 
GeneralRe: Logics is really hard to learn Pin
Liju Sankar7-Apr-11 22:11
Liju Sankar7-Apr-11 22:11 
GeneralRe: Logics is really hard to learn Pin
Sander Rossel6-Apr-11 2:20
professionalSander Rossel6-Apr-11 2:20 
GeneralRe: Logics is really hard to learn Pin
BillW336-Apr-11 5:19
professionalBillW336-Apr-11 5:19 
GeneralRe: Logics is really hard to learn Pin
Chris Meech6-Apr-11 5:43
Chris Meech6-Apr-11 5:43 
JokeRe: Englishs is really hard to learn Pin
Nathan D Cook7-Apr-11 5:28
Nathan D Cook7-Apr-11 5:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.