Click here to Skip to main content
15,885,953 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: :'-( Pin
ExcellentOrg31-Jul-12 23:41
ExcellentOrg31-Jul-12 23:41 
JokeRe: :'-( Pin
dan!sh 1-Aug-12 1:46
professional dan!sh 1-Aug-12 1:46 
GeneralRe: :'-( Pin
jim lahey30-Jul-12 23:29
jim lahey30-Jul-12 23:29 
GeneralRe: :'-( Pin
CDP180231-Jul-12 1:22
CDP180231-Jul-12 1:22 
GeneralRe: :'-( Pin
jim lahey31-Jul-12 1:27
jim lahey31-Jul-12 1:27 
GeneralRe: :'-( Pin
RobCroll31-Jul-12 15:02
RobCroll31-Jul-12 15:02 
GeneralRe: :'-( Pin
woosterprogrammer1-Aug-12 1:51
woosterprogrammer1-Aug-12 1:51 
GeneralRe: :'-( Pin
Schmuli1-Aug-12 3:00
Schmuli1-Aug-12 3:00 
Regarding the issues, there are a few more, like initializing a variable only to re-initialize a few lines later, and others.

In .NET especially, there is connection pooling for database connections, meaning that even after you close a connection, the connection is kept alive by the framework, and next time you open the connection, the existing connection will be reused. No comment on the Singleton pattern.

It is considered a best practice to always call the Dispose method on a Class that implements IDisposable. This is why there is a
C#
using (resource) { }
construct built into the language. Classes usually implement IDisposable to indicate that they are using external resources which need to be released once you are finished with the class.

In .NET, once a method has completed (returned), any instances created that have no other references can be collected by the Garbage Collector (GC). However, because the GC decides to clean the memory in its own time, this can sometimes mean that instances remain alive for longer than necessary. For example, on a computer with a lot of RAM, the GC may not run for a long time, as there is no issue with Memory.

Another issue with relying on the GC is that the GC will not call the Dispose method on an instance, as it doesn't know anything about IDisposable. What it does is call the Finalize method (known as the Finalizer), which all classes inherit from Object. However, the way in which GC calls the Finalizer means that the instance has to be kept alive for longer than absolutely necessary, at minimum until the next GC collection. Additionally, not all classes necessarily implement a Finalizer.

If a class used external resources, such as a file or a database connection and doesn't release the resource, the external resources may remain inaccessible even after the .NET application closes.
GeneralRe: :'-( Pin
woosterprogrammer1-Aug-12 6:28
woosterprogrammer1-Aug-12 6:28 
GeneralRe: :'-( Pin
Schmuli5-Aug-12 21:45
Schmuli5-Aug-12 21:45 
GeneralRe: :'-( Pin
woosterprogrammer7-Aug-12 1:49
woosterprogrammer7-Aug-12 1:49 
GeneralRe: :'-( Pin
Schmuli7-Aug-12 21:03
Schmuli7-Aug-12 21:03 
GeneralRe: :'-( Pin
woosterprogrammer8-Aug-12 1:28
woosterprogrammer8-Aug-12 1:28 
GeneralRe: :'-( Pin
BobJanova1-Aug-12 23:00
BobJanova1-Aug-12 23:00 
GeneralRe: :'-( Pin
Pete O'Hanlon1-Aug-12 23:09
mvePete O'Hanlon1-Aug-12 23:09 
GeneralRe: :'-( Pin
BobJanova2-Aug-12 1:38
BobJanova2-Aug-12 1:38 
GeneralRe: :'-( Pin
CDP18022-Aug-12 3:31
CDP18022-Aug-12 3:31 
GeneralRe: :'-( Pin
bjarneds1-Aug-12 23:31
bjarneds1-Aug-12 23:31 
GeneralRe: :'-( Pin
Gary Huck1-Aug-12 3:40
Gary Huck1-Aug-12 3:40 
GeneralRe: :'-( Pin
Schmuli1-Aug-12 3:01
Schmuli1-Aug-12 3:01 
GeneralRe: :'-( Pin
Dave Kreskowiak1-Aug-12 4:59
mveDave Kreskowiak1-Aug-12 4:59 
GeneralRe: :'-( Pin
reilly961-Aug-12 7:42
reilly961-Aug-12 7:42 
GeneralRe: :'-( Pin
spencepk3-Aug-12 14:37
spencepk3-Aug-12 14:37 
GeneralRe: :'-( Pin
AspDotNetDev3-Aug-12 14:43
protectorAspDotNetDev3-Aug-12 14:43 
GeneralRe: :'-( Pin
Thornik6-Aug-12 9:57
Thornik6-Aug-12 9:57 

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.