|
Remimds me of the code generated by a compiler I once knew:
This was in the days of the superminis, very much CISC. This machine (called ND-500) had a "LoadIndex [register] [indexvalue] [min] [max]" instruction: If the value at [indexvalue] was not between [min] and [max], a exception was generated.
This compiler could (optionally) verify all array indexing, using this instruction, but not quite in the straightforward way that you might think. A disassembly showed something like this
LOAD R4, indexvalue
COMP R4, min
JUMPLT error
COMP R4, max
JUMPGT error
% everything is OK, go ahead
...
error:
LOADINDEX R4, R4, 0, -1 % no legal range, will unconditionally generate exception
Generating six instructions to replace a single one can be meaningful, but hardly when one of the six is the instruction you want to replace... I was working in the company making both the CPU and the compiler, so I went to the compiler guy for an explanation. He insisted that since index check was an option, it should not change any code generated, only add code: The index check is like a debugging aid that you might turn off in a production build, and the production version should be exactly the code you debugged, minus the debug features. With the option off, the first instruciton (LOAD R4, indexvalue) was generated. Turn it on, and you get the five additional instructions.
Needless to say: Even though his argument sort of sounds plausible, I strongly disagreed with him. First, index checking is not a debug feature; you keep it on in the production version. Second: Given an option set, the compiler should be free to the best code for that selection of options, ignoring other option sets (think of optimization options!)
After much arguing, he agreed to rather generate
LOAD R4, indexvalue
LOADINDEX R4, R4, min, max
... two instructions is better than six. But he stuck to his principles: I never got him to generate a singel LOADINDEX.
|
|
|
|
|
that's why i wouldn't get in discussion with senior dev on this
|
|
|
|
|
Does it predate the Nullable data type being added to the framework?
|
|
|
|
|
the parameter is itself a Nullable<int> and i know this is the latest code that we are working on in .NET 4.0 using C# 6 language in it.
modified 25-Jan-18 10:08am.
|
|
|
|
|
You could consider telling the senior dev about the .HasValue property; knowledge share.
Also, the correct English for "... an nullable ..." is "... a nullable ...".
|
|
|
|
|
senior is aware of that, but i am not getting why this method was authored in first place I will discuss for sure sometime that.
|
|
|
|
|
quit reviewing my code little dude.
To err is human to really mess up you need a computer
|
|
|
|
|
it was you, didn't knew
|
|
|
|
|
Ehsan Sajjad wrote: The code is written by very senior developer on my team with huge years of experience in c# There's the problem right there -- they're not used to thinking of base, simple types as classes. Ask them what they think an int? is, and they'll probably tell you it's a pointer to an int. Pointers aren't classes that can have functions.
Took me a while to get used to the concept too.
|
|
|
|
|
you are probably right, once i was having code review meeting with that dev and i was asked to replace var keyword with that particular type name, as according to him, it will degrade performance, i then corrected him and gave reference to a post which explained it is just implicit variable that infers the type and nothing else.
|
|
|
|
|
My issue is with "IsHas".
I use "is" or "has", not both.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
He hasn't written enough code for the week.
|
|
|
|
|
My all-time favourite was from a mid-level programmer of ours who wanted to pass a form field value from one web page to the next: something he did all the time... except that in this instance, for some inexplicable reason, he created a table in the database, used Ajax to write the value to it and retrieve a record ID; he then put the record ID into a hidden field on the page, submitted the form, and then, in the next page, used the record ID to retrieve the value from the database and delete the record. Unfortunately, his English wasn't that great... so in response to the question, "What the hell is this supposed to be?" he said, "That mean I do my way. F*** you, Dan!"
|
|
|
|
|
I also had a mid level developer colleague who had set the bool flag to false by default and then the next statement was checking if it's true
|
|
|
|
|
Excellent. The same one mentioned above wrote in ASP (Classic): "if cstr(ucase(x))=cstr(ucase("CA")) then ..."
there was also some code about cint("1") somewhere...
|
|
|
|
|
Is a broadcast an all-female play?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
As opposed to fishing for a good time at a bar?
Latest Article - Code Review - What You Can Learn From a Single Line of Code
Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny
Artificial intelligence is the only remedy for natural stupidity. - CDP1802
|
|
|
|
|
The best chance to score at a bar is to cut out a stray. What I mean by that is, single woman rarely come into a bar alone, usually in a herd so to have a chance with one you have to get her away from her friends.
Don't let your mind wander too far.
It's too small to be let out alone.
|
|
|
|
|
the Amazons are a broadcaste.
Signature ready for installation. Please Reboot now.
|
|
|
|
|
Tough question. You have cast me into a brood.
... such stuff as dreams are made on
|
|
|
|
|
Wouldn't such a play be miscast?
If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack.
--Winston Churchill
|
|
|
|
|
That would be a play by Overeaters Anonymous; you aren't allowed to know who played what part.
|
|
|
|
|
Don't go to one seeking clever dialog. It's all just one monolog after another.
|
|
|
|
|
I am sure you'll keep us abreast of the situation and not skirt any of the important points.
Ravings en masse^ |
---|
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "If you are searching for perfection in others, then you seek disappointment. If you are seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|