|
Thank you. This was exactly the point I was trying to make.
|
|
|
|
|
|
Good, every one saying about the readability and Debugging,
However this is a Small code, which is called by many classes.
my point is why should i declare a extra variable "resultflag", where this method called 5000+ times in every 10 seconds.
modified 17-Jan-12 7:53am.
|
|
|
|
|
I shouldn't worry about it, if you're accessing a data layer any saving from avoiding allocating 32-bits on the stack is negligible.
Premature optimisation is the root of all evil.
The only actual "improvement" you've made is that the code occupies less space on screen. All the "improvements" you claim will be performed by a decent optimising compiler on release code anyway.
Design for readability/maintainability, then optimise as you have evidence it is worthwhile.
|
|
|
|
|
Declaring an extra variable doesn't affect your performance at all.
Compilers can (and will) easily do the code reduction you did (note what you did is not an optimization).
On the other, having that extra variable does aid in readability and debugging.
The only rewrite I would is (if I absolutely have to change something for no reason other than style):
return ResultFlag != 0;
|
|
|
|
|
Actually, I would move the int declaration down one command, shorten the variable name and use your return with (). I haven't tried it, but I'd be surprised C# would compile your return without ().
|
|
|
|
|
Rajesh Anuhya wrote: However this is a Small code, which is called by many classes. my
point is why should i declare a extra variable "resultflag", where this method
called 5000+ times in every 10 seconds
I can only suppose that that is a general statement that has nothing to do with the code presented.
First the code presented suggests it is doing a database call. You will not be able to even measure the performance gain that you are claiming because of that. The impact of the database call will completely overwhelm the the measurement of what you are claiming. I would suspect that even the variability of network traffic itself would reduce your measurement to the noise level.
Second if your goal is to improve the performance of the that code then you must reduce the number of calls to the database. For example by using a memory cache. That would have a significant impact.
Finally the code is using a return value that is going to end up on the stack regardless of whether it is explicitly stated or implicitly stated. I wouldn't be suprised if the emitted code is almost basically the same between the two versions.
|
|
|
|
|
omg - bad luck with this example for your statement - have a look at the resulting IL - the variable declaration will be optimized away in the release build... If you would realy gain performance...
|
|
|
|
|
One line is more readable than four when three of the four are wasted space. That's because you get three more lines of other code on your screen which help to show the class context (unless the whole class fits on one screen, but that's unusual). There's only one operation in that method which is complex enough to require reading, and putting pointless extra lines makes it less readable.
And I really hope you were intentionally making a point about spurious material with all those emoticons and extraneous formatting, because it makes your post much harder to read.
|
|
|
|
|
Quote: And I really hope you were intentionally making a point about spurious material with all those emoticons and extraneous formatting, because it makes your post much harder to read.
punch +5
|
|
|
|
|
I actually came up with your result before I read further and saw your result. Then I thought, No, you(me) are wrong. Sure as shooting, as soon as I code it that way, when the return is 5 call this routine, when less than 0 call another routine otherwise call a third routine, then return true when the result isn't 0. If I make these 5 statements into 2, they'll never ask to do that.
|
|
|
|
|
I would have fixed the argument name "Sqlstring" while I was at it.
"You get that on the big jobs."
|
|
|
|
|
The first was written by someone who has had to debug code.
The second was written by someone who believes that code always works as intended and never needs to be debugged.
|
|
|
|
|
Trying to translate a winforms app into silverlight, which doesn't have blocking socket operations:
private void ReceiveTelnetDataRepeatedly()
{
while (connection != null && connection.isconnected)
{
connection.CheckForNewBytes();
ProcessData(connection.GetIncomingStrings());
}
}
This was executing in a thread, and the "check for new bytes" was allocating an 8K array every time... within 30 seconds, I'd allocated 1.5GB of RAM and caused an OutOfMemoryException...
|
|
|
|
|
DECLARE @Month VARCHAR(2), @Year VARCHAR(4)
IF (month(GETDATE())) = 1
BEGIN
Set @Month = MONTH(DateAdd(month, -1, GETDATE()));
Set @Year = YEAR(DateAdd(month, -1, GETDATE()));
END
ELSE
BEGIN
Set @Month = MONTH(GETDATE()) -1
Set @Year = YEAR(GETDATE())
END
I just shook my head... It could have been done as easily as:
DECLARE @Month VARCHAR(2), @Year VARCHAR(4)
Set @Month = MONTH(DateAdd(month, -1, GETDATE()));
Set @Year = YEAR(DateAdd(month, -1, GETDATE()));
|
|
|
|
|
Better yet:
DECLARE @Month varchar(2), @Year varchar(4), @LastMonth datetime
SET @LastMonth = DateAdd(MONTH, -1, GetDate())
SET @Month = Month(@LastMonth)
SET @Year = Year(@LastMonth)
EOL
|
|
|
|
|
A better question is, why are grammar so difficult?
|
|
|
|
|
You mean, why is grammars for naturals language so difficults, right?
Well, one explanation could be that the speaker is not a native speaker. But I agree, I'm annoyed by bad grammar too.
|
|
|
|
|
My Priors Idea is hide it.
So from the Servers Initialization file Error and Warning is completely disabled during development time.
|
|
|
|
|
Switch on warnings in production and test. Switch on errors - if possible - on the dev box and get them fixed.
Simples.
At my last job, we had autobuilds of all the products over-night and it was a mater of pride that the builds were clean. For the C# stuff we had FxCop running in Strict South American Police State mode.
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
Nagy Vilmos wrote: For the C# stuff we had FxCop running in Strict South American Police State mode. I'm just curious, how many of your team did make it to release?
'As programmers go, I'm fairly social. Which still means I'm a borderline sociopath by normal standards.' Jeff Atwood
'I'm French! Why do you think I've got this outrrrrageous accent?' Monty Python and the Holy Grail
|
|
|
|
|
Mostly all releases would go out the door with clean builds. There was a lot of rivalry, still is, between the teams about going the most days without a failed build. The dev builds would intentionally fail on any warnings. That meant nobody could get an up to date build once sh*tty code was checked in. The result was that people learnt to check for warnings before they checked in their code.
You'd get, on average, one or two build fails a week out of a dozen products being built daily.
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
I do not doubt the very positive effects on quality that such settings gain. I'm doubting your *slightly* exaggerated qualification for your build rules. Real SA police mode would have got your team members to disappear suddenly
I was thinking along the lines of this sketch (in French): http://www.youtube.com/watch?feature=player_detailpage&v=lPtUZASxCqk#t=306s[^]
For the meteo part at the end, it translates to "Good evening, (...), maybe a little cloud here...".
'As programmers go, I'm fairly social. Which still means I'm a borderline sociopath by normal standards.' Jeff Atwood
'I'm French! Why do you think I've got this outrrrrageous accent?' Monty Python and the Holy Grail
|
|
|
|
|
Whilst checking for warnings is important, it can (as you point out) become so overriding that checking for the code working becomes insignificant.
The attitude becomes "Oh dear, variable 'x' is uninitialised, I'll just change it from int x; to int x = 0; . Phew! Job done." without even stopping to consider what x is being used for. Far better to have something like
int x; and just accept that there will be a warning. I have seen code that looks like
int x = 0;
|
|
|
|
|
Firstly, your assertion is slightly wrong. Uninitialised variables generate a warning if the code path allows them to be accessed before being set.
As an example the following will cause a build warning on the last line:
Integer x;
if (something()) {
x = 3;
}
int y = x * 4;
Secondly, without a good reason, variables used within a loop should be defined in the loop.
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|