|
Michael Losinski wrote: The only thing that I can think of is technically new doesn't guarantee that the variable initialization will take place. Who cares? If the "if" check returns true, the result of calling the routine could make it null. If it's mission critical, initialize it by calling the function and then throw it when the function sets it to null. (Which it doesn't seem to check for, when that is a very possible result of calling the function.) If you are so constrained by memory the new would fail, it'd fail in the function too, thereby throwing an error the code doesn't check for(catch).
|
|
|
|
|
Yes you could the code down to one line of code. You could catch the exception somewhere else, so I suppose the question could then become what do you do in a mission critical system when outofmemory exception or an allocation fails, therefore allowing you to gracefully shutdown. First thing that comes to mind is if the current thread is not mission critical you can kill that can free up some memory. Second, you could have a fail-safe that would allow you to kill all non-mission critical threads thus freeing memory. With the right permissions you could also kill the other applications. I've never implemented one but you could also have a "memory para-shoot" that at the start of the program allocates a chunk of memory and frees it when needed. I suppose allot of it depend on the system and requirements.
|
|
|
|
|
He is just double checking.
|
|
|
|
|
The same thing I told him when I saw this first time.
Previous -> Read "CLR via C#" by Jeffrey Ritcher.
Current -> Exploring WCF thru Apress' "Pro WCF" by Chris Peiris and Dennis Mulder.
Next -> Need to read "The Art of Computer Programming" by Donald E. Knuth.
|
|
|
|
|
Looks like a newbie whose prof in 101 programming hammered down checking objects before using them. This would be sensible if it were a thousand lines down in the code, but, if it is null where is the property/method to new it up?
|
|
|
|
|
Well, he is 4 yrs exp.....
Previous -> Read "CLR via C#" by Jeffrey Ritcher.
Current -> Exploring WCF thru Apress' "Pro WCF" by Chris Peiris and Dennis Mulder.
Next -> Need to read "The Art of Computer Programming" by Donald E. Knuth.
|
|
|
|
|
Mohammed Hameed wrote: Well, he is 4 yrs exp.... So, he IS inexperienced! (I started coding in '74. Late start, '05 on C#.)
|
|
|
|
|
Ohh, is that?
Previous -> Read "CLR via C#" by Jeffrey Ritcher.
Current -> Exploring WCF thru Apress' "Pro WCF" by Chris Peiris and Dennis Mulder.
Next -> Need to read "The Art of Computer Programming" by Donald E. Knuth.
|
|
|
|
|
it could make sense if it was a code update...
let say it was like:
List<Employee> employees = GetEmployessFromSucursal(sucursalID);
if (employees != null){
employees = GetEmployees();//Get employes from other source
}
then for some reason the code was updated or copy&paste... there is also a proba that the IF used to have some other parameter and an ELSE... so again code that was not finally updated to the best final form.
|
|
|
|
|
Thanks.
My Reading-o-Meter
Previous -> Read "CLR via C#" by Jeffrey Richter.
Current -> Exploring WCF thru Apress' "Pro WCF" by Chris Peiris and Dennis Mulder.
Next -> Need to read "The Art of Computer Programming" by Donald E. Knuth.
My blog - My recent article
|
|
|
|
|
Now a smart compiler should probably want about this. Something like when comparing signed and unsigned int's in C and it warns that the statement is always true (or false) due to conversion rules.
Seems like maybe (I know.. "maybe?!?!") a programmer that didn't know what they're doing. That you have to first "create" the list, so you can "fill it in" with the GetEmployees() values or something. Along the same lines as novice programmers that create and assign a local number (or string) variable with a constant value because the function was prototyped with that data type, rather than pass the same constant number inline to the call.
Could be worse.. I've seen this in [employed to write] software:
#define ZERO 0
#define ONE 1
#define TWO 2
|
|
|
|
|
Thanks.
My Reading-o-Meter
Previous -> Read "CLR via C#" by Jeffrey Richter.
Current -> Exploring WCF thru Apress' "Pro WCF" by Chris Peiris and Dennis Mulder.
Next -> Need to read "The Art of Computer Programming" by Donald E. Knuth.
My blog - My recent article
|
|
|
|
|
Just noticed a typo I made.. It should have said:
"Now a smart compiler should probably warn about this."
I guess spell check doesn't catch everything.
|
|
|
|
|
Another gem from the VB6 app I'm in the process of replacing. In production code no less.
SQL = "select policyid, policynumber, covdate"
MsgBox SQL
RS.Open SQL, con, adOpenStatic
My guess is this was a diagnostic message someone neglected to remove. The SQL statement is
quite long (involving a few joins).
Must be quite intimidating for users.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
Alan Kay.
|
|
|
|
|
If only WTFs could be used as an energy source - the VB6 and PHP legacy code out there could fuel us until entropy.
|
|
|
|
|
Sadly true!
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
Alan Kay.
|
|
|
|
|
Oh, a sweet quote for sure. Just replace with your topic of choice...
Charlie Gilley
<italic>You're going to tell me what I want to know, or I'm going to beat you to death in your own house.
"Where liberty dwells, there is my country." B. Franklin, 1783
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
|
|
|
|
|
Parameterised and reusable!
|
|
|
|
|
How about the extra points for the numpty who did this in server side code? System hung, grrr, over to data centre, into server room, find the box, see message, scream "E****! You Elephant Seamstress's Child!"
Reality is an illusion caused by a lack of alcohol
"Nagy, you have won the internets." - Keith Barrow
|
|
|
|
|
Luckily, that is not server side.
Unluckily it is VB6.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
Alan Kay.
|
|
|
|
|
You know what? Just read this, then turned the head around. My colleague behind me has a XP box with a VB6 project open.. (true story)
The signature is in building process.. Please wait...
|
|
|
|
|
Don't leap to assumptions - I also have a VB6 project open, but only because I've been tasked with updating it to C#.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
Alan Kay.
|
|
|
|
|
The problem is: we can't update it. First it's a very large project, seondly the end-user machine does not have and never will have (old box) .NET installed. It has to be that machine due to hardware (scanner, other devices)
The signature is in building process.. Please wait...
|
|
|
|
|
We also have some old legacy projects which need maintenance from time to time. However the gain of updating them to .NET would probably never justify the costs involved.
|
|
|
|
|
The project we have basically produces forms (word docs printed), each one of the form has one or more input masks. Actually over 200. These docs are not allowed to be saved, therefore the application.
The signature is in building process.. Please wait...
|
|
|
|