|
One place I worked had five (count'em...5!) different memory management routines because "Microsoft's doesn't work."
Really? Could it be you just don't know how to use it? Because that's going to be a big surprise to the millions of other programmers using it.
But hey, when management wanted my opinion they told it to me.
Psychosis at 10
Film at 11
|
|
|
|
|
Don't know if this qualifies as a coding horror, but it does give me the heebeegeebees.
Classes that have constructors which initialise the member variables of the class. So far so good.
Except the constructor gets the values it needs from Session Variables, rather than parameters passed in to the constructor.
I understand why it was done, one of the classes is being used to write data to a table that has 118 columns. Who wants to pass 118 parameters to a constructor?
But it still seems questionable to me. To put it simply you can instantiate the same class twice and end up with radically different states depending on how the Session Variables look at the time.
What say you? Coding Horror? Common Practice? Both?
In a strange twist, there is generally a function that is called that sets all the necessary session variables before the class is instantiated.
I don't see why the class couldn't be instantiated first and then have this method set properties on the class rather than setting session variables.
|
|
|
|
|
A table with 118 columns? That's the biggest horror
|
|
|
|
|
I wish that a 118 column table was the biggest horror in that Database.
I've had an intermittent fantasy for about 10 years now leave programming behind and become a train driver. That DB has rekindled that dream.
-Rd
|
|
|
|
|
118 Columns, pfft.. that's child's play.
Oh, right that's not something to be proud of, right?
|
|
|
|
|
GibbleCH wrote: A table with 118 columns? That's the biggest horror
Might be a Fresher's work!!!
|
|
|
|
|
I agree; can't the variables be passed into the constructor as a collection?
|
|
|
|
|
Or just a structure... It could even have a static method to fill itself from the session variables...
MyClass spork = new MyClass(MyClassArgs.LoadFromSession());
Same effect, a bit more verbose, but actually makes it obvious what's happening.
|
|
|
|
|
Both would be improvements.
I think the real horror and a very very common horror is the overuse and misuse of Session Variables.
These classes creating themselves from session variables are a symptom of that.
In reality if you have all these session variables, the class might as well not have any properties, since it then just turns around and writes it's properties to the DB.
Why not just write the Session variables to the DB?
Or why even bother with a class? If you're nailing your colors to the mast of Session variables then a Sub in a Module would do the same job.
Time for someone to write "Session Variables Considered Harmful"
Session variables are actually worse than traditional Global Variables, yet I rarely hear that much fuss about them.
In this day and age shouldn't we be required to declare Session Variables explicitly and also make them typesafe?
The more of other people's ASP.Net code that I have to maintain, the more I despise these little devils.
-Rd
|
|
|
|
|
How true. Did I ever mention the problems caused by a great thinker who stored dynamically created ASP.Net controls in the session?
The session state is member of the page object. The entries in the session state are controls, which again have a reference to the page. Circle complete. Now, what was this about a garbage collection and when exactly does it clean up?
A while ago he asked me what he should have printed on my business cards. I said 'Wizard'.
I read books which nobody else understand. Then I do something which nobody understands. After that the computer does something which nobody understands. When asked, I say things about the results which nobody understand. But everybody expects miracles from me on a regular basis. Looks to me like the classical definition of a wizard.
|
|
|
|
|
What is the end of the session?
I'll take Coding Horrors for $500 Alex.
|
|
|
|
|
|
I just take a look into my friend's code, then I found something confusing to me
I have made some modifications here :
Private Function xxx(ByVal name As String) As Boolean
Dim xxxResult As Boolean = False
If name = "A" Then
Return xxxResult
Else
Return xxxResult
End If
Return xxxResult
Exit Function
End Function
Finally, when I want to go back to my home, I still confused, the world is spinning in my head, there are so much doors.
25160506848319
|
|
|
|
|
Is this a modern Where's Wally?
red_moon wrote: Where is the exit?
Private Function xxx(ByVal name As String) As Boolean
Dim xxxResult As Boolean = False
If name = "A" Then
' Lots of code here
Return xxxResult
Else
' Lots of code here
Return xxxResult
End If
' Lots of code again
Return xxxResult
Exit Function <------Its there just before the word function; Whats the prize?
End Function
Ok, so he's using multiple return points, and there is no requirement here for the Exit Function statement as it is at the end.
|
|
|
|
|
And all statements after End If is never executed too ...
25160506848319
|
|
|
|
|
daveauld wrote: Its there just before the word function; Whats the prize?
Check the code again. Will it come there to execute? How?
Don't forget to Click on [Vote] and [Good Answer] on the posts that helped you.
Regards - Kunal Chowdhury | Software Developer | Chennai | India | My Blog | My Tweets | Silverlight Tutorial
|
|
|
|
|
There are chunks of code removed, so we cannot assume that there are no Exit If 's anywhere.
Also, if its VB6 there may also be some On Error Resume Next statements. (Or On Error Goto xyz ), Ah, those 'handy' statements!
|
|
|
|
|
So, it's depends on the whole code implementation... Without seeing the original code, it's not feasible to reply...
Don't forget to Click on [Vote] and [Good Answer] on the posts that helped you.
Regards - Kunal Chowdhury | Software Developer | Chennai | India | My Blog | My Tweets | Silverlight Tutorial
|
|
|
|
|
Maybe this function is so comfortable that the thread spends a lot more time than needed in it ? Therefore the Exit Function to kick its ass and make it return to work... ^^
|
|
|
|
|
Yeah, that needs some GOTOs.
|
|
|
|
|
Yeah - starting with "GOTO AProgrammingLanguageThanSpotsUnreachableCode"
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
I haven't met many compilers that do a good job at detecting unreachable statements, try this C# snippet:
public int unreachable(int a) {
if (a==1) return 2;
if (a!=1) return 3;
return 4;
}
|
|
|
|
|
That's just a if..else..maybe construct: we used to use them all the time in FORTRAN (because the compiler was such rubbish "maybe" would get executed sometimes).
At least C# would spot
public int unreachable(int a)
{
if (a==1)
return 2;
else
return 3;
return 4;
} Unlike some of the "coderzz" we have asking questions at the moment...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
He codes for both Aristotlean and Bhuddist logic. In the vast majority of cases the black and white of Aristotle will hold true but never underestimate the differing shades of Bhuddist logic. Maybe.
|
|
|
|
|
Most girls I've asked seem to think there is a very specific area that is an exit (making sure to note that it is not an entrance). In order to pass on this knowledge, I thought I'd let you know that "Return xxx..." is not an entrance.
|
|
|
|